Skip to content

Bump moto-ext to 5.0.17.post1 #11659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion localstack-core/localstack/services/apigateway/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from jsonpatch import apply_patch
from jsonpointer import JsonPointerException
from moto.apigateway import models as apigw_models
from moto.apigateway.models import Integration, Resource
from moto.apigateway.models import APIGatewayBackend, Integration, Resource
from moto.apigateway.models import RestAPI as MotoRestAPI
from moto.apigateway.utils import create_id as create_resource_id

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


def get_moto_backend(account_id: str, region: str) -> APIGatewayBackend:
return apigw_models.apigateway_backends[account_id][region]


def get_moto_rest_api(context: RequestContext, rest_api_id: str) -> MotoRestAPI:
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
if rest_api := moto_backend.apis.get(rest_api_id):
Expand Down
29 changes: 16 additions & 13 deletions localstack-core/localstack/services/apigateway/legacy/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
from copy import deepcopy
from datetime import datetime
from operator import itemgetter
from typing import IO, Any

from moto.apigateway import models as apigw_models
Expand Down Expand Up @@ -99,6 +100,7 @@
OpenAPIExt,
apply_json_patch_safe,
get_apigateway_store,
get_moto_backend,
get_moto_rest_api,
get_regional_domain_name,
get_rest_api_container,
Expand Down Expand Up @@ -725,7 +727,7 @@ def put_method(
**kwargs,
) -> Method:
# TODO: add missing validation? check order of validation as well
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
moto_backend = get_moto_backend(context.account_id, context.region)
moto_rest_api: MotoRestAPI = moto_backend.apis.get(rest_api_id)
if not moto_rest_api or not (moto_resource := moto_rest_api.resources.get(resource_id)):
raise NotFoundException("Invalid Resource identifier specified")
Expand Down Expand Up @@ -792,7 +794,7 @@ def update_method(
) -> Method:
# see https://www.linkedin.com/pulse/updating-aws-cli-patch-operations-rest-api-yitzchak-meirovich/
# for path construction
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
moto_backend = get_moto_backend(context.account_id, context.region)
moto_rest_api: MotoRestAPI = moto_backend.apis.get(rest_api_id)
if not moto_rest_api or not (moto_resource := moto_rest_api.resources.get(resource_id)):
raise NotFoundException("Invalid Resource identifier specified")
Expand Down Expand Up @@ -907,7 +909,7 @@ def delete_method(
http_method: String,
**kwargs,
) -> None:
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
moto_backend = get_moto_backend(context.account_id, context.region)
moto_rest_api: MotoRestAPI = moto_backend.apis.get(rest_api_id)
if not moto_rest_api or not (moto_resource := moto_rest_api.resources.get(resource_id)):
raise NotFoundException("Invalid Resource identifier specified")
Expand All @@ -929,7 +931,7 @@ def get_method_response(
**kwargs,
) -> MethodResponse:
# this could probably be easier in a patch?
moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
moto_backend = get_moto_backend(context.account_id, context.region)
moto_rest_api: MotoRestAPI = moto_backend.apis.get(rest_api_id)
# TODO: snapshot test different possibilities
if not moto_rest_api or not (moto_resource := moto_rest_api.resources.get(resource_id)):
Expand Down Expand Up @@ -1002,7 +1004,7 @@ def update_stage(
) -> Stage:
call_moto(context)

moto_backend = apigw_models.apigateway_backends[context.account_id][context.region]
moto_backend = get_moto_backend(context.account_id, context.region)
moto_rest_api: MotoRestAPI = moto_backend.apis.get(rest_api_id)
if not (moto_stage := moto_rest_api.stages.get(stage_name)):
raise NotFoundException("Invalid Stage identifier specified")
Expand Down Expand Up @@ -2076,25 +2078,26 @@ def get_api_keys(
include_values: NullableBoolean = None,
**kwargs,
) -> ApiKeys:
moto_response: ApiKeys = call_moto(context=context)
item_list = PaginatedList(moto_response["items"])
# TODO: migrate API keys in our store
moto_backend = get_moto_backend(context.account_id, context.region)
api_keys = [api_key.to_json() for api_key in moto_backend.keys.values()]
if not include_values:
for api_key in api_keys:
api_key.pop("value")

def token_generator(item):
return item["id"]
item_list = PaginatedList(api_keys)

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

paginated_list, next_token = item_list.get_page(
token_generator=token_generator,
token_generator=itemgetter("id"),
next_token=position,
page_size=limit,
filter_function=filter_function if name_query else None,
)

return ApiKeys(
items=paginated_list, warnings=moto_response.get("warnings"), position=next_token
)
return ApiKeys(items=paginated_list, position=next_token)

def update_api_key(
self,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ runtime = [
"json5>=0.9.11",
"jsonpath-ng>=1.6.1",
"jsonpath-rw>=1.4.0",
"moto-ext[all]==5.0.15.post4",
"moto-ext[all]==5.0.17.post1",
"opensearch-py>=2.4.1",
"pymongo>=4.2.0",
"pyopenssl>=23.0.0",
Expand Down
2 changes: 1 addition & 1 deletion requirements-basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ certifi==2024.8.30
# via requests
cffi==1.17.1
# via cryptography
charset-normalizer==3.3.2
charset-normalizer==3.4.0
# via requests
click==8.1.7
# via localstack-core (pyproject.toml)
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ jsonpointer==3.0.0
jsonschema==4.23.0
# via
# aws-sam-translator
# moto-ext
# openapi-core
# openapi-schema-validator
# openapi-spec-validator
Expand Down Expand Up @@ -255,7 +256,7 @@ mdurl==0.1.2
# via markdown-it-py
more-itertools==10.5.0
# via openapi-core
moto-ext==5.0.15.post4
moto-ext==5.0.17.post1
# via localstack-core
mpmath==1.3.0
# via sympy
Expand Down
3 changes: 2 additions & 1 deletion requirements-runtime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ jsonpointer==3.0.0
jsonschema==4.23.0
# via
# aws-sam-translator
# moto-ext
# openapi-core
# openapi-schema-validator
# openapi-spec-validator
Expand All @@ -189,7 +190,7 @@ mdurl==0.1.2
# via markdown-it-py
more-itertools==10.5.0
# via openapi-core
moto-ext==5.0.15.post4
moto-ext==5.0.17.post1
# via localstack-core (pyproject.toml)
mpmath==1.3.0
# via sympy
Expand Down
3 changes: 2 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ jsonpointer==3.0.0
jsonschema==4.23.0
# via
# aws-sam-translator
# moto-ext
# openapi-core
# openapi-schema-validator
# openapi-spec-validator
Expand Down Expand Up @@ -239,7 +240,7 @@ mdurl==0.1.2
# via markdown-it-py
more-itertools==10.5.0
# via openapi-core
moto-ext==5.0.15.post4
moto-ext==5.0.17.post1
# via localstack-core
mpmath==1.3.0
# via sympy
Expand Down
3 changes: 2 additions & 1 deletion requirements-typehint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ jsonpointer==3.0.0
jsonschema==4.23.0
# via
# aws-sam-translator
# moto-ext
# openapi-core
# openapi-schema-validator
# openapi-spec-validator
Expand Down Expand Up @@ -259,7 +260,7 @@ mdurl==0.1.2
# via markdown-it-py
more-itertools==10.5.0
# via openapi-core
moto-ext==5.0.15.post4
moto-ext==5.0.17.post1
# via localstack-core
mpmath==1.3.0
# via sympy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ContextVarsIdentity,
)
from localstack.testing.config import TEST_AWS_ACCOUNT_ID, TEST_AWS_REGION_NAME
from localstack.utils.strings import short_uid

TEST_API_ID = "testapi"
TEST_API_STAGE = "dev"
Expand Down Expand Up @@ -94,9 +95,9 @@ def _handler_invoker(context: RestApiInvocationContext):
def create_usage_plan(moto_backend):
def _create_usage_plan(attach_stage: bool, attach_key_id: str = None, backend=None):
backend = backend or moto_backend
stage_config = {}
stage_config = {"name": short_uid()}
if attach_stage:
stage_config = {"apiStages": [{"apiId": TEST_API_ID, "stage": TEST_API_STAGE}]}
stage_config["apiStages"] = [{"apiId": TEST_API_ID, "stage": TEST_API_STAGE}]
usage_plan = backend.create_usage_plan(stage_config)
if attach_key_id:
backend.create_usage_plan_key(
Expand Down
Loading