From c875e7aa0e4499af8417c3fa3d068e7b6ea8b8cb Mon Sep 17 00:00:00 2001 From: Julian Charlot Date: Wed, 22 Feb 2023 17:42:13 -0500 Subject: [PATCH] Enhancement - Add policy to update rest api for apigateway (#5951) --- moto/apigateway/models.py | 2 ++ tests/test_apigateway/test_apigateway.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py index 93fd225f6..c6d8a1680 100644 --- a/moto/apigateway/models.py +++ b/moto/apigateway/models.py @@ -1070,6 +1070,8 @@ class RestAPI(CloudFormationModel): self.binaryMediaTypes = [value] if to_path(self.PROP_DISABLE_EXECUTE_API_ENDPOINT) in path: self.disableExecuteApiEndpoint = bool(value) + if to_path(self.PROP_POLICY) in path: + self.policy = value elif operaton == self.OPERATION_ADD: if to_path(self.PROP_BINARY_MEDIA_TYPES) in path: self.binaryMediaTypes.append(value) diff --git a/tests/test_apigateway/test_apigateway.py b/tests/test_apigateway/test_apigateway.py index 60b409499..911850a90 100644 --- a/tests/test_apigateway/test_apigateway.py +++ b/tests/test_apigateway/test_apigateway.py @@ -52,6 +52,12 @@ def test_update_rest_api(): {"op": "replace", "path": "/apiKeySource", "value": "AUTHORIZER"}, {"op": "replace", "path": "/binaryMediaTypes", "value": "image/jpeg"}, {"op": "replace", "path": "/disableExecuteApiEndpoint", "value": "True"}, + { + "op": "replace", + "path": "/policy", + "value": '{"Version": "2012-10-17", "Statement": [{"Effect": "Allow", "Principal": "*", "Action": ' + '"execute-api:Invoke", "Resource": ["execute-api:/*"]}]}', + }, ] response = client.update_rest_api(restApiId=api_id, patchOperations=patchOperations) @@ -65,6 +71,8 @@ def test_update_rest_api(): "version": "V1", "description": "new-description", "apiKeySource": "AUTHORIZER", + "policy": '{"Version": "2012-10-17", "Statement": [{"Effect": "Allow", "Principal": "*", "Action": ' + '"execute-api:Invoke", "Resource": ["execute-api:/*"]}]}', "endpointConfiguration": {"types": ["EDGE"]}, "tags": {}, "disableExecuteApiEndpoint": True,