Skip to content

Commit

Permalink
Update BotoManager to use specified credentials for each bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeckman314 committed Dec 27, 2023
1 parent 83032c4 commit 915edd2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions fence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ def app_config(

def _setup_data_endpoint_and_boto(app):
if "AWS_CREDENTIALS" in config and len(config["AWS_CREDENTIALS"]) > 0:
value = list(config["AWS_CREDENTIALS"].values())[0]
creds = config["AWS_CREDENTIALS"]
buckets = config.get("S3_BUCKETS", {})
app.boto = BotoManager(value, buckets, logger=logger)
app.boto = BotoManager(creds, buckets, logger=logger)
app.register_blueprint(fence.blueprints.data.blueprint, url_prefix="/data")


Expand Down
18 changes: 13 additions & 5 deletions fence/resources/aws/boto_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ def __init__(self, config, buckets, logger):
self.iam = None

def create_s3_clients(self, config, buckets):
s3_clients = {
'default': client('s3', **config)
}
s3_clients = {}
for creds in config:
if config[creds]['aws'] == 'true':
s3_clients = {'default': self.s3_client}

for bucket in buckets:
cred_name = buckets[bucket]['cred']
keys = config[cred_name]
if 'aws' in keys:
keys.pop('aws')

if 'endpoint_url' in buckets[bucket]:
endpoint_url = buckets[bucket]['endpoint_url']
endpoint_url = buckets[bucket]['endpoint_url']
s3_clients[bucket] = client('s3', **config, endpoint_url=endpoint_url)
s3_clients[bucket] = client('s3', **keys, endpoint_url=endpoint_url)
else:
s3_clients[bucket] = client('s3', **keys)
return s3_clients

def get_s3_client(self, bucket):
Expand Down

0 comments on commit 915edd2

Please sign in to comment.