Skip to content
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

fix: use array of exceptions instead of str for InvalidDocumentException #2416

Merged
merged 1 commit into from
Jun 14, 2022
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
2 changes: 1 addition & 1 deletion samtranslator/model/eventsources/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ def _get_permission(self, resources_to_link, stage):
editor = OpenApiEditor(resources_to_link["explicit_api"].get("DefinitionBody"))
except InvalidDocumentException as e:
api_logical_id = self.ApiId.get("Ref") if isinstance(self.ApiId, dict) else self.ApiId
raise InvalidResourceException(api_logical_id, e)
raise InvalidResourceException(api_logical_id, " ".join(ex.message for ex in e.causes))

# If this is using the new $default path, keep path blank and add a * permission
if path == OpenApiEditor._DEFAULT_PATH:
Expand Down
7 changes: 5 additions & 2 deletions samtranslator/open_api/open_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ def __init__(self, doc):
"""
if not OpenApiEditor.is_valid(doc):
raise InvalidDocumentException(
"Invalid OpenApi document. "
"Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'."
[
InvalidTemplateException(
"Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'."
)
]
)

self._doc = copy.deepcopy(doc)
Expand Down
24 changes: 18 additions & 6 deletions samtranslator/swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, doc):
"""

if not SwaggerEditor.is_valid(doc):
raise InvalidDocumentException("Invalid Swagger document")
raise InvalidDocumentException([InvalidTemplateException("Invalid Swagger document")])

self._doc = copy.deepcopy(doc)
self.paths = self._doc["paths"]
Expand Down Expand Up @@ -187,7 +187,11 @@ def add_lambda_integration(
method = self._normalize_method_name(method)
if self.has_integration(path, method):
raise InvalidDocumentException(
"Lambda integration already exists on Path={}, Method={}".format(path, method)
[
InvalidTemplateException(
"Lambda integration already exists on Path={}, Method={}".format(path, method)
)
]
)

self.add_path(path, method)
Expand Down Expand Up @@ -252,7 +256,9 @@ def add_state_machine_integration(

method = self._normalize_method_name(method)
if self.has_integration(path, method):
raise InvalidDocumentException("Integration already exists on Path={}, Method={}".format(path, method))
raise InvalidDocumentException(
[InvalidTemplateException("Integration already exists on Path={}, Method={}".format(path, method))]
)

self.add_path(path, method)

Expand Down Expand Up @@ -1029,7 +1035,9 @@ def _add_iam_resource_policy_for_method(self, policy_list, effect, resource_list
return

if effect not in ["Allow", "Deny"]:
raise InvalidDocumentException("Effect must be one of {}".format(["Allow", "Deny"]))
raise InvalidDocumentException(
[InvalidTemplateException("Effect must be one of {}".format(["Allow", "Deny"]))]
)

if not isinstance(policy_list, (dict, list)):
raise InvalidDocumentException(
Expand Down Expand Up @@ -1091,7 +1099,9 @@ def _add_ip_resource_policy_for_method(self, ip_list, conditional, resource_list
ip_list = [ip_list]

if conditional not in ["IpAddress", "NotIpAddress"]:
raise InvalidDocumentException("Conditional must be one of {}".format(["IpAddress", "NotIpAddress"]))
raise InvalidDocumentException(
[InvalidTemplateException("Conditional must be one of {}".format(["IpAddress", "NotIpAddress"]))]
)

self.resource_policy["Version"] = "2012-10-17"
allow_statement = Py27Dict()
Expand Down Expand Up @@ -1127,7 +1137,9 @@ def _add_vpc_resource_policy_for_method(self, endpoint_dict, conditional, resour
"""

if conditional not in ["StringNotEquals", "StringEquals"]:
raise InvalidDocumentException("Conditional must be one of {}".format(["StringNotEquals", "StringEquals"]))
raise InvalidDocumentException(
[InvalidTemplateException("Conditional must be one of {}".format(["StringNotEquals", "StringEquals"]))]
)

condition = Py27Dict()
string_endpoint_list = endpoint_dict.get("StringEndpointList")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"errorMessage": "Resource with id [Api] is invalid. Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'."
}
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Api] is invalid. Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'."
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Api] is invalid. Structure of the SAM template is invalid. Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'."
}