Fetch DW credentials and test.

This commit is contained in:
Pablo Martin 2023-01-16 13:57:34 +01:00
parent 3590bedffd
commit 2d9300c18e
2 changed files with 37 additions and 0 deletions

View file

@ -87,6 +87,7 @@ class LolaConfig:
self.ENV_DATA = None self.ENV_DATA = None
self.TRINO_CREDENTIALS = None self.TRINO_CREDENTIALS = None
self.SSH_TUNNEL_CREDENTIALS = None self.SSH_TUNNEL_CREDENTIALS = None
self.DW_CREDENTIALS = None
self._s3_reader = S3FileReader(s3_client=boto3.client("s3")) self._s3_reader = S3FileReader(s3_client=boto3.client("s3"))
@ -138,6 +139,22 @@ class LolaConfig:
"ssh_jumphost": self.ENV_DATA["pt_ssh_jumphost"], "ssh_jumphost": self.ENV_DATA["pt_ssh_jumphost"],
} }
@_needs_env_data
def fetch_dw_credentials(self, s3_reader=None) -> None:
"""
Read the env file from S3 and store the DW credentials.
:param s3_reader: a client to fetch files from S3.
:return: None
"""
self.DW_CREDENTIALS = {
"host": self.ENV_DATA["datadw_host"],
"user": self.ENV_DATA["datadw_user"],
"password": self.ENV_DATA["datadw_pass"],
"port": self.ENV_DATA["datadw_port"],
}
def fetch_env_data(self, s3_reader=None) -> None: def fetch_env_data(self, s3_reader=None) -> None:
""" """
Read the env file from S3 with the default or a passed s3_reader and Read the env file from S3 with the default or a passed s3_reader and

View file

@ -71,3 +71,23 @@ def test_lolaconfig_fetches_ssh_tunnel_creds_properly():
lolaconfig.fetch_ssh_tunnel_credentials(s3_reader=fake_s3_reader) lolaconfig.fetch_ssh_tunnel_credentials(s3_reader=fake_s3_reader)
assert type(lolaconfig.SSH_TUNNEL_CREDENTIALS) is dict assert type(lolaconfig.SSH_TUNNEL_CREDENTIALS) is dict
def test_lolaconfig_fetches_dw_creds_properly():
lolaconfig = LolaConfig(flow_name="some-flow")
fake_s3_reader = SimpleNamespace()
def mock_read_json_from_s3_file(bucket, key):
return {
"datadw_host": "some_host",
"datadw_user": "some_user",
"datadw_pass": "some_password",
"datadw_port": "some_port",
}
fake_s3_reader.read_json_from_s3_file = mock_read_json_from_s3_file
lolaconfig.fetch_dw_credentials(s3_reader=fake_s3_reader)
assert type(lolaconfig.DW_CREDENTIALS) is dict