Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-4624] [S3 Improvements] Use boto3 to access bucket regions using V4 s3 auth #10427

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/s3/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
boto==2.38.0
boto3==1.4.7
28 changes: 14 additions & 14 deletions addons/s3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from rest_framework import status as http_status

import boto3
from boto import exception
from boto.s3.connection import S3Connection
from boto.s3.connection import OrdinaryCallingFormat
Expand Down Expand Up @@ -131,26 +132,25 @@ def get_bucket_location_or_error(access_key, secret_key, bucket_name):


def get_bucket_prefixes(access_key, secret_key, prefix, bucket_name):
connection = S3Connection(access_key, secret_key)

if bucket_name != bucket_name.lower() or '.' in bucket_name:
# Must use ordinary calling format for mIxEdCaSe or `.` containing bucket names
# otherwise use the default as it handles bucket outside of the US
connection.calling_format = OrdinaryCallingFormat()

bucket = connection.get_bucket(bucket_name)
s3 = boto3.client(
's3',
aws_access_key_id=access_key,
aws_secret_access_key=secret_key
)

result = s3.list_objects(Bucket=bucket_name, Prefix=prefix, Delimiter='/')
folders = []
for key in bucket.list(delimiter='/', prefix=prefix):
if key.name.endswith('/') and key.name != prefix:
for common_prefixes in result.get('CommonPrefixes', []):
key_name = common_prefixes.get('Prefix')
if key_name != prefix:
folders.append(
{
'path': key.name,
'id': f'{bucket_name}:/{key.name}',
'folder_id': key.name,
'path': key_name,
'id': f'{bucket_name}:/{key_name}',
'folder_id': key_name,
'kind': 'folder',
'bucket_name': bucket_name,
'name': key.name.split('/')[-2],
'name': key_name.split('/')[-2],
'addon': 's3',
}
)
Expand Down
Loading