Skip to content

Commit

Permalink
APIGatewayV2: Refactor request handling (#7630)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Apr 25, 2024
1 parent 23a7dc5 commit b8d55d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 278 deletions.
208 changes: 0 additions & 208 deletions moto/apigatewayv2/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,148 +21,6 @@ def apigatewayv2_backend(self) -> ApiGatewayV2Backend:
"""Return backend instance specific for this region."""
return apigatewayv2_backends[self.current_account][self.region]

def apis(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "POST":
return self.create_api()
if self.method == "GET":
return self.get_apis()

def api(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "GET":
return self.get_api()
if self.method == "PATCH":
return self.update_api()
if self.method == "PUT":
return self.reimport_api()
if self.method == "DELETE":
return self.delete_api()

def authorizer(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "DELETE":
return self.delete_authorizer()
if self.method == "GET":
return self.get_authorizer()
if self.method == "PATCH":
return self.update_authorizer()

def authorizers(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "POST":
return self.create_authorizer()

def cors(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "DELETE":
return self.delete_cors_configuration()

def route_request_parameter( # type: ignore[return]
self, request: Any, full_url: str, headers: Any
) -> TYPE_RESPONSE:
self.setup_class(request, full_url, headers)

if self.method == "DELETE":
return self.delete_route_request_parameter()

def model(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "DELETE":
return self.delete_model()
if self.method == "GET":
return self.get_model()
if self.method == "PATCH":
return self.update_model()

def models(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "POST":
return self.create_model()

def integration(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "DELETE":
return self.delete_integration()
if self.method == "GET":
return self.get_integration()
if self.method == "PATCH":
return self.update_integration()

def integrations(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "GET":
return self.get_integrations()
if self.method == "POST":
return self.create_integration()

def integration_response( # type: ignore[return]
self, request: Any, full_url: str, headers: Any
) -> TYPE_RESPONSE:
self.setup_class(request, full_url, headers)

if self.method == "DELETE":
return self.delete_integration_response()
if self.method == "GET":
return self.get_integration_response()
if self.method == "PATCH":
return self.update_integration_response()

def integration_responses( # type: ignore[return]
self, request: Any, full_url: str, headers: Any
) -> TYPE_RESPONSE:
self.setup_class(request, full_url, headers)

if self.method == "GET":
return self.get_integration_responses()
if self.method == "POST":
return self.create_integration_response()

def route(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "DELETE":
return self.delete_route()
if self.method == "GET":
return self.get_route()
if self.method == "PATCH":
return self.update_route()

def routes(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "GET":
return self.get_routes()
if self.method == "POST":
return self.create_route()

def route_response( # type: ignore[return]
self, request: Any, full_url: str, headers: Any
) -> TYPE_RESPONSE:
self.setup_class(request, full_url, headers)

if self.method == "DELETE":
return self.delete_route_response()
if self.method == "GET":
return self.get_route_response()

def route_responses( # type: ignore[return]
self, request: Any, full_url: str, headers: Any
) -> TYPE_RESPONSE:
self.setup_class(request, full_url, headers)

if self.method == "POST":
return self.create_route_response()

def tags(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

Expand All @@ -173,72 +31,6 @@ def tags(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # t
if self.method == "DELETE":
return self.untag_resource()

def vpc_link(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if request.method == "DELETE":
return self.delete_vpc_link()
if request.method == "GET":
return self.get_vpc_link()
if request.method == "PATCH":
return self.update_vpc_link()

def vpc_links(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if request.method == "GET":
return self.get_vpc_links()
if request.method == "POST":
return self.create_vpc_link()

def domain_names(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if request.method == "GET":
return self.get_domain_names()
if request.method == "POST":
return self.create_domain_name()

def domain_name(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if request.method == "GET":
return self.get_domain_name()
if request.method == "DELETE":
return self.delete_domain_name()

def api_mappings(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if request.method == "GET":
return self.get_api_mappings()
if request.method == "POST":
return self.create_api_mapping()

def api_mapping(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if request.method == "GET":
return self.get_api_mapping()
if request.method == "DELETE":
return self.delete_api_mapping()

def stages(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "POST":
return self.create_stage()
if self.method == "GET":
return self.get_stages()

def stage(self, request: Any, full_url: str, headers: Any) -> TYPE_RESPONSE: # type: ignore[return]
self.setup_class(request, full_url, headers)

if self.method == "GET":
return self.get_stage()
if self.method == "DELETE":
return self.delete_stage()

def create_api(self) -> TYPE_RESPONSE:
params = json.loads(self.body)

Expand Down
94 changes: 24 additions & 70 deletions moto/apigatewayv2/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,24 @@


url_paths = {
"{0}/v2/apis$": ApiGatewayV2Response.method_dispatch(ApiGatewayV2Response.apis),
"{0}/v2/apis/(?P<api_id>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.api
),
"{0}/v2/apis/(?P<api_id>[^/]+)/authorizers$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.authorizers
),
"{0}/v2/apis/(?P<api_id>[^/]+)/authorizers/(?P<authorizer_id>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.authorizer
),
"{0}/v2/apis/(?P<api_id>[^/]+)/cors$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.cors
),
"{0}/v2/apis/(?P<api_id>[^/]+)/integrations$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.integrations
),
"{0}/v2/apis/(?P<api_id>[^/]+)/integrations/(?P<integration_id>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.integration
),
"{0}/v2/apis/(?P<api_id>[^/]+)/integrations/(?P<integration_id>[^/]+)/integrationresponses$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.integration_responses
),
"{0}/v2/apis/(?P<api_id>[^/]+)/integrations/(?P<integration_id>[^/]+)/integrationresponses/(?P<integration_response_id>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.integration_response
),
"{0}/v2/apis/(?P<api_id>[^/]+)/models$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.models
),
"{0}/v2/apis/(?P<api_id>[^/]+)/models/(?P<model_id>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.model
),
"{0}/v2/apis/(?P<api_id>[^/]+)/routes$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.routes
),
"{0}/v2/apis/(?P<api_id>[^/]+)/routes/(?P<route_id>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.route
),
"{0}/v2/apis/(?P<api_id>[^/]+)/routes/(?P<route_id>[^/]+)/routeresponses$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.route_responses
),
"{0}/v2/apis/(?P<api_id>[^/]+)/routes/(?P<route_id>[^/]+)/routeresponses/(?P<route_response_id>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.route_response
),
"{0}/v2/apis/(?P<api_id>[^/]+)/routes/(?P<route_id>[^/]+)/requestparameters/(?P<request_parameter>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.route_request_parameter
),
"{0}/v2/apis/(?P<api_id>[^/]+)/stages$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.stages
),
"{0}/v2/apis/(?P<api_id>[^/]+)/stages/(?P<stage_name>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.stage
),
"{0}/v2/apis$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/authorizers$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/authorizers/(?P<authorizer_id>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/cors$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/integrations$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/integrations/(?P<integration_id>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/integrations/(?P<integration_id>[^/]+)/integrationresponses$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/integrations/(?P<integration_id>[^/]+)/integrationresponses/(?P<integration_response_id>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/models$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/models/(?P<model_id>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/routes$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/routes/(?P<route_id>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/routes/(?P<route_id>[^/]+)/routeresponses$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/routes/(?P<route_id>[^/]+)/routeresponses/(?P<route_response_id>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/routes/(?P<route_id>[^/]+)/requestparameters/(?P<request_parameter>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/stages$": ApiGatewayV2Response.dispatch,
"{0}/v2/apis/(?P<api_id>[^/]+)/stages/(?P<stage_name>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/tags/(?P<resource_arn>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.tags
),
Expand All @@ -69,22 +35,10 @@
"{0}/v2/tags/(?P<resource_arn_pt1>[^/]+)/vpclinks/(?P<resource_arn_pt2>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.tags
),
"{0}/v2/vpclinks$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.vpc_links
),
"{0}/v2/vpclinks/(?P<vpc_link_id>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.vpc_link
),
"{0}/v2/domainnames$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.domain_names
),
"{0}/v2/domainnames/(?P<domain_name>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.domain_name
),
"{0}/v2/domainnames/(?P<domain_name>[^/]+)/apimappings$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.api_mappings
),
"{0}/v2/domainnames/(?P<domain_name>[^/]+)/apimappings/(?P<api_mapping_id>[^/]+)$": ApiGatewayV2Response.method_dispatch(
ApiGatewayV2Response.api_mapping
),
"{0}/v2/vpclinks$": ApiGatewayV2Response.dispatch,
"{0}/v2/vpclinks/(?P<vpc_link_id>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/domainnames$": ApiGatewayV2Response.dispatch,
"{0}/v2/domainnames/(?P<domain_name>[^/]+)$": ApiGatewayV2Response.dispatch,
"{0}/v2/domainnames/(?P<domain_name>[^/]+)/apimappings$": ApiGatewayV2Response.dispatch,
"{0}/v2/domainnames/(?P<domain_name>[^/]+)/apimappings/(?P<api_mapping_id>[^/]+)$": ApiGatewayV2Response.dispatch,
}

0 comments on commit b8d55d6

Please sign in to comment.