From b8d55d6f7170b35265d8f4f210a45d67e61b4f34 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Thu, 25 Apr 2024 18:42:19 +0000 Subject: [PATCH] APIGatewayV2: Refactor request handling (#7630) --- moto/apigatewayv2/responses.py | 208 --------------------------------- moto/apigatewayv2/urls.py | 94 ++++----------- 2 files changed, 24 insertions(+), 278 deletions(-) diff --git a/moto/apigatewayv2/responses.py b/moto/apigatewayv2/responses.py index d10ae7d102bf..a03833405a95 100644 --- a/moto/apigatewayv2/responses.py +++ b/moto/apigatewayv2/responses.py @@ -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) @@ -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) diff --git a/moto/apigatewayv2/urls.py b/moto/apigatewayv2/urls.py index 63bc79fb6ccd..bbe9146225ca 100644 --- a/moto/apigatewayv2/urls.py +++ b/moto/apigatewayv2/urls.py @@ -8,58 +8,24 @@ url_paths = { - "{0}/v2/apis$": ApiGatewayV2Response.method_dispatch(ApiGatewayV2Response.apis), - "{0}/v2/apis/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.api - ), - "{0}/v2/apis/(?P[^/]+)/authorizers$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.authorizers - ), - "{0}/v2/apis/(?P[^/]+)/authorizers/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.authorizer - ), - "{0}/v2/apis/(?P[^/]+)/cors$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.cors - ), - "{0}/v2/apis/(?P[^/]+)/integrations$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.integrations - ), - "{0}/v2/apis/(?P[^/]+)/integrations/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.integration - ), - "{0}/v2/apis/(?P[^/]+)/integrations/(?P[^/]+)/integrationresponses$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.integration_responses - ), - "{0}/v2/apis/(?P[^/]+)/integrations/(?P[^/]+)/integrationresponses/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.integration_response - ), - "{0}/v2/apis/(?P[^/]+)/models$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.models - ), - "{0}/v2/apis/(?P[^/]+)/models/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.model - ), - "{0}/v2/apis/(?P[^/]+)/routes$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.routes - ), - "{0}/v2/apis/(?P[^/]+)/routes/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.route - ), - "{0}/v2/apis/(?P[^/]+)/routes/(?P[^/]+)/routeresponses$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.route_responses - ), - "{0}/v2/apis/(?P[^/]+)/routes/(?P[^/]+)/routeresponses/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.route_response - ), - "{0}/v2/apis/(?P[^/]+)/routes/(?P[^/]+)/requestparameters/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.route_request_parameter - ), - "{0}/v2/apis/(?P[^/]+)/stages$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.stages - ), - "{0}/v2/apis/(?P[^/]+)/stages/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.stage - ), + "{0}/v2/apis$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/authorizers$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/authorizers/(?P[^/]+)$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/cors$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/integrations$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/integrations/(?P[^/]+)$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/integrations/(?P[^/]+)/integrationresponses$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/integrations/(?P[^/]+)/integrationresponses/(?P[^/]+)$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/models$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/models/(?P[^/]+)$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/routes$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/routes/(?P[^/]+)$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/routes/(?P[^/]+)/routeresponses$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/routes/(?P[^/]+)/routeresponses/(?P[^/]+)$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/routes/(?P[^/]+)/requestparameters/(?P[^/]+)$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/stages$": ApiGatewayV2Response.dispatch, + "{0}/v2/apis/(?P[^/]+)/stages/(?P[^/]+)$": ApiGatewayV2Response.dispatch, "{0}/v2/tags/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( ApiGatewayV2Response.tags ), @@ -69,22 +35,10 @@ "{0}/v2/tags/(?P[^/]+)/vpclinks/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( ApiGatewayV2Response.tags ), - "{0}/v2/vpclinks$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.vpc_links - ), - "{0}/v2/vpclinks/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.vpc_link - ), - "{0}/v2/domainnames$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.domain_names - ), - "{0}/v2/domainnames/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.domain_name - ), - "{0}/v2/domainnames/(?P[^/]+)/apimappings$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.api_mappings - ), - "{0}/v2/domainnames/(?P[^/]+)/apimappings/(?P[^/]+)$": ApiGatewayV2Response.method_dispatch( - ApiGatewayV2Response.api_mapping - ), + "{0}/v2/vpclinks$": ApiGatewayV2Response.dispatch, + "{0}/v2/vpclinks/(?P[^/]+)$": ApiGatewayV2Response.dispatch, + "{0}/v2/domainnames$": ApiGatewayV2Response.dispatch, + "{0}/v2/domainnames/(?P[^/]+)$": ApiGatewayV2Response.dispatch, + "{0}/v2/domainnames/(?P[^/]+)/apimappings$": ApiGatewayV2Response.dispatch, + "{0}/v2/domainnames/(?P[^/]+)/apimappings/(?P[^/]+)$": ApiGatewayV2Response.dispatch, }