Skip to content

Commit

Permalink
Merge pull request #379 from JiriPapousek/optional-s3-upload-acl
Browse files Browse the repository at this point in the history
[CCXDEV-14213] Make ACL during archive upload optional
  • Loading branch information
JiriPapousek authored Jan 7, 2025
2 parents b7e68ce + 3347e8f commit 3c62e61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ccx_messaging/engines/s3_upload_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(
endpoint=None,
archives_path_prefix=None,
archive_name_pattern="$cluster_id[:2]/$cluster_id/$year$month/$day/$time.tar.gz",
s3_acl_enabled=True,
):
"""Initialize engine for S3 upload.
Expand Down Expand Up @@ -87,6 +88,7 @@ def __init__(
access_key=access_key,
secret_key=secret_key,
endpoint=endpoint,
acl_enabled=s3_acl_enabled,
)

def process(self, broker, local_path):
Expand Down
15 changes: 11 additions & 4 deletions ccx_messaging/utils/s3_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class S3Uploader:
"""S3 uploader."""

def __init__(self, access_key, secret_key, endpoint):
def __init__(self, access_key, secret_key, endpoint, acl_enabled=True):
"""Inicialize uploader."""
if not access_key:
raise TypeError("access_key cannot be nulleable")
Expand All @@ -41,12 +41,19 @@ def __init__(self, access_key, secret_key, endpoint):
endpoint_url=endpoint,
)

self.acl_enabled = acl_enabled

def upload_file(self, path, bucket, file_name):
"""Upload file to target path in bucket."""
LOG.info(f"Uploading '{file_name}' as '{path}' to '{bucket}'")

with open(path, "rb") as file_data:
self.client.put_object(
Bucket=bucket, Key=file_name, Body=file_data, ACL="bucket-owner-read"
)
if self.acl_enabled:
self.client.put_object(
Bucket=bucket, Key=file_name, Body=file_data, ACL="bucket-owner-read"
)
else:
self.client.put_object(
Bucket=bucket, Key=file_name, Body=file_data
)
LOG.info(f"Uploaded '{file_name}' as '{path}' to '{bucket}'")

0 comments on commit 3c62e61

Please sign in to comment.