Skip to content

APIGW NG: fix storing store attribute instead of full store #11702

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 1 commit into from
Oct 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from localstack.http import Response
from localstack.services.apigateway.models import ApiGatewayStore, apigateway_stores
from localstack.services.edge import ROUTER
from localstack.services.stores import AccountRegionBundle

from .context import RestApiInvocationContext
from .gateway import RestApiGateway
Expand Down Expand Up @@ -38,12 +39,14 @@ class ApiGatewayEndpoint:
Gateway to be processed by the handler chain.
"""

def __init__(self, rest_gateway: RestApiGateway = None, store: ApiGatewayStore = None):
def __init__(self, rest_gateway: RestApiGateway = None, store: AccountRegionBundle = None):
self.rest_gateway = rest_gateway or RestApiGateway()
# we only access CrossAccount attributes in the handler, so we use a global store in default account and region
self._global_store = (
store or apigateway_stores[DEFAULT_AWS_ACCOUNT_ID][AWS_REGION_US_EAST_1]
)
self._store = store or apigateway_stores

@property
def _global_store(self) -> ApiGatewayStore:
return self._store[DEFAULT_AWS_ACCOUNT_ID][AWS_REGION_US_EAST_1]

def __call__(self, request: Request, **kwargs: Unpack[RouteHostPathParameters]) -> Response:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
TestInvokeMethodRequest,
TestInvokeMethodResponse,
)
from localstack.constants import AWS_REGION_US_EAST_1, DEFAULT_AWS_ACCOUNT_ID
from localstack.services.apigateway.helpers import (
get_apigateway_store,
get_moto_rest_api,
Expand Down Expand Up @@ -47,8 +46,7 @@ def __init__(self, router: ApiGatewayRouter = None):
# we initialize the route handler with a global store with default account and region, because it only ever
# access values with CrossAccount attributes
if not router:
store = apigateway_stores[DEFAULT_AWS_ACCOUNT_ID][AWS_REGION_US_EAST_1]
route_handler = ApiGatewayEndpoint(store=store)
route_handler = ApiGatewayEndpoint(store=apigateway_stores)
router = ApiGatewayRouter(ROUTER, handler=route_handler)

super().__init__(router=router)
Expand Down
Loading