From f4df1a69eb34a1b3f480e995cde2ac537c1658cd Mon Sep 17 00:00:00 2001 From: Adam Hellberg Date: Thu, 14 Mar 2019 22:51:16 +0100 Subject: [PATCH] Allow configuration of region and access keys Adds the option to set more boto3 options: region_name, aws_access_key_id, and aws_secret_access_key. This makes it easier to configure without having to be careful about some CLI tool having the correct configuration. Also allows setting the region name. --- s3_storage_provider.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/s3_storage_provider.py b/s3_storage_provider.py index ecfb074..d15d35c 100644 --- a/s3_storage_provider.py +++ b/s3_storage_provider.py @@ -51,9 +51,19 @@ class S3StorageProviderBackend(StorageProvider): self.bucket = config["bucket"] self.storage_class = config["storage_class"] self.api_kwargs = {} + + if "region_name" in config: + self.api_kwargs["region_name"] = config["region_name"] + if "endpoint_url" in config: self.api_kwargs["endpoint_url"] = config["endpoint_url"] + if "access_key_id" in config: + self.api_kwargs["aws_access_key_id"] = config["access_key_id"] + + if "secret_access_key" in config: + self.api_kwargs["aws_secret_access_key"] = config["secret_access_key"] + def store_file(self, path, file_info): """See StorageProvider.store_file""" @@ -95,9 +105,18 @@ class S3StorageProviderBackend(StorageProvider): "storage_class": storage_class, } + if "region_name" in config: + result["region_name"] = config["region_name"] + if "endpoint_url" in config: result["endpoint_url"] = config["endpoint_url"] + if "access_key_id" in config: + result["access_key_id"] = config["access_key_id"] + + if "secret_access_key" in config: + result["secret_access_key"] = config["secret_access_key"] + return result