From 78da6639d8cdd698729ef14c2e86e2472f9137d9 Mon Sep 17 00:00:00 2001 From: Shreya Gangishetty Date: Thu, 20 Feb 2020 12:59:28 -0800 Subject: [PATCH] fix: make usageplan properties referable --- samtranslator/model/sam_resources.py | 12 +++++++++++- .../translator/input/api_with_usageplans.yaml | 12 ++++++++++++ .../translator/output/api_with_usageplans.json | 18 ++++++++++++++++++ .../output/aws-cn/api_with_usageplans.json | 18 ++++++++++++++++++ .../output/aws-us-gov/api_with_usageplans.json | 18 ++++++++++++++++++ 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 8683dba3d9..83715de890 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -10,7 +10,14 @@ from .s3_utils.uri_parser import construct_s3_location_object from .tags.resource_tagging import get_tag_list from samtranslator.model import PropertyType, SamResourceMacro, ResourceTypeResolver -from samtranslator.model.apigateway import ApiGatewayDeployment, ApiGatewayStage, ApiGatewayDomainName +from samtranslator.model.apigateway import ( + ApiGatewayDeployment, + ApiGatewayStage, + ApiGatewayDomainName, + ApiGatewayUsagePlan, + ApiGatewayUsagePlanKey, + ApiGatewayApiKey, +) from samtranslator.model.apigatewayv2 import ApiGatewayV2Stage from samtranslator.model.cloudformation import NestedStack from samtranslator.model.dynamodb import DynamoDBTable @@ -764,6 +771,9 @@ class SamApi(SamResourceMacro): "Stage": ApiGatewayStage.resource_type, "Deployment": ApiGatewayDeployment.resource_type, "DomainName": ApiGatewayDomainName.resource_type, + "UsagePlan": ApiGatewayUsagePlan.resource_type, + "UsagePlanKey": ApiGatewayUsagePlanKey.resource_type, + "ApiKey": ApiGatewayApiKey.resource_type, } def to_cloudformation(self, **kwargs): diff --git a/tests/translator/input/api_with_usageplans.yaml b/tests/translator/input/api_with_usageplans.yaml index 36aa0ba0a5..836d98648b 100644 --- a/tests/translator/input/api_with_usageplans.yaml +++ b/tests/translator/input/api_with_usageplans.yaml @@ -126,3 +126,15 @@ Outputs: Description: "API endpoint URL for Prod environment" Value: Fn::Sub: 'https://${MyApiThree}.execute-api.${AWS::Region}.amazonaws.com/Prod/' + UsagePlan: + Description: "Usage Plan physical Id" + Value: + !Ref MyApiTwo.UsagePlan + UsagePlanKey: + Description: "Usage Plan Key" + Value: + !Ref MyApiTwo.UsagePlanKey + ApiKey: + Description: "Api Key" + Value: + !Ref MyApiThree.ApiKey \ No newline at end of file diff --git a/tests/translator/output/api_with_usageplans.json b/tests/translator/output/api_with_usageplans.json index 6e11a953af..4885484657 100644 --- a/tests/translator/output/api_with_usageplans.json +++ b/tests/translator/output/api_with_usageplans.json @@ -17,6 +17,24 @@ "Value": { "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" } + }, + "ApiKey": { + "Description": "Api Key", + "Value": { + "Ref": "ServerlessApiKey" + } + }, + "UsagePlanKey": { + "Description": "Usage Plan Key", + "Value": { + "Ref": "MyApiTwoUsagePlanKey" + } + }, + "UsagePlan": { + "Description": "Usage Plan physical Id", + "Value": { + "Ref": "MyApiTwoUsagePlan" + } } }, "Resources": { diff --git a/tests/translator/output/aws-cn/api_with_usageplans.json b/tests/translator/output/aws-cn/api_with_usageplans.json index 3f38b0ce5e..23c0dd22df 100644 --- a/tests/translator/output/aws-cn/api_with_usageplans.json +++ b/tests/translator/output/aws-cn/api_with_usageplans.json @@ -17,6 +17,24 @@ "Value": { "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" } + }, + "ApiKey": { + "Description": "Api Key", + "Value": { + "Ref": "ServerlessApiKey" + } + }, + "UsagePlanKey": { + "Description": "Usage Plan Key", + "Value": { + "Ref": "MyApiTwoUsagePlanKey" + } + }, + "UsagePlan": { + "Description": "Usage Plan physical Id", + "Value": { + "Ref": "MyApiTwoUsagePlan" + } } }, "Resources": { diff --git a/tests/translator/output/aws-us-gov/api_with_usageplans.json b/tests/translator/output/aws-us-gov/api_with_usageplans.json index 7c0d0eaad3..55b2a87137 100644 --- a/tests/translator/output/aws-us-gov/api_with_usageplans.json +++ b/tests/translator/output/aws-us-gov/api_with_usageplans.json @@ -17,6 +17,24 @@ "Value": { "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" } + }, + "ApiKey": { + "Description": "Api Key", + "Value": { + "Ref": "ServerlessApiKey" + } + }, + "UsagePlanKey": { + "Description": "Usage Plan Key", + "Value": { + "Ref": "MyApiTwoUsagePlanKey" + } + }, + "UsagePlan": { + "Description": "Usage Plan physical Id", + "Value": { + "Ref": "MyApiTwoUsagePlan" + } } }, "Resources": {