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

ccmlib/common: improve aws_bucket_ls #473

Merged
merged 1 commit into from
Jul 9, 2023
Merged
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
17 changes: 6 additions & 11 deletions ccmlib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,21 +943,16 @@ def assert_jdk_valid_for_cassandra_version(cassandra_version):
exit(1)


def aws_bucket_ls(s3_url):
def aws_bucket_ls(s3_url: str) -> list[str]:
bucket_object = s3_url.replace('https://s3.amazonaws.com/', '').split('/')
prefix = '/'.join(bucket_object[1:])
s3_conn = Session().client(service_name='s3', config=Config(signature_version=UNSIGNED))
paginator = s3_conn.get_paginator('list_objects_v2')
pages = paginator.paginate(Bucket=bucket_object[0], Prefix=prefix)

files_in_bucket = []
for page in pages:
if 'Contents' not in page:
break
s3_resource = Session().resource(service_name='s3', config=Config(signature_version=UNSIGNED))
bucket = s3_resource.Bucket(bucket_object[0])

files_in_bucket = bucket.objects.filter(Prefix=prefix)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, i missed the prefix part in my proposed change.


for obj in page['Contents']:
files_in_bucket.append(obj['Key'].replace(prefix + "/", ''))
return files_in_bucket
return [f.key.replace(prefix + "/", '') for f in sorted(files_in_bucket, key=lambda x: x.last_modified)]


def grouper(n, iterable, padvalue=None):
Expand Down