in backend-printing/helper/backend_print.py [0:0]
def validation_engine(self, sap_config: dict):
"""Validate the connection to the SAP system.
Validate the queue names are present in the SAP system.
If the validation pass, store the connection details in the Key Vault.
Args:
sap_config (dict): _description_
Returns:
_type_: _description_
"""
try:
sap_configuration_map = self._load_schema(sap_config)
print_client = SAPPrintClient(sap_configuration_map)
sap_queues = print_client.get_print_queues()
for queue in sap_queues:
if not print_client.find_print_queue(queue):
return {"status": "error", "message": f"Incorrect queue information - {queue}"}
self.logger.info(
f"[{self.log_tag}] SAP connection validated, saving to key vault"
)
KeyVault().set_kv_secrets(
secret_key=SAP_CONFIG_KEY_VAULT_KEY
% (
sap_configuration_map.sap_environment,
sap_configuration_map.sap_sid,
),
secret_value=json.dumps(asdict(sap_configuration_map)),
)
return {"status": "success", "message": "SAP connection validated"}
except Exception as e:
self.logger.error(
f"[{self.log_tag}] Error occurred while validating SAP connection: {e}"
)
return {"status": "error", "message": str(e)}