From 0be2f1c689f50909a319cde37a923e6d0b4453b5 Mon Sep 17 00:00:00 2001 From: Alex Meadows Date: Mon, 24 Jun 2019 10:55:01 -0400 Subject: [PATCH] Trying for 0.4.4 Issue with config files and lambda remained. Trying another method to work with it. --- process_tracker/utilities/settings.py | 12 ++++++++---- tests/utilities/test_settings_manager.py | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/process_tracker/utilities/settings.py b/process_tracker/utilities/settings.py index fdfc3a5..c15c0b2 100644 --- a/process_tracker/utilities/settings.py +++ b/process_tracker/utilities/settings.py @@ -1,10 +1,10 @@ # Settings manager and configuration, both for initialization and reading. import configparser -import io import logging import os from pathlib import Path +import tempfile from process_tracker.utilities.aws_utilities import AwsUtilities @@ -109,10 +109,14 @@ def read_config_file(self): bucket = self.aws_utils.get_s3_bucket(bucket_name=bucket_name) key = self.aws_utils.determine_file_key(path=self.config_file) - cfg = bucket.Object(key).get() - cfg = io.TextIOWrapper(io.BytesIO(cfg["Body"].read())) + temporary_file = tempfile.NamedTemporaryFile() - self.config.readfp(cfg) + bucket.download_file(key, temporary_file.name) + + with open(temporary_file.name, "r") as f: + self.config.read_file(f) + + temporary_file.close() else: diff --git a/tests/utilities/test_settings_manager.py b/tests/utilities/test_settings_manager.py index 941374d..57e5ee3 100644 --- a/tests/utilities/test_settings_manager.py +++ b/tests/utilities/test_settings_manager.py @@ -70,7 +70,10 @@ def test_read_config_file_s3(self): expected_keys = ["process_tracker_config.ini"] test_bucket = "test_bucket" - path = "s3://test_bucket/process_tracker_config.ini" + path = ( + "s3://test_bucket/process_tracker_config/SANDBOX/process_tracker_config.ini" + ) + # path = "s3://test_bucket/process_tracker_config.ini" client = boto3.client( "s3",