From 2d9300c18ea90a9628e197edfb4016819f3ef7ed Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 16 Jan 2023 13:57:34 +0100 Subject: [PATCH] Fetch DW credentials and test. --- lolafect/lolaconfig.py | 17 +++++++++++++++++ tests/test_lolaconfig.py | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lolafect/lolaconfig.py b/lolafect/lolaconfig.py index 5d275f6..515d824 100644 --- a/lolafect/lolaconfig.py +++ b/lolafect/lolaconfig.py @@ -87,6 +87,7 @@ class LolaConfig: self.ENV_DATA = None self.TRINO_CREDENTIALS = None self.SSH_TUNNEL_CREDENTIALS = None + self.DW_CREDENTIALS = None self._s3_reader = S3FileReader(s3_client=boto3.client("s3")) @@ -138,6 +139,22 @@ class LolaConfig: "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: """ Read the env file from S3 with the default or a passed s3_reader and diff --git a/tests/test_lolaconfig.py b/tests/test_lolaconfig.py index f42dd4b..212bc69 100644 --- a/tests/test_lolaconfig.py +++ b/tests/test_lolaconfig.py @@ -71,3 +71,23 @@ def test_lolaconfig_fetches_ssh_tunnel_creds_properly(): lolaconfig.fetch_ssh_tunnel_credentials(s3_reader=fake_s3_reader) 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