Remove duplicate template of SNS error response (#3647)

In e9dc5edf7f a custom error template
was added to correct the response returned by get_endpoint_attributes
for a non-existent endpoint.

However, after some more inspection, it was found that a valid
template already existed in moto/sns/responses.py.

This commit removes the template introduced in e9dc5ed and takes
into use the existing template.

It is a marginal improvement, but helps keeping a cleaner code
base

Co-authored-by: Antillon, Alejandro <alejandro.antillon@f-secure.com>
This commit is contained in:
aantillonl 2021-02-01 16:58:48 +02:00 committed by GitHub
parent c9dd9cc7f9
commit d382731a14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 28 deletions

View File

@ -1,23 +1,11 @@
from __future__ import unicode_literals
from moto.core.exceptions import RESTError
NOT_FOUND_ENDPOINT_ERROR = """<ErrorResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
<Error>
<Type>{{ sender }}</Type>
<Code>{{ error_type }}</Code>
<Message>{{ message }}</Message>
</Error>
<RequestId>9dd01905-5012-5f99-8663-4b3ecd0dfaef</RequestId>
</ErrorResponse>"""
class SNSNotFoundError(RESTError):
code = 404
def __init__(self, message, **kwargs):
kwargs.setdefault("template", "endpoint_error")
kwargs.setdefault("sender", "Sender")
self.templates["endpoint_error"] = NOT_FOUND_ENDPOINT_ERROR
super(SNSNotFoundError, self).__init__("NotFound", message, **kwargs)

View File

@ -6,7 +6,7 @@ from collections import defaultdict
from moto.core.responses import BaseResponse
from moto.core.utils import camelcase_to_underscores
from .models import sns_backends
from .exceptions import InvalidParameterValue
from .exceptions import InvalidParameterValue, SNSNotFoundError
from .utils import is_e164
@ -543,24 +543,28 @@ class SNSResponse(BaseResponse):
def get_endpoint_attributes(self):
arn = self._get_param("EndpointArn")
endpoint = self.backend.get_endpoint(arn)
try:
endpoint = self.backend.get_endpoint(arn)
if self.request_json:
return json.dumps(
{
"GetEndpointAttributesResponse": {
"GetEndpointAttributesResult": {
"Attributes": endpoint.attributes
},
"ResponseMetadata": {
"RequestId": "384ac68d-3775-11df-8963-01868b7c937f"
},
if self.request_json:
return json.dumps(
{
"GetEndpointAttributesResponse": {
"GetEndpointAttributesResult": {
"Attributes": endpoint.attributes
},
"ResponseMetadata": {
"RequestId": "384ac68d-3775-11df-8963-01868b7c937f"
},
}
}
}
)
)
template = self.response_template(GET_ENDPOINT_ATTRIBUTES_TEMPLATE)
return template.render(endpoint=endpoint)
template = self.response_template(GET_ENDPOINT_ATTRIBUTES_TEMPLATE)
return template.render(endpoint=endpoint)
except SNSNotFoundError:
error_response = self._error("NotFound", "Endpoint does not exist")
return error_response, dict(status=404)
def set_endpoint_attributes(self):
arn = self._get_param("EndpointArn")