8000 follow up on CFN template-url S3 URI (#9329) · codeperl/localstack@c129376 · GitHub
[go: up one dir, main page]

Skip to content

Commit c129376

Browse files
authored
follow up on CFN template-url S3 URI (localstack#9329)
1 parent 4ddec69 commit c129376

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

localstack/services/cloudformation/api_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ def convert_s3_to_local_url(url: str) -> str:
8686
headers = {"host": url_parsed.netloc}
8787
bucket_name, key_name = extract_bucket_name_and_key_from_headers_and_path(headers, path)
8888

89-
if not bucket_name or not key_name:
90-
if url_parsed.scheme != "s3" and not (
91-
url_parsed.netloc.startswith("s3.") or ".s3." in url_parsed.netloc
92-
):
93-
raise ValidationError("TemplateURL must be a supported URL.")
89+
if url_parsed.scheme == "s3":
9490
raise ValidationError(
9591
f"S3 error: Domain name specified in {url_parsed.netloc} is not a valid S3 domain"
9692
)
9793

94+
if not bucket_name or not key_name:
95+
if not (url_parsed.netloc.startswith("s3.") or ".s3." in url_parsed.netloc):
96+
raise ValidationError("TemplateURL must be a supported URL.")
97+
9898
# note: make sure to normalize the bucket name here!
9999
bucket_name = normalize_bucket_name(bucket_name)
100100
local_url = f"{config.service_url('s3')}/{bucket_name}/{key_name}"

tests/aws/services/cloudformation/api/test_templates.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ def test_create_stack_from_s3_template_url(
5555
"""
5656
)
5757

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

6060
match url_style:
6161
case "s3_url":
62-
template_url = f"s3://{bucket_name}/template.yml"
62+
template_url = f"s3://{bucket_name}/test/template.yml"
6363
case "http_path":
64-
template_url = f"https://s3.amazonaws.com/{bucket_name}/template.yml"
64+
template_url = f"https://s3.amazonaws.com/{bucket_name}/test/template.yml"
6565
case "http_host":
66-
template_url = f"https://{bucket_name}.s3.amazonaws.com/template.yml"
66+
template_url = f"https://{bucket_name}.s3.amazonaws.com/test/template.yml"
6767
case "http_invalid":
6868
# note: using an invalid (non-existing) URL here, but in fact all non-S3 HTTP URLs are invalid in real AWS
6969
template_url = "https://example.com/dummy.yml"

tests/aws/services/cloudformation/api/test_templates.snapshot.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
}
2626
},
2727
"tests/aws/services/cloudformation/api/test_templates.py::test_create_stack_from_s3_template_url[s3_url]": {
28-
"recorded-date": "08-10-2023, 16:15:04",
28+
"recorded-date": "11-10-2023, 00:03:44",
2929
"recorded-content": {
3030
"create-error": {
3131
"Error": {
@@ -41,7 +41,7 @@
4141
}
4242
},
4343
"tests/aws/services/cloudformation/api/test_templates.py::test_create_stack_from_s3_template_url[http_path]": {
44-
"recorded-date": "08-10-2023, 16:15:14",
44+
"recorded-date": "11-10-2023, 00:03:53",
4545
"recorded-content": {
4646
"matching-topic": [
4747
{
@@ -51,7 +51,7 @@
5151
}
5252
},
5353
"tests/aws/services/cloudformation/api/test_templates.py::test_create_stack_from_s3_template_url[http_host]": {
54-
"recorded-date": "08-10-2023, 16:15:24",
54+
"r 7832 ecorded-date": "11-10-2023, 00:04:02",
5555
"recorded-content": {
5656
"matching-topic": [
5757
{
@@ -61,7 +61,7 @@
6161
}
6262
},
6363
"tests/aws/services/cloudformation/api/test_templates.py::test_create_stack_from_s3_template_url[http_invalid]": {
64-
"recorded-date": "08-10-2023, 16:15:26",
64+
"recorded-date": "11-10-2023, 00:04:04",
6565
"recorded-content": {
6666
"create-error": {
6767
"Error": {

0 commit comments

Comments
 (0)
0