Skip to content

Commit

Permalink
Abstract ECS to container for shared logic
Browse files Browse the repository at this point in the history
  • Loading branch information
SamRemis committed Oct 26, 2023
1 parent 5b163b8 commit 5999c4e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions botocore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2938,8 +2938,8 @@ def _validate_allowed_url(self, full_url):
is_whitelisted_host = self._check_if_whitelisted_host(parsed.hostname)
if not is_whitelisted_host:
raise ValueError(
"Unsupported host '%s'. Can only "
"retrieve metadata from these hosts: %s"
"Unsupported host '%s'. Can only retrieve metadata "
"from a loopback address or one of these hosts: %s"
% (parsed.hostname, ', '.join(self._ALLOWED_HOSTS))
)

Expand All @@ -2956,7 +2956,7 @@ def _check_if_whitelisted_host(self, host):
return False

def retrieve_uri(self, relative_uri):
"""Retrieve JSON metadata from ECS metadata.
"""Retrieve JSON metadata from container metadata.
:type relative_uri: str
:param relative_uri: A relative URI, e.g "/foo/bar?id=123"
Expand Down Expand Up @@ -2998,22 +2998,20 @@ def _get_response(self, full_url, headers, timeout):
if response.status_code != 200:
raise MetadataRetrievalError(
error_msg=(
"Received non 200 response (%s) from ECS metadata: %s"
"Received non 200 response (%s) from container metadata: %s"
)
% (response.status_code, response_text)
)
try:
return json.loads(response_text)
except ValueError:
error_msg = (
"Unable to parse JSON returned from ECS metadata services"
)
error_msg = "Unable to parse JSON returned from container metadata services"
logger.debug('%s:%s', error_msg, response_text)
raise MetadataRetrievalError(error_msg=error_msg)
except RETRYABLE_HTTP_ERRORS as e:
error_msg = (
"Received error when attempting to retrieve "
"ECS metadata: %s" % e
"container metadata: %s" % e
)
raise MetadataRetrievalError(error_msg=error_msg)

Expand Down

0 comments on commit 5999c4e

Please sign in to comment.