Skip to content

Commit a2bc9f1

Browse files
viren-nadkarnibentsku
authored andcommitted
Bump moto-ext to 5.0.17.post1 (#11659)
Co-authored-by: Benjamin Simon <benjh.simon@gmail.com>
1 parent f4f74bf commit a2bc9f1

File tree

8 files changed

+33
-21
lines changed

8 files changed

+33
-21
lines changed

localstack-core/localstack/services/apigateway/helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from jsonpatch import apply_patch
1111
from jsonpointer import JsonPointerException
1212
from moto.apigateway import models as apigw_models
13-
from moto.apigateway.models import Integration, Resource
13+
from moto.apigateway.models import APIGatewayBackend, Integration, Resource
1414
from moto.apigateway.models import RestAPI as MotoRestAPI
1515
from moto.apigateway.utils import create_id as create_resource_id
1616

@@ -104,6 +104,10 @@ def get_apigateway_store_for_invocation(context: ApiInvocationContext) -> ApiGat
104104
return apigateway_stores[account_id][region_name]
105105

106106

107+
def get_moto_backend(account_id: str, region: str) -> APIGatewayBackend:
108+
return apigw_models.apigateway_backends[account_id][region]
109+
110+
107111
def get_moto_rest_api(context: RequestContext, rest_api_id: str) -> MotoRestAPI:
108112
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
109113
if rest_api := moto_backend.apis.get(rest_api_id):

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
from copy import deepcopy
77
from datetime import datetime
8+
from operator import itemgetter
89
from typing import IO, Any
910

1011
from moto.apigateway import models as apigw_models
@@ -99,6 +100,7 @@
99100
OpenAPIExt,
100101
apply_json_patch_safe,
101102
get_apigateway_store,
103+
get_moto_backend,
102104
get_moto_rest_api,
103105
get_regional_domain_name,
104106
get_rest_api_container,
@@ -725,7 +727,7 @@ def put_method(
725727
**kwargs,
726728
) -> Method:
727729
# TODO: add missing validation? check order of validation as well
728-
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
730+
moto_backend = get_moto_backend(context.account_id, context.region)
729731
moto_rest_api: MotoRestAPI = moto_backend.apis.get(rest_api_id)
730732
if not moto_rest_api or not (moto_resource := moto_rest_api.resources.get(resource_id)):
731733
raise NotFoundException("Invalid Resource identifier specified")
@@ -792,7 +794,7 @@ def update_method(
792794
) -> Method:
793795
# see https://www.linkedin.com/pulse/updating-aws-cli-patch-operations-rest-api-yitzchak-meirovich/
794796
# for path construction
795-
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
797+
moto_backend = get_moto_backend(context.account_id, context.region)
796798
moto_rest_api: MotoRestAPI = moto_backend.apis.get(rest_api_id)
797799
if not moto_rest_api or not (moto_resource := moto_rest_api.resources.get(resource_id)):
798800
raise NotFoundException("Invalid Resource identifier specified")
@@ -907,7 +909,7 @@ def delete_method(
907909
http_method: String,
908910
**kwargs,
909911
) -> None:
910-
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
912+
moto_backend = get_moto_backend(context.account_id, context.region)
911913
moto_rest_api: MotoRestAPI = moto_backend.apis.get(rest_api_id)
912914
if not moto_rest_api or not (moto_resource := moto_rest_api.resources.get(resource_id)):
913915
raise NotFoundException("Invalid Resource identifier specified")
@@ -929,7 +931,7 @@ def get_method_response(
929931
**kwargs,
930932
) -> MethodResponse:
931933
# this could probably be easier in a patch?
932-
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
934+
moto_backend = get_moto_backend(context.account_id, context.region)
933935
moto_rest_api: MotoRestAPI = moto_backend.apis.get(rest_api_id)
934936
# TODO: snapshot test different possibilities
935937
if not moto_rest_api or not (moto_resource := moto_rest_api.resources.get(resource_id)):
@@ -1002,7 +1004,7 @@ def update_stage(
10021004
) -> Stage:
10031005
call_moto(context)
10041006

1005-
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
1007+
moto_backend = get_moto_backend(context.account_id, context.region)
10061008
moto_rest_api: MotoRestAPI = moto_backend.apis.get(rest_api_id)
10071009
if not (moto_stage := moto_rest_api.stages.get(stage_name)):
10081010
raise NotFoundException("Invalid Stage identifier specified")
@@ -2076,25 +2078,26 @@ def get_api_keys(
20762078
include_values: NullableBoolean = None,
20772079
**kwargs,
20782080
) -> ApiKeys:
2079-
moto_response: ApiKeys = call_moto(context=context)
2080-
item_list = PaginatedList(moto_response["items"])
2081+
# TODO: migrate API keys in our store
2082+
moto_backend = get_moto_backend(context.account_id, context.region)
2083+
api_keys = [api_key.to_json() for api_key in moto_backend.keys.values()]
2084+
if not include_values:
2085+
for api_key in api_keys:
2086+
api_key.pop("value")
20812087

2082-
def token_generator(item):
2083-
return item["id"]
2088+
item_list = PaginatedList(api_keys)
20842089

20852090
def filter_function(item):
20862091
return item["name"].startswith(name_query)
20872092

20882093
paginated_list, next_token = item_list.get_page(
2089-
token_generator=token_generator,
2094+
token_generator=itemgetter("id"),
20902095
next_token=position,
20912096
page_size=limit,
20922097
filter_function=filter_function if name_query else None,
20932098
)
20942099

2095-
return ApiKeys(
2096-
items=paginated_list, warnings=moto_response.get("warnings"), position=next_token
2097-
)
2100+
return ApiKeys(items=paginated_list, position=next_token)
20982101

20992102
def update_api_key(
21002103
self,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ runtime = [
9393
"json5>=0.9.11",
9494
"jsonpath-ng>=1.6.1",
9595
"jsonpath-rw>=1.4.0",
96-
"moto-ext[all]==5.0.15.post4",
96+
"moto-ext[all]==5.0.17.post1",
9797
"opensearch-py>=2.4.1",
9898
"pymongo>=4.2.0",
9999
"pyopenssl>=23.0.0",

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ jsonpointer==3.0.0
228228
jsonschema==4.23.0
229229
# via
230230
# aws-sam-translator
231+
# moto-ext
231232
# openapi-core
232233
# openapi-schema-validator
233234
# openapi-spec-validator
@@ -255,7 +256,7 @@ mdurl==0.1.2
255256
# via markdown-it-py
256257
more-itertools==10.5.0
257258
# via openapi-core
258-
moto-ext==5.0.15.post4
259+
moto-ext==5.0.17.post1
259260
# via localstack-core
260261
mpmath==1.3.0
261262
# via sympy

requirements-runtime.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ jsonpointer==3.0.0
164164
jsonschema==4.23.0
165165
# via
166166
# aws-sam-translator
167+
# moto-ext
167168
# openapi-core
168169
# openapi-schema-validator
169170
# openapi-spec-validator
@@ -189,7 +190,7 @@ mdurl==0.1.2
189190
# via markdown-it-py
190191
more-itertools==10.5.0
191192
# via openapi-core
192-
moto-ext==5.0.15.post4
193+
moto-ext==5.0.17.post1
193194
# via localstack-core (pyproject.toml)
194195
mpmath==1.3.0
195196
# via sympy

requirements-test.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ jsonpointer==3.0.0
212212
jsonschema==4.23.0
213213
# via
214214
# aws-sam-translator
215+
# moto-ext
215216
# openapi-core
216217
# openapi-schema-validator
217218
# openapi-spec-validator
@@ -239,7 +240,7 @@ mdurl==0.1.2
239240
# via markdown-it-py
240241
more-itertools==10.5.0
241242
# via openapi-core
242-
moto-ext==5.0.15.post4
243+
moto-ext==5.0.17.post1
243244
# via localstack-core
244245
mpmath==1.3.0
245246
# via sympy

requirements-typehint.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ jsonpointer==3.0.0
232232
jsonschema==4.23.0
233233
# via
234234
# aws-sam-translator
235+
# moto-ext
235236
# openapi-core
236237
# openapi-schema-validator
237238
# openapi-spec-validator
@@ -259,7 +260,7 @@ mdurl==0.1.2
259260
# via markdown-it-py
260261
more-itertools==10.5.0
261262
# via openapi-core
262-
moto-ext==5.0.15.post4
263+
moto-ext==5.0.17.post1
263264
# via localstack-core
264265
mpmath==1.3.0
265266
# via sympy

tests/unit/services/apigateway/test_handler_api_key_validation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
ContextVarsIdentity,
1818
)
1919
from localstack.testing.config import TEST_AWS_ACCOUNT_ID, TEST_AWS_REGION_NAME
20+
from localstack.utils.strings import short_uid
2021

2122
TEST_API_ID = "testapi"
2223
TEST_API_STAGE = "dev"
@@ -94,9 +95,9 @@ def _handler_invoker(context: RestApiInvocationContext):
9495
def create_usage_plan(moto_backend):
9596
def _create_usage_plan(attach_stage: bool, attach_key_id: str = None, backend=None):
9697
backend = backend or moto_backend
97-
stage_config = {}
98+
stage_config = {"name": short_uid()}
9899
if attach_stage:
99-
stage_config = {"apiStages": [{"apiId": TEST_API_ID, "stage": TEST_API_STAGE}]}
100+
stage_config["apiStages"] = [{"apiId": TEST_API_ID, "stage": TEST_API_STAGE}]
100101
usage_plan = backend.create_usage_plan(stage_config)
101102
if attach_key_id:
102103
backend.create_usage_plan_key(

0 commit comments

Comments
 (0)