-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: additional validation and bin/sam-translate.py update #873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
c532fd8
ec54e79
26e37a1
036b663
1f2971a
7eeb01a
70b4d5b
4b0281c
7a3336a
eda4c2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import boto3 | ||
| import json | ||
| from botocore.exceptions import ClientError, EndpointConnectionError | ||
| import logging | ||
| from time import sleep, time | ||
|
|
@@ -86,10 +87,17 @@ def on_before_transform_template(self, template_dict): | |
|
|
||
| app_id = self._replace_value(app.properties[self.LOCATION_KEY], | ||
| self.APPLICATION_ID_KEY, intrinsic_resolvers) | ||
|
|
||
| semver = self._replace_value(app.properties[self.LOCATION_KEY], | ||
| self.SEMANTIC_VERSION_KEY, intrinsic_resolvers) | ||
|
|
||
| if isinstance(app_id, dict) or isinstance(semver, dict): | ||
| key = (json.dumps(app_id), json.dumps(semver)) | ||
| self._applications[key] = False | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you choose to set this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just needed a value here. Wanted to get any other recommendations from you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. We're getting a value here because we don't resolve intrinsics until later, right? Could we resolve them earlier so that the flow in this area remains the same? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can actually stick an error instead of |
||
| continue | ||
|
|
||
| key = (app_id, semver) | ||
|
|
||
| if key not in self._applications: | ||
| try: | ||
| # Lazy initialization of the client- create it when it is needed | ||
|
|
@@ -211,11 +219,23 @@ def on_before_transform_resource(self, logical_id, resource_type, resource_prope | |
| [self.APPLICATION_ID_KEY, self.SEMANTIC_VERSION_KEY]) | ||
|
|
||
| app_id = resource_properties[self.LOCATION_KEY].get(self.APPLICATION_ID_KEY) | ||
|
|
||
| if not app_id: | ||
| raise InvalidResourceException(logical_id, "Property 'ApplicationId' cannot be blank.") | ||
|
|
||
| if isinstance(app_id, dict): | ||
| raise InvalidResourceException(logical_id, "Property 'ApplicationId' cannot be resolved. Only FindInMap " | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error messages for both of these instances are practically the same, any way we could re-use the verbage and insert the property name? |
||
| "and Ref intrinsic functions are supported.") | ||
|
|
||
| semver = resource_properties[self.LOCATION_KEY].get(self.SEMANTIC_VERSION_KEY) | ||
|
|
||
| if not semver: | ||
| raise InvalidResourceException(logical_id, "Property 'SemanticVersion cannot be blank.") | ||
| raise InvalidResourceException(logical_id, "Property 'SemanticVersion' cannot be blank.") | ||
|
|
||
| if isinstance(semver, dict): | ||
| raise InvalidResourceException(logical_id, "Property 'SemanticVersion' cannot be resolved. Only FindInMap " | ||
| "and Ref intrinsic functions are supported.") | ||
|
|
||
| key = (app_id, semver) | ||
|
|
||
| # Throw any resource exceptions saved from the before_transform_template event | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Resources: | ||
| Function: | ||
| Type: AWS::Serverless::Function | ||
keetonian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Properties: | ||
keetonian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| { | ||
| "errors": [ | ||
| { | ||
| "errorMessage": "Resource with id [BlankProperties] is invalid. Property 'ApplicationId' cannot be blank. Resource with id [MissingApplicationId] is invalid. Resource is missing the required [ApplicationId] property. Resource with id [MissingLocation] is invalid. Resource is missing the required [Location] property. Resource with id [MissingSemanticVersion] is invalid. Resource is missing the required [SemanticVersion] property. Resource with id [NormalApplication] is invalid. Type of property 'ApplicationId' is invalid. Resource with id [UnsupportedProperty] is invalid. Resource is missing the required [Location] property." | ||
| "errorMessage": "Resource with id [BlankProperties] is invalid. Property 'ApplicationId' cannot be blank. Resource with id [IntrinsicProperties] is invalid. Property 'ApplicationId' cannot be resolved. Only FindInMap and Ref intrinsic functions are supported. Resource with id [MissingApplicationId] is invalid. Resource is missing the required [ApplicationId] property. Resource with id [MissingLocation] is invalid. Resource is missing the required [Location] property. Resource with id [MissingSemanticVersion] is invalid. Resource is missing the required [SemanticVersion] property. Resource with id [NormalApplication] is invalid. Type of property 'ApplicationId' is invalid. Resource with id [UnsupportedProperty] is invalid. Resource is missing the required [Location] property." | ||
| } | ||
| ], | ||
| "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 6. Resource with id [BlankProperties] is invalid. Property 'ApplicationId' cannot be blank. Resource with id [MissingApplicationId] is invalid. Resource is missing the required [ApplicationId] property. Resource with id [MissingLocation] is invalid. Resource is missing the required [Location] property. Resource with id [MissingSemanticVersion] is invalid. Resource is missing the required [SemanticVersion] property. Resource with id [NormalApplication] is invalid. Type of property 'ApplicationId' is invalid. Resource with id [UnsupportedProperty] is invalid. Resource is missing the required [Location] property." | ||
| "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 7. Resource with id [BlankProperties] is invalid. Property 'ApplicationId' cannot be blank. Resource with id [IntrinsicProperties] is invalid. Property 'ApplicationId' cannot be resolved. Only FindInMap and Ref intrinsic functions are supported. Resource with id [MissingApplicationId] is invalid. Resource is missing the required [ApplicationId] property. Resource with id [MissingLocation] is invalid. Resource is missing the required [Location] property. Resource with id [MissingSemanticVersion] is invalid. Resource is missing the required [SemanticVersion] property. Resource with id [NormalApplication] is invalid. Type of property 'ApplicationId' is invalid. Resource with id [UnsupportedProperty] is invalid. Resource is missing the required [Location] property." | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "errors": [ | ||
| { | ||
| "errorMessage": "Resource with id [Function] is invalid. All 'Resources' must be Objects and have a 'Properties' Object. If you're using YAML, this may be an indentation issue." | ||
| } | ||
| ], | ||
| "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. All 'Resources' must be Objects and have a 'Properties' Object. If you're using YAML, this may be an indentation issue." | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.