From cc6365cdeb9180339e24d20d8f0433771b66650f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Morosi?= Date: Fri, 12 Jan 2024 09:54:23 +0100 Subject: [PATCH] Fix InvokeFunction permission for ANY method Apigateway v1 doesn't work with ANY in the ARN of the InvokeFunction permission. It has to be replaced with * --- src/e3/aws/troposphere/apigateway/__init__.py | 2 +- .../troposphere/apigateway/apigateway_test.py | 2 +- .../troposphere/apigateway/apigatewayv1_test.json | 2 +- .../apigatewayv1_test_custom_domain.json | 2 +- .../apigatewayv1_test_custom_domain_stages.json | 4 ++-- .../apigateway/apigatewayv1_test_lambda_alias.json | 4 ++-- .../apigatewayv1_test_nested_resources.json | 14 +++++++------- .../apigateway/apigatewayv1_test_stages.json | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/e3/aws/troposphere/apigateway/__init__.py b/src/e3/aws/troposphere/apigateway/__init__.py index 1bb77db..c5c230f 100644 --- a/src/e3/aws/troposphere/apigateway/__init__.py +++ b/src/e3/aws/troposphere/apigateway/__init__.py @@ -963,7 +963,7 @@ def _declare_method( f"${{api}}/{config.name}/${{method}}/{resource_path}", dict_values={ "api": self.ref, - "method": method.method, + "method": "*" if method.method == "ANY" else method.method, }, ), ) diff --git a/tests/tests_e3_aws/troposphere/apigateway/apigateway_test.py b/tests/tests_e3_aws/troposphere/apigateway/apigateway_test.py index 5a94dbe..f3c5825 100644 --- a/tests/tests_e3_aws/troposphere/apigateway/apigateway_test.py +++ b/tests/tests_e3_aws/troposphere/apigateway/apigateway_test.py @@ -736,7 +736,7 @@ def test_rest_api_nested_resources(stack: Stack, lambda_fun: PyFunction) -> None # Specific lambda for this resource lambda_arn=products_lambda.ref, method_list=[Method("ANY")], - resource_list=[Resource(path="abcd", method_list=[Method("ANY")])], + resource_list=[Resource(path="abcd", method_list=[Method("GET")])], ), ], ) diff --git a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test.json b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test.json index 16abfb8..a2a5e65 100644 --- a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test.json +++ b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test.json @@ -130,7 +130,7 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "*" } ] } diff --git a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_custom_domain.json b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_custom_domain.json index 4a4c7a2..7b6c1ef 100644 --- a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_custom_domain.json +++ b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_custom_domain.json @@ -159,7 +159,7 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "*" } ] } diff --git a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_custom_domain_stages.json b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_custom_domain_stages.json index a09c883..69a0fa9 100644 --- a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_custom_domain_stages.json +++ b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_custom_domain_stages.json @@ -205,7 +205,7 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "*" } ] } @@ -226,7 +226,7 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "*" } ] } diff --git a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_lambda_alias.json b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_lambda_alias.json index ac18d39..ea8a144 100644 --- a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_lambda_alias.json +++ b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_lambda_alias.json @@ -170,7 +170,7 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "*" } ] } @@ -191,7 +191,7 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "*" } ] } diff --git a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_nested_resources.json b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_nested_resources.json index 99b437d..14e3ccb 100644 --- a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_nested_resources.json +++ b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_nested_resources.json @@ -84,7 +84,7 @@ "DependsOn": [ "TestapiAccountsANYMethod", "TestapiProductsANYMethod", - "TestapiProductsAbcdANYMethod" + "TestapiProductsAbcdGETMethod" ] }, "TestapiDefaultStage": { @@ -178,13 +178,13 @@ }, "Type": "AWS::ApiGateway::Method" }, - "TestapiProductsAbcdANYMethod": { + "TestapiProductsAbcdGETMethod": { "Properties": { "RestApiId": { "Ref": "Testapi" }, "AuthorizationType": "NONE", - "HttpMethod": "ANY", + "HttpMethod": "GET", "Integration": { "CacheKeyParameters": [], "CacheNamespace": "none", @@ -222,7 +222,7 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "*" } ] } @@ -243,14 +243,14 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "*" } ] } }, "Type": "AWS::Lambda::Permission" }, - "TestapiProductsAbcdANYDefaultLambdaPermission": { + "TestapiProductsAbcdGETDefaultLambdaPermission": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -264,7 +264,7 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "GET" } ] } diff --git a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_stages.json b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_stages.json index 1335b15..7a1ff56 100644 --- a/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_stages.json +++ b/tests/tests_e3_aws/troposphere/apigateway/apigatewayv1_test_stages.json @@ -176,7 +176,7 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "*" } ] } @@ -197,7 +197,7 @@ "api": { "Ref": "Testapi" }, - "method": "ANY" + "method": "*" } ] }