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

output - strip trailing slashes from s3 output url paths #8559

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"