Skip to content

Commit

Permalink
♻️ refactor logic in source regarding credentials exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-wojcik committed Mar 15, 2024
1 parent 2d3ee8d commit e5ee5b7
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions viadot/sources/sap_rfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ def __init__(
"""

self._con = None
self.sap_credentials = sap_credentials
self.sap_credentials_key = sap_credentials_key
self.env = env

Expand All @@ -271,7 +270,7 @@ def __init__(
required_credentials_params = ["sysnr", "user", "passwd", "ashost"]
for key in required_credentials_params:
if key not in credentials_keys:
self.logger.warning(
logger.warning(
f"Required key '{key}' not found in your 'sap_credentials' dictionary!"
)
sap_credentials = None
Expand All @@ -280,12 +279,21 @@ def __init__(
logger.warning(
f"Your credentials will use {env} environment from local config. If you would like to use different one - please specified it in sap_credentials parameter."
)
sap_credentials = local_config.get(sap_credentials_key).get(env)
try:
sap_credentials = local_config.get(sap_credentials_key).get(env)
except AttributeError:
raise CredentialError(
f"Sap_credentials_key: {sap_credentials_key} is not stored neither in KeyVault or Local Config!"
)
if sap_credentials is None:
raise CredentialError(f"Missing {env} credentials!")

super().__init__(*args, credentials=sap_credentials, **kwargs)
super().__init__(
*args,
**kwargs,
)

self.sap_credentials = sap_credentials
self.sep = sep
self.client_side_filters = None
self.func = func
Expand All @@ -295,7 +303,7 @@ def __init__(
def con(self) -> pyrfc.Connection:
if self._con is not None:
return self._con
con = pyrfc.Connection(**self.credentials)
con = pyrfc.Connection(**self.sap_credentials)
self._con = con
return con

Expand Down Expand Up @@ -724,7 +732,6 @@ def __init__(
"""

self._con = None
self.sap_credentials = sap_credentials
self.sap_credentials_key = sap_credentials_key
self.env = env

Expand All @@ -733,7 +740,7 @@ def __init__(
required_credentials_params = ["sysnr", "user", "passwd", "ashost"]
for key in required_credentials_params:
if key not in credentials_keys:
self.logger.warning(
logger.warning(
f"Required key '{key}' not found in your 'sap_credentials' dictionary!"
)
sap_credentials = None
Expand All @@ -742,12 +749,18 @@ def __init__(
logger.warning(
f"Your credentials will use {env} environment from local config. If you would like to use different one - please specified it in sap_credentials parameter."
)
sap_credentials = local_config.get(sap_credentials_key).get(env)
try:
sap_credentials = local_config.get(sap_credentials_key).get(env)
except AttributeError:
raise CredentialError(
f"Sap_credentials_key: {sap_credentials_key} is not stored neither in KeyVault or Local Config!"
)
if sap_credentials is None:
raise CredentialError(f"Missing {env} credentials!")

super().__init__(*args, credentials=sap_credentials, **kwargs)
super().__init__(*args, **kwargs)

self.sap_credentials = sap_credentials
self.sep = sep
self.replacement = replacement
self.client_side_filters = None
Expand Down

0 comments on commit e5ee5b7

Please sign in to comment.