Skip to content

Commit da033fb

Browse files
Merge pull request #1887 from Lawiss/add-s3-acl-to-cli
Adds --s3-acl option to the cli to be able to set S3 report permissions.
2 parents d71d811 + 7fa29bc commit da033fb

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

elementary/clients/s3/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ def send_report(
4141
bucket_report_path = remote_bucket_file_path or report_filename
4242
bucket_website_url = None
4343
logger.info(f'Uploading to S3 bucket "{self.config.s3_bucket_name}"')
44+
45+
extra_args = {"ContentType": "text/html"}
46+
if self.config.s3_acl is not None:
47+
extra_args["ACL"] = self.config.s3_acl
4448
self.client.upload_file(
4549
local_html_file_path,
4650
self.config.s3_bucket_name,
4751
bucket_report_path,
48-
ExtraArgs={"ContentType": "text/html"},
52+
ExtraArgs=extra_args,
4953
)
5054
logger.info("Uploaded report to S3.")
5155
if self.config.update_bucket_website:

elementary/config/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262
aws_session_token: Optional[str] = None,
6363
s3_endpoint_url: Optional[str] = None,
6464
s3_bucket_name: Optional[str] = None,
65+
s3_acl: Optional[str] = None,
6566
google_project_name: Optional[str] = None,
6667
google_service_account_path: Optional[str] = None,
6768
gcs_bucket_name: Optional[str] = None,
@@ -159,6 +160,7 @@ def __init__(
159160
self.aws_access_key_id = aws_access_key_id
160161
self.aws_secret_access_key = aws_secret_access_key
161162
self.aws_session_token = aws_session_token
163+
self.s3_acl = s3_acl
162164

163165
google_config = config.get(self._GOOGLE, {})
164166
self.google_project_name = self._first_not_none(

elementary/monitor/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,12 @@ def report(
526526
default=None,
527527
help="The name of the S3 bucket to upload the report to.",
528528
)
529+
@click.option(
530+
"--s3-acl",
531+
type=str,
532+
default=None,
533+
help="S3 Canned ACL value used to modify report permissions, for example set to 'public-read' to make the report publicly accessible.",
534+
)
529535
@click.option(
530536
"--google-service-account-path",
531537
type=str,
@@ -638,6 +644,7 @@ def send_report(
638644
aws_session_token,
639645
s3_endpoint_url,
640646
s3_bucket_name,
647+
s3_acl,
641648
azure_connection_string,
642649
azure_container_name,
643650
google_service_account_path,
@@ -686,6 +693,7 @@ def send_report(
686693
azure_container_name=azure_container_name,
687694
s3_endpoint_url=s3_endpoint_url,
688695
s3_bucket_name=s3_bucket_name,
696+
s3_acl=s3_acl,
689697
google_service_account_path=google_service_account_path,
690698
google_project_name=google_project_name,
691699
gcs_bucket_name=gcs_bucket_name,

0 commit comments

Comments
 (0)