2014-12-31 19:21:47 +00:00
|
|
|
from werkzeug.exceptions import BadRequest
|
2014-10-23 18:39:15 +00:00
|
|
|
from jinja2 import Template
|
|
|
|
|
2014-10-21 18:51:26 +00:00
|
|
|
|
|
|
|
class UnformattedGetAttTemplateException(Exception):
|
2019-10-31 15:44:26 +00:00
|
|
|
description = (
|
|
|
|
"Template error: resource {0} does not support attribute type {1} in Fn::GetAtt"
|
|
|
|
)
|
2014-10-21 18:51:26 +00:00
|
|
|
status_code = 400
|
2014-10-23 18:39:15 +00:00
|
|
|
|
|
|
|
|
2014-12-31 19:21:47 +00:00
|
|
|
class ValidationError(BadRequest):
|
2021-10-18 09:13:27 +00:00
|
|
|
def __init__(self, name_or_id=None, message=None):
|
2016-04-11 21:52:03 +00:00
|
|
|
if message is None:
|
2017-02-24 02:37:43 +00:00
|
|
|
message = "Stack with id {0} does not exist".format(name_or_id)
|
2016-04-11 21:52:03 +00:00
|
|
|
|
2014-12-31 19:21:47 +00:00
|
|
|
template = Template(ERROR_RESPONSE)
|
|
|
|
super(ValidationError, self).__init__()
|
2019-10-31 15:44:26 +00:00
|
|
|
self.description = template.render(code="ValidationError", message=message)
|
2014-10-23 18:39:15 +00:00
|
|
|
|
2014-12-31 19:21:47 +00:00
|
|
|
|
|
|
|
class MissingParameterError(BadRequest):
|
|
|
|
def __init__(self, parameter_name):
|
|
|
|
template = Template(ERROR_RESPONSE)
|
|
|
|
super(MissingParameterError, self).__init__()
|
|
|
|
self.description = template.render(
|
|
|
|
code="Missing Parameter",
|
2016-04-28 13:21:54 +00:00
|
|
|
message="Missing parameter {0}".format(parameter_name),
|
2014-12-31 19:21:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-05-30 18:59:25 +00:00
|
|
|
class ExportNotFound(BadRequest):
|
|
|
|
"""Exception to raise if a template tries to import a non-existent export"""
|
|
|
|
|
|
|
|
def __init__(self, export_name):
|
|
|
|
template = Template(ERROR_RESPONSE)
|
|
|
|
super(ExportNotFound, self).__init__()
|
|
|
|
self.description = template.render(
|
2019-10-31 15:44:26 +00:00
|
|
|
code="ExportNotFound",
|
|
|
|
message="No export named {0} found.".format(export_name),
|
2018-05-30 18:59:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2014-12-31 19:21:47 +00:00
|
|
|
ERROR_RESPONSE = """<ErrorResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/">
|
2014-10-23 18:39:15 +00:00
|
|
|
<Error>
|
|
|
|
<Type>Sender</Type>
|
2014-12-31 19:21:47 +00:00
|
|
|
<Code>{{ code }}</Code>
|
|
|
|
<Message>{{ message }}</Message>
|
2014-10-23 18:39:15 +00:00
|
|
|
</Error>
|
|
|
|
<RequestId>cf4c737e-5ae2-11e4-a7c9-ad44eEXAMPLE</RequestId>
|
|
|
|
</ErrorResponse>
|
|
|
|
"""
|