Skip to content

Commit a324a08

Browse files
cloutierMatbentsku
authored andcommitted
Updated imports
1 parent ceef8f6 commit a324a08

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

localstack-core/localstack/services/apigateway/next_gen/execute_api/handlers/api_key_validation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from localstack.http import Response
66

77
from ..api import RestApiGatewayHandler, RestApiGatewayHandlerChain
8-
from ..context import IdentityContext, InvocationRequest, RestApiInvocationContext
8+
from ..context import InvocationRequest, RestApiInvocationContext
99
from ..gateway_response import InvalidAPIKeyError
1010
from ..moto_helpers import get_api_key, get_usage_plan_keys, get_usage_plans
11+
from ..variables import ContextVarsIdentity
1112

1213
LOG = logging.getLogger(__name__)
1314

@@ -36,7 +37,7 @@ def __call__(
3637
return
3738

3839
# If the Identity context was not created yet, instantiate it and attach it to the context variables
39-
if not (identity := context.context_variables.get("identity", IdentityContext())):
40+
if not (identity := context.context_variables.get("identity", ContextVarsIdentity())):
4041
context.context_variables["identity"] = identity
4142

4243
# Look for the api key value in the request. If it is not found, raise an exception
@@ -95,7 +96,7 @@ def validate_api_key(
9596
return api_key if api_key["enabled"] else None
9697

9798
def get_request_api_key(
98-
self, rest_api: RestApi, request: InvocationRequest, identity: IdentityContext
99+
self, rest_api: RestApi, request: InvocationRequest, identity: ContextVarsIdentity
99100
) -> Optional[str]:
100101
"""https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-key-source.html
101102
The source of the API key for metering requests according to a usage plan.

tests/unit/services/apigateway/test_handler_api_key_validation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
from localstack.services.apigateway.models import MergedRestApi, RestApiDeployment
88
from localstack.services.apigateway.next_gen.execute_api.api import RestApiGatewayHandlerChain
99
from localstack.services.apigateway.next_gen.execute_api.context import (
10-
ContextVariables,
11-
IdentityContext,
1210
InvocationRequest,
1311
RestApiInvocationContext,
1412
)
1513
from localstack.services.apigateway.next_gen.execute_api.gateway_response import InvalidAPIKeyError
1614
from localstack.services.apigateway.next_gen.execute_api.handlers import ApiKeyValidationHandler
15+
from localstack.services.apigateway.next_gen.execute_api.variables import (
16+
ContextVariables,
17+
ContextVarsIdentity,
18+
)
1719
from localstack.testing.config import TEST_AWS_ACCOUNT_ID, TEST_AWS_REGION_NAME
1820

1921
TEST_API_ID = "testapi"
@@ -71,7 +73,7 @@ def _create_context(
7173

7274
# Context populated by a Lambda Authorizer
7375
if api_key is not None:
74-
context.context_variables["identity"] = IdentityContext(apiKey=api_key)
76+
context.context_variables["identity"] = ContextVarsIdentity(apiKey=api_key)
7577
return context
7678

7779
return _create_context

0 commit comments

Comments
 (0)