Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 994350a

Browse files
authored
Update remaining host matching for localhost.localstack.cloud (localstack#9642)
1 parent a59fd6d commit 994350a

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

‎localstack/services/apigateway/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
r"^/restapis/([A-Za-z0-9_\\-]+)(?:/([A-Za-z0-9\_($|%%24)\\-]+))?/%s/(.*)$" % PATH_USER_REQUEST
6161
)
6262
# URL pattern for invocations
63-
HOST_REGEX_EXECUTE_API = r"(?:.*://)?([a-zA-Z0-9]+)(?:(-vpce-[^.]+))?\.execute-api\.(localhost.localstack.cloud|([^\.]+)\.amazonaws\.com)(.*)"
63+
HOST_REGEX_EXECUTE_API = r"(?:.*://)?([a-zA-Z0-9]+)(?:(-vpce-[^.]+))?\.execute-api\.(.*)"
6464

6565
# regex path patterns
6666
PATH_REGEX_MAIN = r"^/restapis/([A-Za-z0-9_\-]+)/[a-z]+(\?.*)?"

‎localstack/services/cloudformation/engine/template_deployer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from localstack.services.cloudformation.engine.parameters import StackParameter
1919
from localstack.services.cloudformation.engine.quirks import VALID_GETATT_PROPERTIES
2020
from localstack.services.cloudformation.engine.template_utils import (
21+
AWS_URL_SUFFIX,
2122
fn_equals_type_conversion,
2223
get_deps_for_resource,
2324
)
@@ -44,7 +45,6 @@
4445

4546
ACTION_CREATE = "create"
4647
ACTION_DELETE = "delete"
47-
AWS_URL_SUFFIX = localstack_host().host # value is "amazonaws.com" in real AWS
4848

4949
REGEX_OUTPUT_APIGATEWAY = re.compile(
5050
rf"^(https?://.+\.execute-api\.)(?:[^-]+-){{2,3}}\d\.(amazonaws\.com|{AWS_URL_SUFFIX})/?(.*)$"

‎localstack/services/cloudformation/engine/template_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from typing import Any
33

44
from localstack.services.cloudformation.deployment_utils import PLACEHOLDER_AWS_NO_VALUE
5+
from localstack.utils.urls import localstack_host
56

6-
# TODO: deduplicate
7-
AWS_URL_SUFFIX = "localhost.localstack.cloud"
7+
AWS_URL_SUFFIX = localstack_host().host # value is "amazonaws.com" in real AWS
88

99

1010
def get_deps_for_resource(resource: dict, evaluated_conditions: dict[str, bool]) -> set[str]:

‎localstack/services/s3/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,13 @@
187187
from localstack.utils.patch import patch
188188
from localstack.utils.strings import short_uid
189189
from localstack.utils.time import parse_timestamp
190+
from localstack.utils.urls import localstack_host
190191

191192
LOG = logging.getLogger(__name__)
192193

193194
os.environ[
194195
"MOTO_S3_CUSTOM_ENDPOINTS"
195-
] = "s3.localhost.localstack.cloud:4566,s3.localhost.localstack.cloud"
196+
] = f"s3.{localstack_host().host_and_port()},s3.{localstack_host().host}"
196197

197198
MOTO_CANONICAL_USER_ID = "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a"
198199
# max file size for S3 objects kept in memory (500 KB by default)

‎localstack/services/sqs/query_api.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@
3838

3939
@route(
4040
'/<regex("[0-9]{12}"):account_id>/<regex("[a-zA-Z0-9_-]+(.fifo)?"):queue_name>',
41-
host='sqs.<regex("([a-z0-9-]+\\.)?"):region>localhost.localstack.cloud<regex("(:[0-9]{2,5})?"):port>',
41+
host='sqs.<regex("([a-z0-9-]+\\.)?"):region><regex(".*"):domain><regex("(:[0-9]{2,5})?"):port>',
4242
methods=["POST", "GET"],
4343
)
4444
def standard_strategy_handler(
45-
request: Request, account_id: str, queue_name: str, region: str = None, port: int = None
45+
request: Request,
46+
account_id: str,
47+
queue_name: str,
48+
region: str = None,
49+
domain: str = None,
50+
port: int = None,
4651
):
4752
"""
4853
Handler for modern-style endpoints which always have the region encoded.
@@ -61,11 +66,16 @@ def path_strategy_handler(request: Request, region, account_id: str, queue_name:
6166

6267
@route(
6368
'/<regex("[0-9]{12}"):account_id>/<regex("[a-zA-Z0-9_-]+(.fifo)?"):queue_name>',
64-
host='<regex("([a-z0-9-]+\\.)?"):region>queue.localhost.localstack.cloud<regex("(:[0-9]{2,5})?"):port>',
69+
host='<regex("([a-z0-9-]+\\.)?"):region>queue.<regex(".*"):domain><regex("(:[0-9]{2,5})?"):port>',
6570
methods=["POST", "GET"],
6671
)
6772
def domain_strategy_handler(
68-
request: Request, account_id: str, queue_name: str, region: str = None, port: int = None
73+
request: Request,
74+
account_id: str,
75+
queue_name: str,
76+
region: str = None,
77+
domain: str = None,
78+
port: int = None,
6979
):
7080
"""Uses the endpoint host to extract the region. See:
7181
https://docs.aws.amazon.com/general/latest/gr/sqs-service.html"""

‎localstack/utils/crypto.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .files import TMP_FILES, file_exists_not_empty, load_file, new_tmp_file, save_file
1212
from .strings import short_uid, to_bytes, to_str
1313
from .sync import synchronized
14+
from .urls import localstack_host
1415

1516
LOG = logging.getLogger(__name__)
1617

@@ -82,6 +83,8 @@ def store_cert_key_files(base_filename):
8283
k = crypto.PKey()
8384
k.generate_key(crypto.TYPE_RSA, 2048)
8485

86+
host_definition = localstack_host()
87+
8588
# create a self-signed cert
8689
cert = crypto.X509()
8790
subj = cert.get_subject()
@@ -101,8 +104,8 @@ def store_cert_key_files(base_filename):
101104
cert.set_issuer(cert.get_subject())
102105
cert.set_pubkey(k)
103106
alt_names = (
104-
b"DNS:localhost,DNS:test.localhost.atlassian.io,DNS:localhost.localstack.cloud,IP:127.0.0.1"
105-
)
107+
f"DNS:localhost,DNS:test.localhost.atlassian.io,DNS:localhost.localstack.cloud,DNS:{host_definition.host}IP:127.0.0.1"
108+
).encode("utf8")
106109
cert.add_extensions(
107110
[
108111
crypto.X509Extension(b"subjectAltName", False, alt_names),

0 commit comments

Comments
 (0)