Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ def _construct_rest_api(self):

if self.definition_uri and self.definition_body:
raise InvalidResourceException(
self.logical_id, "Specify either 'DefinitionUri' or 'DefinitionBody' property and not both"
self.logical_id, "Specify either 'DefinitionUri' or 'DefinitionBody' property and not both."
)

if self.open_api_version:
if not SwaggerEditor.safe_compare_regex_with_string(
SwaggerEditor.get_openapi_versions_supported_regex(), self.open_api_version
):
raise InvalidResourceException(
self.logical_id, 'The OpenApiVersion value must be of the format "3.0.0"'
self.logical_id, "The OpenApiVersion value must be of the format '3.0.0'."
)

self._add_cors()
Expand Down Expand Up @@ -193,7 +193,7 @@ def _construct_body_s3_dict(self):
if not self.definition_uri.get("Bucket", None) or not self.definition_uri.get("Key", None):
# DefinitionUri is a dictionary but does not contain Bucket or Key property
raise InvalidResourceException(
self.logical_id, "'DefinitionUri' requires Bucket and Key properties to be specified"
self.logical_id, "'DefinitionUri' requires Bucket and Key properties to be specified."
)
s3_pointer = self.definition_uri

Expand All @@ -205,7 +205,7 @@ def _construct_body_s3_dict(self):
raise InvalidResourceException(
self.logical_id,
"'DefinitionUri' is not a valid S3 Uri of the form "
'"s3://bucket/key" with optional versionId query parameter.',
"'s3://bucket/key' with optional versionId query parameter.",
)

body_s3 = {"Bucket": s3_pointer["Bucket"], "Key": s3_pointer["Key"]}
Expand Down Expand Up @@ -276,7 +276,7 @@ def _construct_api_domain(self, rest_api):

if self.domain.get("DomainName") is None or self.domain.get("CertificateArn") is None:
raise InvalidResourceException(
self.logical_id, "Custom Domains only works if both DomainName and CertificateArn" " are provided"
self.logical_id, "Custom Domains only works if both DomainName and CertificateArn" " are provided."
)

self.domain["ApiDomainName"] = "{}{}".format(
Expand All @@ -293,7 +293,7 @@ def _construct_api_domain(self, rest_api):
elif endpoint not in ["EDGE", "REGIONAL"]:
raise InvalidResourceException(
self.logical_id,
"EndpointConfiguration for Custom Domains must be" " one of {}".format(["EDGE", "REGIONAL"]),
"EndpointConfiguration for Custom Domains must be" " one of {}.".format(["EDGE", "REGIONAL"]),
)

if endpoint == "REGIONAL":
Expand Down Expand Up @@ -427,7 +427,7 @@ def _add_cors(self):

if self.cors and not self.definition_body:
raise InvalidResourceException(
self.logical_id, "Cors works only with inline Swagger specified in " "'DefinitionBody' property"
self.logical_id, "Cors works only with inline Swagger specified in 'DefinitionBody' property."
)

if isinstance(self.cors, string_types) or is_instrinsic(self.cors):
Expand All @@ -447,7 +447,8 @@ def _add_cors(self):
if not SwaggerEditor.is_valid(self.definition_body):
raise InvalidResourceException(
self.logical_id,
"Unable to add Cors configuration because " "'DefinitionBody' does not contain a valid Swagger",
"Unable to add Cors configuration because "
"'DefinitionBody' does not contain a valid Swagger definition.",
)

if properties.AllowCredentials is True and properties.AllowOrigin == _CORS_WILDCARD:
Expand Down Expand Up @@ -500,7 +501,7 @@ def _add_auth(self):

if self.auth and not self.definition_body:
raise InvalidResourceException(
self.logical_id, "Auth works only with inline Swagger specified in " "'DefinitionBody' property"
self.logical_id, "Auth works only with inline Swagger specified in " "'DefinitionBody' property."
)

# Make sure keys in the dict are recognized
Expand All @@ -510,7 +511,8 @@ def _add_auth(self):
if not SwaggerEditor.is_valid(self.definition_body):
raise InvalidResourceException(
self.logical_id,
"Unable to add Auth configuration because " "'DefinitionBody' does not contain a valid Swagger",
"Unable to add Auth configuration because "
"'DefinitionBody' does not contain a valid Swagger definition.",
)
swagger_editor = SwaggerEditor(self.definition_body)
auth_properties = AuthProperties(**self.auth)
Expand Down Expand Up @@ -565,10 +567,10 @@ def _construct_usage_plan(self, rest_api_stage=None):
usage_plan_key = None

if create_usage_plan is None:
raise InvalidResourceException(self.logical_id, "'CreateUsagePlan' is a required field for UsagePlan")
raise InvalidResourceException(self.logical_id, "'CreateUsagePlan' is a required field for UsagePlan.")
if create_usage_plan not in create_usage_plans_accepted_values:
raise InvalidResourceException(
self.logical_id, "'CreateUsagePlan' accepts one of {}".format(create_usage_plans_accepted_values)
self.logical_id, "'CreateUsagePlan' accepts one of {}.".format(create_usage_plans_accepted_values)
)

if create_usage_plan == "NONE":
Expand Down Expand Up @@ -680,7 +682,7 @@ def _add_gateway_responses(self):
if self.gateway_responses and not self.definition_body:
raise InvalidResourceException(
self.logical_id,
"GatewayResponses works only with inline Swagger specified in " "'DefinitionBody' property",
"GatewayResponses works only with inline Swagger specified in " "'DefinitionBody' property.",
)

# Make sure keys in the dict are recognized
Expand All @@ -689,13 +691,16 @@ def _add_gateway_responses(self):
if response_key not in GatewayResponseProperties:
raise InvalidResourceException(
self.logical_id,
"Invalid property '{}' in 'GatewayResponses' property '{}'".format(response_key, responses_key),
"Invalid property '{}' in 'GatewayResponses' property '{}'.".format(
response_key, responses_key
),
)

if not SwaggerEditor.is_valid(self.definition_body):
raise InvalidResourceException(
self.logical_id,
"Unable to add Auth configuration because " "'DefinitionBody' does not contain a valid Swagger",
"Unable to add Auth configuration because "
"'DefinitionBody' does not contain a valid Swagger definition.",
)

swagger_editor = SwaggerEditor(self.definition_body)
Expand Down Expand Up @@ -726,13 +731,14 @@ def _add_models(self):

if self.models and not self.definition_body:
raise InvalidResourceException(
self.logical_id, "Models works only with inline Swagger specified in " "'DefinitionBody' property"
self.logical_id, "Models works only with inline Swagger specified in " "'DefinitionBody' property."
)

if not SwaggerEditor.is_valid(self.definition_body):
raise InvalidResourceException(
self.logical_id,
"Unable to add Models definitions because " "'DefinitionBody' does not contain a valid Swagger",
"Unable to add Models definitions because "
"'DefinitionBody' does not contain a valid Swagger definition.",
)

if not all(isinstance(model, dict) for model in self.models.values()):
Expand Down Expand Up @@ -815,7 +821,7 @@ def _get_authorizers(self, authorizers_config, default_authorizer=None):
return None

if not isinstance(authorizers_config, dict):
raise InvalidResourceException(self.logical_id, "Authorizers must be a dictionary")
raise InvalidResourceException(self.logical_id, "Authorizers must be a dictionary.")

for authorizer_name, authorizer in authorizers_config.items():
if not isinstance(authorizer, dict):
Expand Down Expand Up @@ -892,7 +898,9 @@ def _set_default_authorizer(
if not authorizers.get(default_authorizer) and default_authorizer != "AWS_IAM":
raise InvalidResourceException(
self.logical_id,
"Unable to set DefaultAuthorizer because '" + default_authorizer + "' was not defined in 'Authorizers'",
"Unable to set DefaultAuthorizer because '"
+ default_authorizer
+ "' was not defined in 'Authorizers'.",
)

for path in swagger_editor.iter_on_path():
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/model/api/http_api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _construct_body_s3_dict(self):
raise InvalidResourceException(
self.logical_id,
"'DefinitionUri' is not a valid S3 Uri of the form "
'"s3://bucket/key" with optional versionId query parameter.',
"'s3://bucket/key' with optional versionId query parameter.",
)

body_s3 = {"Bucket": s3_pointer["Bucket"], "Key": s3_pointer["Key"]}
Expand Down
3 changes: 2 additions & 1 deletion samtranslator/model/apigateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ def __init__(
):
if function_payload_type not in ApiGatewayAuthorizer._VALID_FUNCTION_PAYLOAD_TYPES:
raise InvalidResourceException(
api_logical_id, name + " Authorizer has invalid " "'FunctionPayloadType': " + function_payload_type
api_logical_id,
name + " Authorizer has invalid " "'FunctionPayloadType': " + function_payload_type + ".",
)

if function_payload_type == "REQUEST" and self._is_missing_identity_source(identity):
Expand Down
4 changes: 2 additions & 2 deletions samtranslator/model/s3_utils/uri_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def construct_s3_location_object(location_uri, logical_id, property_name):
if not location_uri.get("Bucket") or not location_uri.get("Key"):
# location_uri is a dictionary but does not contain Bucket or Key property
raise InvalidResourceException(
logical_id, "'{}' requires Bucket and Key properties to be " "specified".format(property_name)
logical_id, "'{}' requires Bucket and Key properties to be specified.".format(property_name)
)

s3_pointer = location_uri
Expand All @@ -72,7 +72,7 @@ def construct_s3_location_object(location_uri, logical_id, property_name):
raise InvalidResourceException(
logical_id,
"'{}' is not a valid S3 Uri of the form "
'"s3://bucket/key" with optional versionId query '
"'s3://bucket/key' with optional versionId query "
"parameter.".format(property_name),
)

Expand Down
4 changes: 2 additions & 2 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def _validate_dlq(self):
if not self.DeadLetterQueue.get("Type") or not self.DeadLetterQueue.get("TargetArn"):
raise InvalidResourceException(
self.logical_id,
"'DeadLetterQueue' requires Type and TargetArn properties to be specified".format(valid_dlq_types),
"'DeadLetterQueue' requires Type and TargetArn properties to be specified.".format(valid_dlq_types),
)

# Validate required Types
Expand Down Expand Up @@ -715,7 +715,7 @@ def _validate_deployment_preference_and_add_update_policy(
if deployment_preference_collection.get(self.logical_id).enabled:
if self.AutoPublishAlias is None:
raise InvalidResourceException(
self.logical_id, "'DeploymentPreference' requires AutoPublishAlias property to be specified"
self.logical_id, "'DeploymentPreference' requires AutoPublishAlias property to be specified."
)
if lambda_alias is None:
raise ValueError("lambda_alias expected for updating it with the appropriate update policy")
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Invalid property 'SubStatusCode' in 'GatewayResponses' property 'UNAUTHORIZED'"}
{"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Invalid property 'SubStatusCode' in 'GatewayResponses' property 'UNAUTHORIZED'."}
4 changes: 2 additions & 2 deletions tests/translator/output/error_api_invalid_auth.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 15. Resource with id [AuthNotDictApi] is invalid. Type of property 'Auth' is invalid. Resource with id [AuthWithAdditionalPropertyApi] is invalid. Invalid value for 'Auth' property Resource with id [AuthWithDefinitionUriApi] is invalid. Auth works only with inline Swagger specified in 'DefinitionBody' property Resource with id [AuthWithInvalidDefinitionBodyApi] is invalid. Unable to add Auth configuration because 'DefinitionBody' does not contain a valid Swagger Resource with id [AuthWithMissingDefaultAuthorizerApi] is invalid. Unable to set DefaultAuthorizer because 'NotThere' was not defined in 'Authorizers' Resource with id [AuthorizerNotDict] is invalid. Authorizer MyCognitoAuthorizer must be a dictionary. Resource with id [AuthorizersNotDictApi] is invalid. Authorizers must be a dictionary Resource with id [InvalidFunctionPayloadTypeApi] is invalid. MyLambdaAuthorizer Authorizer has invalid 'FunctionPayloadType': INVALID Resource with id [MissingAuthorizerFn] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer [UnspecifiedAuthorizer] on API method [get] for path [/] because it wasn't defined in the API's Authorizers. Resource with id [NoApiAuthorizerFn] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer [MyAuth] on API method [get] for path [/] because the related API does not define any Authorizers. Resource with id [NoAuthFn] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer [MyAuth] on API method [get] for path [/] because the related API does not define any Authorizers. Resource with id [NoAuthorizersFn] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer [MyAuth] on API method [get] for path [/] because the related API does not define any Authorizers. Resource with id [NoDefaultAuthorizerWithNoneFn] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer on API method [get] for path [/] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified. Resource with id [NoIdentityOnRequestAuthorizer] is invalid. MyLambdaRequestAuthorizer Authorizer must specify Identity with at least one of Headers, QueryStrings, StageVariables, or Context. Resource with id [NoIdentitySourceOnRequestAuthorizer] is invalid. MyLambdaRequestAuthorizer Authorizer must specify Identity with at least one of Headers, QueryStrings, StageVariables, or Context."
}
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 15. Resource with id [AuthNotDictApi] is invalid. Type of property 'Auth' is invalid. Resource with id [AuthWithAdditionalPropertyApi] is invalid. Invalid value for 'Auth' property Resource with id [AuthWithDefinitionUriApi] is invalid. Auth works only with inline Swagger specified in 'DefinitionBody' property. Resource with id [AuthWithInvalidDefinitionBodyApi] is invalid. Unable to add Auth configuration because 'DefinitionBody' does not contain a valid Swagger definition. Resource with id [AuthWithMissingDefaultAuthorizerApi] is invalid. Unable to set DefaultAuthorizer because 'NotThere' was not defined in 'Authorizers'. Resource with id [AuthorizerNotDict] is invalid. Authorizer MyCognitoAuthorizer must be a dictionary. Resource with id [AuthorizersNotDictApi] is invalid. Authorizers must be a dictionary. Resource with id [InvalidFunctionPayloadTypeApi] is invalid. MyLambdaAuthorizer Authorizer has invalid 'FunctionPayloadType': INVALID. Resource with id [MissingAuthorizerFn] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer [UnspecifiedAuthorizer] on API method [get] for path [/] because it wasn't defined in the API's Authorizers. Resource with id [NoApiAuthorizerFn] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer [MyAuth] on API method [get] for path [/] because the related API does not define any Authorizers. Resource with id [NoAuthFn] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer [MyAuth] on API method [get] for path [/] because the related API does not define any Authorizers. Resource with id [NoAuthorizersFn] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer [MyAuth] on API method [get] for path [/] because the related API does not define any Authorizers. Resource with id [NoDefaultAuthorizerWithNoneFn] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer on API method [get] for path [/] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified. Resource with id [NoIdentityOnRequestAuthorizer] is invalid. MyLambdaRequestAuthorizer Authorizer must specify Identity with at least one of Headers, QueryStrings, StageVariables, or Context. Resource with id [NoIdentitySourceOnRequestAuthorizer] is invalid. MyLambdaRequestAuthorizer Authorizer must specify Identity with at least one of Headers, QueryStrings, StageVariables, or Context."
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"errors": [
{
"errorMessage": "Resource with id [Api] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form \"s3://bucket/key\" with optional versionId query parameter."
"errorMessage": "Resource with id [Api] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter."
},
{
"errorMessage": "Resource with id [ApiWithBodyAndDefinitionUri] is invalid. Specify either 'DefinitionUri' or 'DefinitionBody' property and not both"
"errorMessage": "Resource with id [ApiWithBodyAndDefinitionUri] is invalid. Specify either 'DefinitionUri' or 'DefinitionBody' property and not both."
}
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [Api] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form \"s3://bucket/key\" with optional versionId query parameter. Resource with id [ApiWithBodyAndDefinitionUri] is invalid. Specify either 'DefinitionUri' or 'DefinitionBody' property and not both"
}
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [Api] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter. Resource with id [ApiWithBodyAndDefinitionUri] is invalid. Specify either 'DefinitionUri' or 'DefinitionBody' property and not both."
}
Loading