| 26 | |
| 27 | |
| 28 | class AWSStorageManager(object): |
| 29 | _storage_config_file = "connector.config" |
| 30 | _logger = None |
| 31 | |
| 32 | _aws_session = None |
| 33 | _aws_region = "us-west-2" |
| 34 | |
| 35 | def _log(self): |
| 36 | """ |
| 37 | Get the log |
| 38 | """ |
| 39 | return logging.getLogger(__name__) |
| 40 | |
| 41 | def _auth_to_amazon(self, config): |
| 42 | """ |
| 43 | Authenticate to Amazon |
| 44 | """ |
| 45 | access_key_id = ConnectorUtil.get_config_setting( |
| 46 | self._logger, config, "AWS", "aws.access_key_id" |
| 47 | ) |
| 48 | secret = ConnectorUtil.get_config_setting( |
| 49 | self._logger, config, "AWS", "aws.secret_access_key" |
| 50 | ) |
| 51 | |
| 52 | self._aws_region = ConnectorUtil.get_config_setting( |
| 53 | self._logger, config, "AWS", "aws.region", "str", self._aws_region |
| 54 | ) |
| 55 | |
| 56 | try: |
| 57 | # If the access_key and secret were not found, |
| 58 | # then this defaults to the local config in ~/.aws |
| 59 | self._aws_session = boto3.Session( |
| 60 | aws_access_key_id=access_key_id, |
| 61 | aws_secret_access_key=secret, |
| 62 | region_name=self._aws_region, |
| 63 | ) |
| 64 | except Exception as err: |
| 65 | self._logger.error("Unable to authenticate to Amazon") |
| 66 | self._logger.error(str(err)) |
| 67 | exit(1) |
| 68 | |
| 69 | self._s3_resource = self._aws_session.resource("s3") |
| 70 | |
| 71 | def __init__(self, config_file="", log_level=None) -> None: |
| 72 | """ |
| 73 | Initialize the instance |
| 74 | """ |
| 75 | |
| 76 | self._logger = self._log() |
| 77 | if log_level is not None: |
| 78 | self._logger.setLevel(log_level) |
| 79 | |
| 80 | if config_file != "": |
| 81 | self._storage_config_file = config_file |
| 82 | |
| 83 | config = configparser.ConfigParser() |
| 84 | list = config.read(self._storage_config_file) |
| 85 | if len(list) == 0: |
nothing calls this directly
no outgoing calls
no test coverage detected