10000 follow up on CloudFormation template URLs S3 URI by bentsku · Pull Request #9329 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

follow up on CloudFormation template URLs S3 URI #9329

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

Merged
merged 1 commit into from
Oct 11, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions localstack/services/cloudformation/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def convert_s3_to_local_url(url: str) -> str:
headers = {"host": url_parsed.netloc}
bucket_name, key_name = extract_bucket_name_and_key_from_headers_and_path(headers, path)

if not bucket_name or not key_name:
if url_parsed.scheme != "s3" and not (
url_parsed.netloc.startswith("s3.") or ".s3." in url_parsed.netloc
):
raise ValidationError("TemplateURL must be a supported URL.")
if url_parsed.scheme == "s3":
raise ValidationError(
f"S3 error: Domain name specified in {url_parsed.netloc} is not a valid S3 domain"
)

if not bucket_name or not key_name:
if not (url_parsed.netloc.startswith("s3.") or ".s3." in url_parsed.netloc):
raise ValidationError("TemplateURL must be a supported URL.")

# note: make sure to normalize the bucket name here!
bucket_name = normalize_bucket_name(bucket_name)
local_url = f"{config.service_url('s3')}/{bucket_name}/{key_name}"
Expand Down
8 changes: 4 additions & 4 deletions tests/aws/services/cloudformation/api/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ def test_create_stack_from_s3_template_url(
"""
)

aws_client.s3.put_object(Bucket=bucket_name, Key="template.yml", Body=to_bytes(template))
aws_client.s3.put_object(Bucket=bucket_name, Key="test/template.yml", Body=to_bytes(template))

match url_style:
case "s3_url":
template_url = f"s3://{bucket_name}/template.yml"
template_url = f"s3://{bucket_name}/test/template.yml"
case "http_path":
template_url = f"https://s3.amazonaws.com/{bucket_name}/template.yml"
template_url = f"https://s3.amazonaws.com/{bucket_name}/test/template.yml"
case "http_host":
template_url = f"https://{bucket_name}.s3.amazonaws.com/template.yml"
template_url = f"https://{bucket_name}.s3.amazonaws.com/test/template.yml"
case "http_invalid":
# note: using an invalid (non-existing) URL here, but in fact all non-S3 HTTP URLs are invalid in real AWS
template_url = "https://example.com/dummy.yml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
},
"tests/aws/services/cloudformation/api/test_templates.py::test_create_stack_from_s3_template_url[s3_url]": {
"recorded-date": "08-10-2023, 16:15:04",
"recorded-date": "11-10-2023, 00:03:44",
"recorded-content": {
"create-error": {
"Error": {
Expand All @@ -41,7 +41,7 @@
}
},
"tests/aws/services/cloudformation/api/test_templates.py::test_create_stack_from_s3_template_url[http_path]": {
"recorded-date": "08-10-2023, 16:15:14",
"recorded-date": "11-10-2023, 00:03:53",
"recorded-content": {
"matching-topic": [
{
Expand All @@ -51,7 +51,7 @@
}
},
"tests/aws/services/cloudformation/api/test_templates.py::test_create_stack_from_s3_template_url[http_host]": {
"recorded-date": "08-10-2023, 16:15:24",
"recorded-date": "11-10-2023, 00:04:02",
"recorded-content": {
"matching-topic": [
{
Expand All @@ -61,7 +61,7 @@
}
},
"tests/aws/services/cloudformation/api/test_templates.py::test_create_stack_from_s3_template_url[http_invalid]": {
"recorded-date": "08-10-2023, 16:15:26",
"recorded-date": "11-10-2023, 00:04:04",
"recorded-content": {
"create-error": {
"Error": {
Expand Down
0