Skip to content

Commit

Permalink
♻️ Change logic of checking credentials_keys dictionary from task to …
Browse files Browse the repository at this point in the history
…the source level
  • Loading branch information
adrian-wojcik committed Mar 15, 2024
1 parent f456ed2 commit e6a9810
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
20 changes: 20 additions & 0 deletions viadot/sources/sap_rfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ def __init__(
self.sap_credentials_key = sap_credentials_key
self.env = env

if isinstance(sap_credentials, dict):
credentials_keys = list(sap_credentials.keys())
required_credentials_params = ["sysnr", "user", "passwd", "ashost"]
for key in required_credentials_params:
if key not in credentials_keys:
self.logger.warning(
f"Required key '{key}' not found in your 'sap_credentials' dictionary!"
)
sap_credentials = None

if sap_credentials is None:
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."
Expand Down Expand Up @@ -718,6 +728,16 @@ def __init__(
self.sap_credentials_key = sap_credentials_key
self.env = env

if isinstance(sap_credentials, dict):
credentials_keys = list(sap_credentials.keys())
required_credentials_params = ["sysnr", "user", "passwd", "ashost"]
for key in required_credentials_params:
if key not in credentials_keys:
self.logger.warning(
f"Required key '{key}' not found in your 'sap_credentials' dictionary!"
)
sap_credentials = None

if sap_credentials is None:
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."
Expand Down
10 changes: 0 additions & 10 deletions viadot/tasks/sap_rfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,6 @@ def run(
pd.DataFrame: DataFrame with SAP data.
"""

if isinstance(sap_credentials, dict):
credentials_keys = list(sap_credentials.keys())
required_credentials_params = ["sysnr", "user", "passwd", "ashost"]
for key in required_credentials_params:
if key not in credentials_keys:
self.logger.warning(
f"Required key '{key}' not found in your 'sap_credentials' dictionary!"
)
sap_credentials = None

if sap_credentials is None:
credentials_str = AzureKeyVaultSecret(
secret=sap_credentials_key,
Expand Down

0 comments on commit e6a9810

Please sign in to comment.