From d23b574148bd1e2420de2c07a2a6d96e236bb2dc Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Wed, 11 Mar 2020 09:34:50 -0700 Subject: [PATCH 1/2] support fail on warnings --- samtranslator/model/api/http_api_generator.py | 5 +++++ samtranslator/model/sam_resources.py | 2 ++ samtranslator/plugins/globals/globals.py | 1 + tests/translator/input/explicit_http_api.yaml | 1 + tests/translator/input/http_api_explicit_stage.yaml | 1 + tests/translator/output/aws-cn/explicit_http_api.json | 1 + tests/translator/output/aws-cn/http_api_explicit_stage.json | 1 + tests/translator/output/aws-us-gov/explicit_http_api.json | 1 + .../output/aws-us-gov/http_api_explicit_stage.json | 1 + tests/translator/output/explicit_http_api.json | 1 + tests/translator/output/http_api_explicit_stage.json | 1 + 11 files changed, 16 insertions(+) diff --git a/samtranslator/model/api/http_api_generator.py b/samtranslator/model/api/http_api_generator.py index 1943663ff0..afd9c40731 100644 --- a/samtranslator/model/api/http_api_generator.py +++ b/samtranslator/model/api/http_api_generator.py @@ -47,6 +47,7 @@ def __init__( resource_attributes=None, passthrough_resource_attributes=None, domain=None, + fail_on_warnings=False, ): """Constructs an API Generator class that generates API Gateway resources @@ -79,6 +80,7 @@ def __init__( self.resource_attributes = resource_attributes self.passthrough_resource_attributes = passthrough_resource_attributes self.domain = domain + self.fail_on_warnings = fail_on_warnings def _construct_http_api(self): """Constructs and returns the ApiGatewayV2 HttpApi. @@ -99,6 +101,9 @@ def _construct_http_api(self): self._add_auth() self._add_tags() + if self.fail_on_warnings: + http_api.FailOnWarnings = self.fail_on_warnings + if self.definition_uri: http_api.BodyS3Location = self._construct_body_s3_dict() elif self.definition_body: diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 88c16cae8c..37c5ff6640 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -878,6 +878,7 @@ class SamHttpApi(SamResourceMacro): "Auth": PropertyType(False, is_type(dict)), "RouteSettings": PropertyType(False, is_type(dict)), "Domain": PropertyType(False, is_type(dict)), + "FailOnWarnings": PropertyType(False, is_type(bool)), } referable_properties = { @@ -916,6 +917,7 @@ def to_cloudformation(self, **kwargs): resource_attributes=self.resource_attributes, passthrough_resource_attributes=self.get_passthrough_resource_attributes(), domain=self.Domain, + fail_on_warnings=self.FailOnWarnings, ) (http_api, stage, domain, basepath_mapping, route53,) = api_generator.to_cloudformation() diff --git a/samtranslator/plugins/globals/globals.py b/samtranslator/plugins/globals/globals.py index 41afb4e137..c00df46fca 100644 --- a/samtranslator/plugins/globals/globals.py +++ b/samtranslator/plugins/globals/globals.py @@ -73,6 +73,7 @@ class Globals(object): "DefaultRouteSettings", "Domain", "RouteSettings", + "FailOnWarnings", ], SamResourceType.SimpleTable.value: ["SSESpecification"], } diff --git a/tests/translator/input/explicit_http_api.yaml b/tests/translator/input/explicit_http_api.yaml index d07bc65de6..2d50630512 100644 --- a/tests/translator/input/explicit_http_api.yaml +++ b/tests/translator/input/explicit_http_api.yaml @@ -19,6 +19,7 @@ Resources: MyApi: Type: AWS::Serverless::HttpApi Properties: + FailOnWarnings: True Auth: Authorizers: OAuth2: diff --git a/tests/translator/input/http_api_explicit_stage.yaml b/tests/translator/input/http_api_explicit_stage.yaml index f24269ccc7..90b1b1932a 100644 --- a/tests/translator/input/http_api_explicit_stage.yaml +++ b/tests/translator/input/http_api_explicit_stage.yaml @@ -8,6 +8,7 @@ Globals: "$default": DataTraceEnabled: True ThrottlingBurstLimit: 100 + FailOnWarnings: true Resources: HttpApiFunction: Type: AWS::Serverless::Function diff --git a/tests/translator/output/aws-cn/explicit_http_api.json b/tests/translator/output/aws-cn/explicit_http_api.json index 2d1e8cec97..d363267629 100644 --- a/tests/translator/output/aws-cn/explicit_http_api.json +++ b/tests/translator/output/aws-cn/explicit_http_api.json @@ -196,6 +196,7 @@ "MyApi": { "Type": "AWS::ApiGatewayV2::Api", "Properties": { + "FailOnWarnings": true, "Body": { "info": { "version": "1.0", diff --git a/tests/translator/output/aws-cn/http_api_explicit_stage.json b/tests/translator/output/aws-cn/http_api_explicit_stage.json index ceae81a4f0..e42314c13b 100644 --- a/tests/translator/output/aws-cn/http_api_explicit_stage.json +++ b/tests/translator/output/aws-cn/http_api_explicit_stage.json @@ -111,6 +111,7 @@ "MyApi": { "Type": "AWS::ApiGatewayV2::Api", "Properties": { + "FailOnWarnings": true, "Body": { "info": { "version": "1.0", diff --git a/tests/translator/output/aws-us-gov/explicit_http_api.json b/tests/translator/output/aws-us-gov/explicit_http_api.json index 5c0e1761ec..5a6a2d873f 100644 --- a/tests/translator/output/aws-us-gov/explicit_http_api.json +++ b/tests/translator/output/aws-us-gov/explicit_http_api.json @@ -196,6 +196,7 @@ "MyApi": { "Type": "AWS::ApiGatewayV2::Api", "Properties": { + "FailOnWarnings": true, "Body": { "info": { "version": "1.0", diff --git a/tests/translator/output/aws-us-gov/http_api_explicit_stage.json b/tests/translator/output/aws-us-gov/http_api_explicit_stage.json index 509c33ea6a..a81cdcc15b 100644 --- a/tests/translator/output/aws-us-gov/http_api_explicit_stage.json +++ b/tests/translator/output/aws-us-gov/http_api_explicit_stage.json @@ -111,6 +111,7 @@ "MyApi": { "Type": "AWS::ApiGatewayV2::Api", "Properties": { + "FailOnWarnings": true, "Body": { "info": { "version": "1.0", diff --git a/tests/translator/output/explicit_http_api.json b/tests/translator/output/explicit_http_api.json index 3f7e4c22e8..274547f317 100644 --- a/tests/translator/output/explicit_http_api.json +++ b/tests/translator/output/explicit_http_api.json @@ -196,6 +196,7 @@ "MyApi": { "Type": "AWS::ApiGatewayV2::Api", "Properties": { + "FailOnWarnings": true, "Body": { "info": { "version": "1.0", diff --git a/tests/translator/output/http_api_explicit_stage.json b/tests/translator/output/http_api_explicit_stage.json index 715ea85898..e98ce978c8 100644 --- a/tests/translator/output/http_api_explicit_stage.json +++ b/tests/translator/output/http_api_explicit_stage.json @@ -111,6 +111,7 @@ "MyApi": { "Type": "AWS::ApiGatewayV2::Api", "Properties": { + "FailOnWarnings": true, "Body": { "info": { "version": "1.0", From 3ebcfe7379e06990a1f2fc9908f397c548a478b0 Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Wed, 11 Mar 2020 11:05:05 -0700 Subject: [PATCH 2/2] Add FailOnWarnings to docs and examples --- examples/2016-10-31/http_api_cors/template.yaml | 1 + versions/2016-10-31.md | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/2016-10-31/http_api_cors/template.yaml b/examples/2016-10-31/http_api_cors/template.yaml index 45ae74d3af..9654dfc9d7 100644 --- a/examples/2016-10-31/http_api_cors/template.yaml +++ b/examples/2016-10-31/http_api_cors/template.yaml @@ -26,6 +26,7 @@ Resources: MyApi: Type: AWS::Serverless::HttpApi Properties: + FailOnWarnings: true CorsConfiguration: AllowHeaders: - x-apigateway-header diff --git a/versions/2016-10-31.md b/versions/2016-10-31.md index afb71dd658..b6da95222c 100644 --- a/versions/2016-10-31.md +++ b/versions/2016-10-31.md @@ -286,6 +286,7 @@ DefaultRouteSettings | [RouteSettings](https://docs.aws.amazon.com/AWSCloudForma RouteSettings | [RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-stage-routesettings.html) | Per-route route settings for this HTTP API. Domain | [Domain Configuration Object](#domain-configuration-object) | Configuration settings for custom domains on API. Must contain `DomainName` and `CertificateArn` StageVariables | Map of `string` to `string` | A map that defines the stage variables for a Stage. Variable names can have alphanumeric and underscore characters, and the values must match [A-Za-z0-9-._~:/?#&=,]+. +FailOnWarnings | `boolean` | Specifies whether to rollback the API creation (true) or not (false) when a warning is encountered. The default value is false. ##### Return values