Skip to content

Commit 7dd4321

Browse files
committed
fail early with hyphen in custom_id tag
1 parent 5e8dc09 commit 7dd4321

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

localstack-core/localstack/services/apigateway/next_gen/provider.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from localstack.aws.api import CommonServiceException, RequestContext, handler
22
from localstack.aws.api.apigateway import (
3+
BadRequestException,
34
CacheClusterSize,
5+
CreateRestApiRequest,
46
CreateStageRequest,
57
Deployment,
68
DeploymentCanarySettings,
@@ -12,12 +14,14 @@
1214
NotFoundException,
1315
NullableBoolean,
1416
NullableInteger,
17+
RestApi,
1518
Stage,
1619
StatusCode,
1720
String,
1821
TestInvokeMethodRequest,
1922
TestInvokeMethodResponse,
2023
)
24+
from localstack.constants import TAG_KEY_CUSTOM_ID
2125
from localstack.services.apigateway.helpers import (
2226
get_apigateway_store,
2327
get_moto_rest_api,
@@ -56,6 +60,16 @@ def on_after_init(self):
5660
apply_patches()
5761
self.router.register_routes()
5862

63+
@handler("CreateRestApi", expand=False)
64+
def create_rest_api(self, context: RequestContext, request: CreateRestApiRequest) -> RestApi:
65+
if "-" in request.get("tags", {}).get(TAG_KEY_CUSTOM_ID, ""):
66+
raise BadRequestException(
67+
f"The '{TAG_KEY_CUSTOM_ID}' tag cannot contain the '-' character."
68+
)
69+
70+
response = super().create_rest_api(context, request)
71+
return response
72+
5973
@handler("DeleteRestApi")
6074
def delete_rest_api(self, context: RequestContext, rest_api_id: String, **kwargs) -> None:
6175
super().delete_rest_api(context, rest_api_id, **kwargs)

tests/aws/services/apigateway/test_apigateway_api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,21 @@ def test_create_rest_api_with_tags(self, apigw_create_rest_api, snapshot, aws_cl
201201
snapshot.match("get-rest-apis-w-tags", response)
202202

203203
@markers.aws.only_localstack
204-
def test_create_rest_api_with_custom_id_tag(self, apigw_create_rest_api):
204+
def test_create_rest_api_with_custom_id_tag(self, apigw_create_rest_api, aws_client):
205205
custom_id_tag = "testid123"
206206
response = apigw_create_rest_api(
207207
name="my_api", description="this is my api", tags={TAG_KEY_CUSTOM_ID: custom_id_tag}
208208
)
209209
api_id = response["id"]
210210
assert api_id == custom_id_tag
211211

212+
with pytest.raises(aws_client.apigateway.exceptions.BadRequestException):
213+
apigw_create_rest_api(
214+
name="my_api",
215+
description="bad custom id",
216+
tags={TAG_KEY_CUSTOM_ID: "bad-custom-id-hyphen"},
217+
)
218+
212219
@markers.aws.validated
213220
def test_update_rest_api_operation_add_remove(
214221
self, apigw_create_rest_api, snapshot, aws_client

0 commit comments

Comments
 (0)