8000 APIGW: move current provider in legacy module (#11651) · localstack/localstack@9b47dc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b47dc3

Browse files
bentskumacnev2013
authored andcommitted
APIGW: move current provider in legacy module (#11651)
1 parent a060628 commit 9b47dc3

File tree

16 files changed

+769
-741
lines changed

16 files changed

+769
-741
lines changed

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

Lines changed: 6 additions & 704 deletions
Large diffs are not rendered by default.

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

Whitespace-only changes.

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

Lines changed: 711 additions & 0 deletions
Large diffs are not rendered by default.

localstack-core/localstack/services/apigateway/integration.py renamed to localstack-core/localstack/services/apigateway/legacy/integration.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121
dump_dto,
2222
)
2323
from localstack.constants import APPLICATION_JSON, HEADER_CONTENT_TYPE
24-
from localstack.services.apigateway import helpers
25-
from localstack.services.apigateway.context import ApiInvocationContext
26-
from localstack.services.apigateway.helpers import (
24+
from localstack.services.apigateway.legacy.context import ApiInvocationContext
25+
from localstack.services.apigateway.legacy.helpers import (
2726
ApiGatewayIntegrationError,
2827
IntegrationParameters,
2928
RequestParametersResolver,
3029
ResponseParametersResolver,
3130
extract_path_params,
3231
extract_query_string_params,
3332
get_event_request_context,
33+
get_stage_variables,
3434
make_error_response,
3535
multi_value_dict_for_list,
3636
)
37-
from localstack.services.apigateway.templates import (
37+
from localstack.services.apigateway.legacy.templates import (
3838
MappingTemplates,
3939
RequestTemplates,
4040
ResponseTemplates,
@@ -437,8 +437,7 @@ def invoke(self, invocation_context: ApiInvocationContext):
437437

438438
class LambdaIntegration(BackendIntegration):
439439
def invoke(self, invocation_context: ApiInvocationContext):
440-
# invocation_context.context = helpers.get_event_request_context(invocation_context)
441-
invocation_context.stage_variables = helpers.get_stage_variables(invocation_context)
440+
invocation_context.stage_variables = get_stage_variables(invocation_context)
442441
headers = invocation_context.headers
443442

444443
# resolve integration parameters
@@ -530,8 +529,8 @@ def invoke(self, invocation_context: ApiInvocationContext):
530529
# want to refactor this into a model class.
531530
# I'd argue we should not make a decision on the event_request_context inside the integration because,
532531
# it's different between API types (REST, HTTP, WebSocket) and per event version
533-
invocation_context.context = helpers.get_event_request_context(invocation_context)
534-
invocation_context.stage_variables = helpers.get_stage_variables(invocation_context)
532+
invocation_context.context = get_event_request_context(invocation_context)
533+
invocation_context.stage_variables = get_stage_variables(invocation_context)
535534

536535
# integration type "AWS" is only supported for WebSocket APIs and REST
537536
# API (v1), but the template selection expression is only supported for
@@ -787,8 +786,8 @@ def invoke(self, invo 8000 cation_context: ApiInvocationContext):
787786
uri = "http://%s/%s" % (instance["Id"], invocation_path.lstrip("/"))
788787

789788
# apply custom request template
790-
invocation_context.context = helpers.get_event_request_context(invocation_context)
791-
invocation_context.stage_variables = helpers.get_stage_variables(invocation_context)
789+
invocation_context.context = get_event_request_context(invocation_context)
790+
invocation_context.stage_variables = get_stage_variables(invocation_context)
792791
payload = self.request_templates.render(invocation_context)
793792

794793
if isinstance(payload, dict):
@@ -875,7 +874,7 @@ class SNSIntegration(BackendIntegration):
875874
def invoke(self, invocation_context: ApiInvocationContext) -> Response:
876875
# TODO: check if the logic below is accurate - cover with snapshot tests!
877876
invocation_context.context = get_event_request_context(invocation_context)
878-
invocation_context.stage_variables = helpers.get_stage_variables(invocation_context)
877+
invocation_context.stage_variables = get_stage_variables(invocation_context)
879878
integration = invocation_context.integration
880879
uri = integration.get("uri") or integration.get("integrationUri") or ""
881880

localstack-core/localstack/services/apigateway/invocations.py renamed to localstack-core/localstack/services/apigateway/legacy/invocations.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
from localstack.aws.connect import connect_to
1010
from localstack.constants import APPLICATION_JSON
11-
from localstack.services.apigateway import helpers
12-
from localstack.services.apigateway.context import ApiInvocationContext
1311
from localstack.services.apigateway.helpers import (
1412
EMPTY_MODEL,
1513
ModelResolver,
1614
get_apigateway_store_for_invocation,
15+
)
16+
from localstack.services.apigateway.legacy.context import ApiInvocationContext
17+
from localstack.services.apigateway.legacy.helpers import (
1718
get_cors_response,
19+
get_event_request_context,
20+
get_target_resource_details,
1821
make_error_response,
22+
set_api_id_stage_invocation_path,
1923
)
20-
from localstack.services.apigateway.integration import (
24+
from localstack.services.apigateway.legacy.integration import (
2125
ApiGatewayIntegrationError,
2226
DynamoDBIntegration,
2327
EventBridgeIntegration,
@@ -254,7 +258,7 @@ def update_content_length(response: Response):
254258

255259

256260
def invoke_rest_api_from_request(invocation_context: ApiInvocationContext):
257-
helpers.set_api_id_stage_invocation_path(invocation_context)
261+
set_api_id_stage_invocation_path(invocation_context)
258262
try:
259263
return invoke_rest_api(invocation_context)
260264
except AuthorizationError as e:
@@ -273,7 +277,7 @@ def invoke_rest_api(invocation_context: ApiInvocationContext):
273277
method = invocation_context.method
274278
headers = invocation_context.headers
275279

276-
extracted_path, resource = helpers.get_target_resource_details(invocation_context)
280+
extracted_path, resource = get_target_resource_details(invocation_context)
277281
if not resource:
278282
return make_error_response("Unable to find path %s" % invocation_context.path, 404)
279283

@@ -349,7 +353,7 @@ def invoke_rest_api_integration_backend(invocation_context: ApiInvocationContext
349353
if (re.match(f"{ARN_PARTITION_REGEX}:apigateway:", uri) and ":lambda:path" in uri) or re.match(
350354
f"{ARN_PARTITION_REGEX}:lambda", uri
351355
):
352-
invocation_context.context = helpers.get_event_request_context(invocation_context)
356+
invocation_context.context = get_event_request_context(invocation_context)
353357
if integration_type == "AWS_PROXY":
354358
return LambdaProxyIntegration().invoke(invocation_context)
355359
elif integration_type == "AWS":

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@
106106
is_greedy_path,
107107
is_variable_path,
108108
log_template,
109-
multi_value_dict_for_list,
110109
resolve_references,
111110
)
112-
from localstack.services.apigateway.invocations import invoke_rest_api_from_request
111+
from localstack.services.apigateway.legacy.helpers import multi_value_dict_for_list
112+
from localstack.services.apigateway.legacy.invocations import invoke_rest_api_from_request
113+
from localstack.services.apigateway.legacy.router_asf import ApigatewayRouter, to_invocation_context
113114
from localstack.services.apigateway.models import ApiGatewayStore, RestApiContainer
114115
from localstack.services.apigateway.next_gen.execute_api.router import (
115116
ApiGatewayRouter as ApiGatewayRouterNextGen,
116117
)
117118
from localstack.services.apigateway.patches import apply_patches
118-
from localstack.services.apigateway.router_asf import ApigatewayRouter, to_invocation_context
119119
from localstack.services.edge import ROUTER
120120
from localstack.services.moto import call_moto, call_moto_with_request
121121
from localstack.services.plugins import ServiceLifecycleHook

localstack-core/localstack/services/apigateway/router_asf.py renamed to localstack-core/localstack/services/apigateway/legacy/router_asf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from localstack.http import Request, Response, Router
1010
from localstack.http.dispatcher import Handler
1111
from localstack.http.request import restore_payload
12-
from localstack.services.apigateway.context import ApiInvocationContext
13-
from localstack.services.apigateway.helpers import get_api_account_id_and_region
14-
from localstack.services.apigateway.invocations import invoke_rest_api_from_request
12+
from localstack.services.apigateway.legacy.context import ApiInvocationContext
13+
from localstack.services.apigateway.legacy.helpers import get_api_account_id_and_region
14+
from localstack.services.apigateway.legacy.invocations import invoke_rest_api_from_request
1515
from localstack.utils.aws.aws_responses import LambdaResponse
1616
from localstack.utils.strings import remove_leading_extra_slashes
1717

localstack-core/localstack/services/apigateway/templates.py renamed to localstack-core/localstack/services/apigateway/legacy/templates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from localstack import config
1212
from localstack.constants import APPLICATION_JSON, APPLICATION_XML
13-
from localstack.services.apigateway.context import ApiInvocationContext
14-
from localstack.services.apigateway.helpers import select_integration_response
13+
from localstack.services.apigateway.legacy.context import ApiInvocationContext
14+
from localstack.services.apigateway.legacy.helpers import select_integration_response
1515
from localstack.utils.aws.templating import VelocityUtil, VtlTemplate
1616
from localstack.utils.json import extract_jsonpath, json_safe, try_json
1717
from localstack.utils.strings import to_str

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
Stage,
1616
StatusCode,
1717
String,
18+
TestInvokeMethodRequest,
19+
TestInvokeMethodResponse,
1820
)
1921
from localstack.constants import AWS_REGION_US_EAST_1, DEFAULT_AWS_ACCOUNT_ID
2022
from localstack.services.apigateway.helpers import (
2123
get_apigateway_store,
2224
get_moto_rest_api,
2325
get_rest_api_container,
2426
)
27+
from localstack.services.apigateway.legacy.provider import ApigatewayProvider
2528
from localstack.services.apigateway.patches import apply_patches
26-
from localstack.services.apigateway.provider import ApigatewayProvider
2729
from localstack.services.edge import ROUTER
2830
from localstack.services.moto import call_moto
2931

@@ -239,6 +241,12 @@ def get_gateway_responses(
239241
]
240242
return GatewayResponses(items=gateway_responses)
241243

244+
def test_invoke_method(
245+
self, context: RequestContext, request: TestInvokeMethodRequest
246+
) -> TestInvokeMethodResponse:
247+
# TODO: rewrite and migrate to NextGen
248+
return super().test_invoke_method(context, request)
249+
242250

243251
def _get_gateway_response_or_default(
244252
response_type: GatewayResponseType,

0 commit comments

Comments
 (0)
0