Skip to content

Commit

Permalink
aws - output - strip trailing slashes from s3 output url paths (#8559)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkerrigan committed May 12, 2023
1 parent 072d238 commit 0819287
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions c7n/resources/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ def get_bucket_url_with_region(bucket_url, region):
query = f"region={region}"
if parsed.query:
query = parsed.query + f"&region={region}"
parts = list(parsed)
parts[4] = query
parts = parsed._replace(
path=parsed.path.strip("/"),
query=query
)
return urlparse.urlunparse(parts)


Expand Down
7 changes: 7 additions & 0 deletions tests/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ def test_get_bucket_url_s3_cross_region():
assert aws.get_bucket_url_with_region(
"s3://slack.cloudcustodian.io",
"us-west-2") == "s3://slack.cloudcustodian.io?region=us-east-1"
assert aws.get_bucket_url_with_region(
"s3://slack.cloudcustodian.io/",
"us-west-2") == "s3://slack.cloudcustodian.io?region=us-east-1"


@vcr.use_cassette(
Expand All @@ -533,3 +536,7 @@ def test_get_bucket_url_s3_same_region():
assert aws.get_bucket_url_with_region(
"s3://slack.cloudcustodian.io?param=x",
"us-east-1") == "s3://slack.cloudcustodian.io?param=x&region=us-east-1"

assert aws.get_bucket_url_with_region(
"s3://slack.cloudcustodian.io/logs/?param=x",
"us-east-1") == "s3://slack.cloudcustodian.io/logs?param=x&region=us-east-1"

0 comments on commit 0819287

Please sign in to comment.