8000 Address comments · localstack/localstack@4c00bab · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c00bab

Browse files
committed
Address comments
1 parent d598037 commit 4c00bab

File tree

6 files changed

+36
-19
lines changed

6 files changed

+36
-19
lines changed

localstack-core/localstack/services/lambda_/api_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
# pattern therefore we can sub this value in when appropriate.
109109
ARN_NAME_PATTERN_VALIDATION_TEMPLATE = "(arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{{2}}((-gov)|(-iso([a-z]?)))?-[a-z]+-\\d{{1}}:)?(\\d{{12}}:)?(function:)?([a-zA-Z0-9-_{0}]+)(:(\\$LATEST|[a-zA-Z0-9-_]+))?"
110110

111+
# AWS response when invalid ARNs are used in Tag operations.
111112
TAGGABLE_RESOURCE_ARN_PATTERN = "arn:(aws[a-zA-Z-]*):lambda:[a-z]{2}((-gov)|(-iso([a-z]?)))?-[a-z]+-\\d{1}:\\d{12}:(function:[a-zA-Z0-9-_]+(:(\\$LATEST|[a-zA-Z0-9-_]+))?|layer:([a-zA-Z0-9-_]+)|code-signing-config:csc-[a-z0-9]{17}|event-source-mapping:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})"
112113

113114

localstack-core/localstack/services/lambda_/invocation/lambda_models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,6 @@ class Function:
595595
provisioned_concurrency_configs: dict[str, ProvisionedConcurrencyConfiguration] = (
596596
dataclasses.field(default_factory=dict)
597597
)
598-
tags: dict[str, str] | None = (
599-
None # TODO: This should be removed in favour of the TaggingService
600-
)
601598

602599
lock: threading.RLock = dataclasses.field(default_factory=threading.RLock)
603600
next_version: int = 1

localstack-core/localstack/services/lambda_/provider.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,15 +1003,12 @@ def create_function(
10031003
),
10041004
)
10051005
fn.versions["$LATEST"] = version
1006-
# TODO: should validation failures here "fail" the function creation like it is now?
10071006
state.functions[function_name] = fn
10081007
self.lambda_service.create_function_version(version)
10091008

10101009
if tags := request.get("Tags"):
10111010
# This will check whether the function exists.
10121011
self._store_tags(arn.unqualified_arn(), tags)
1013-
# TODO: This should be removed in favour of using the TaggingService
1014-
fn.tags = tags
10151012

10161013
if request.get("Publish"):
10171014
version = self._publish_version_with_changes(
@@ -2367,8 +2364,9 @@ def create_function_url_config(
23672364
)
23682365

23692366
custom_id: str | None = None
2370-
# TODO: References to Function.tags should be replaced with calls to the TaggingService
2371-
if fn.tags is not None and TAG_KEY_CUSTOM_URL in fn.tags:
2367+
2368+
tags = self._get_tags(api_utils.unqualified_lambda_arn(function_name, account_id, region))
2369+
if TAG_KEY_CUSTOM_URL in tags:
23722370
# Note: I really wanted to add verification here that the
23732371
# url_id is unique, so we could surface that to the user ASAP.
23742372
# However, it seems like that information isn't available yet,
@@ -2378,9 +2376,7 @@ def create_function_url_config(
23782376
# just for this particular lambda function, but for the entire
23792377
# lambda provider. Therefore... that idea proved non-trivial!
23802378
custom_id_tag_value = (
2381-
f"{fn.tags[TAG_KEY_CUSTOM_URL]}-{qualifier}"
2382-
if qualifier
2383-
else fn.tags[TAG_KEY_CUSTOM_URL]
2379+
f"{tags[TAG_KEY_CUSTOM_URL]}-{qualifier}" if qualifier else tags[TAG_KEY_CUSTOM_URL]
23842380
)
23852381
if TAG_KEY_CUSTOM_URL_VALIDATOR.match(custom_id_tag_value):
23862382
custom_id = custom_id_tag_value
@@ -4237,7 +4233,6 @@ def tag_resource(
42374233
name, _, account, region = function_locators_from_arn(resource)
42384234
function = self._get_function(name, account, region)
42394235
with function.lock:
4240-
function.tags = tags
42414236
# dirty hack for changed revision id, should reevaluate model to prevent this:
42424237
latest_version = function.versions["$LATEST"]
42434238
function.versions["$LATEST"] = dataclasses.replace(
@@ -4266,11 +4261,8 @@ def untag_resource(
42664261
):
42674262
name, _, account, region = function_locators_from_arn(resource)
42684263
function = self._get_function(name, account, region)
4264+
# TODO: Potential race condition
42694265
with function.lock:
4270-
function.tags = {
4271-
tag["Key"]: tag["Value"]
4272-
for tag in state.TAGS.list_tags_for_resource(resource).get("Tags")
4273-
}
42744266
# dirty hack for changed revision id, should reevaluate model to prevent this:
42754267
latest_version = function.versions["$LATEST"]
42764268
function.versions["$LATEST"] = dataclasses.replace(

tests/aws/services/lambda_/test_lambda_api.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5520,7 +5520,7 @@ def test_tag_exceptions(
55205520
assert "b_key" in aws_client.lambda_.list_tags(Resource=function_arn)["Tags"]
55215521

55225522
@markers.aws.validated
5523-
def test_tag_limits(self, create_lambda_function, snapshot, aws_client):
5523+
def test_tag_limits(self, create_lambda_function, snapshot, aws_client, lambda_su_role):
55245524
"""test the limit of 50 tags per resource"""
55255525
function_name = f"fn-tag-{short_uid()}"
55265526
create_lambda_function(
@@ -5556,6 +5556,21 @@ def test_tag_limits(self, create_lambda_function, snapshot, aws_client):
55565556
aws_client.lambda_.tag_resource(Resource=function_arn, Tags={"a_key": "a_value"})
55575557
snapshot.match("tag_lambda_too_many_tags_additional", e.value.response)
55585558

5559+
# add too many tags on a CreateFunction
5560+
function_name = f"fn-tag-{short_uid()}"
5561+
zip_file_bytes = create_lambda_archive(load_file(TEST_LAMBDA_PYTHON_ECHO), get_content=True)
5562+
with pytest.raises(ClientError) as e:
5563+
aws_client.lambda_.create_function(
5564+
FunctionName=function_name,
5565+
Handler="index.handler",
5566+
Code={"ZipFile": zip_file_bytes},
5567+
PackageType="Zip",
5568+
Role=lambda_su_role,
5569+
Runtime=Runtime.python3_12,
5570+
Tags={f"{k}_key": f"{k}_value" for k in range(51)},
5571+
)
5572+
snapshot.match("create_function_invalid_tags", e.value.response)
5573+
55595574
@markers.aws.validated
55605575
def test_tag_versions(self, create_lambda_function, snapshot, aws_client):
55615576
function_name = f"fn-tag-{short_uid()}"

tests/aws/services/lambda_/test_lambda_api.snapshot.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6062,7 +6062,7 @@
60626062
}
60636063
},
60646064
"tests/aws/services/lambda_/test_lambda_api.py::TestLambdaTags::test_tag_limits": {
6065-
"recorded-date": "24-10-2024, 15:22:35",
6065+
"recorded-date": "28-10-2024, 14:16:38",
60666066
"recorded-content": {
60676067
"tag_lambda_too_many_tags": {
60686068
"Error": {
@@ -6254,6 +6254,18 @@
62546254
"HTTPHeaders": {},
62556255
"HTTPStatusCode": 400
62566256
}
6257+
},
6258+
"create_function_invalid_tags": {
6259+
"Error": {
6260+
"Code": "InvalidParameterValueException",
6261+
"Message": "Number of tags exceeds resource tag limit."
6262+
},
6263+
"Type": "User",
6264+
"message": "Number of tags exceeds resource tag limit.",
6265+
"ResponseMetadata": {
6266+
"HTTPHeaders": {},
6267+
"HTTPStatusCode": 400
6268+
}
62576269
}
62586270
}
62596271
},

tests/aws/services/lambda_/test_lambda_api.validation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@
573573
"last_validated_date": "2024-10-24T15:22:47+00:00"
574574
},
575575
"tests/aws/services/lambda_/test_lambda_api.py::TestLambdaTags::test_tag_limits": {
576-
"last_validated_date": "2024-10-24T15:22:33+00:00"
576+
"last_validated_date": "2024-10-28T14:16:36+00:00"
577577
},
578578
"tests/aws/services/lambda_/test_lambda_api.py::TestLambdaTags::test_tag_versions": {
579579
"last_validated_date": "2024-10-24T15:22:38+00:00"

0 commit comments

Comments
 (0)
0