Skip to content

Commit c9e21d0

Browse files
committed
Backport fixes
1 parent e41e633 commit c9e21d0

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

packages/smithy-aws-core/src/smithy_aws_core/credentials_resolvers/container.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
from smithy_core import URI
1010
from smithy_core.aio.interfaces.identity import IdentityResolver
11-
from smithy_core.exceptions import SmithyIdentityError
11+
from smithy_core.exceptions import SmithyIdentityException
1212
from smithy_http import Field, Fields
1313
from smithy_http.aio import HTTPRequest
1414
from smithy_http.aio.interfaces import HTTPClient, HTTPResponse
1515

16-
from smithy_aws_core.identity import AWSCredentialsIdentity, AWSIdentityProperties
16+
from smithy_aws_core.identity import AWSCredentialsIdentity, IdentityProperties
1717

1818
_CONTAINER_METADATA_IP = "169.254.170.2"
1919
_CONTAINER_METADATA_ALLOWED_HOSTS = {
@@ -47,7 +47,7 @@ def _validate_allowed_url(self, uri: URI) -> None:
4747
return
4848

4949
if not self._is_allowed_container_metadata_host(uri.host):
50-
raise SmithyIdentityError(
50+
raise SmithyIdentityException(
5151
f"Unsupported host '{uri.host}'. "
5252
f"Can only retrieve metadata from a loopback address or "
5353
f"one of: {', '.join(_CONTAINER_METADATA_ALLOWED_HOSTS)}"
@@ -69,22 +69,22 @@ async def get_credentials(self, uri: URI, fields: Fields) -> dict[str, str]:
6969
response: HTTPResponse = await self._http_client.send(request)
7070
body = await response.consume_body_async()
7171
if response.status != 200:
72-
raise SmithyIdentityError(
72+
raise SmithyIdentityException(
7373
f"Container metadata service returned {response.status}: "
7474
f"{body.decode('utf-8')}"
7575
)
7676
try:
7777
return json.loads(body.decode("utf-8"))
7878
except Exception as e:
79-
raise SmithyIdentityError(
79+
raise SmithyIdentityException(
8080
f"Unable to parse JSON from container metadata: {body.decode('utf-8')}"
8181
) from e
8282
except Exception as e:
8383
last_exc = e
8484
await asyncio.sleep(_SLEEP_SECONDS)
8585
attempts += 1
8686

87-
raise SmithyIdentityError(
87+
raise SmithyIdentityException(
8888
f"Failed to retrieve container metadata after {self._config.retries} attempt(s)"
8989
) from last_exc
9090

@@ -99,7 +99,7 @@ def _is_allowed_container_metadata_host(self, hostname: str) -> bool:
9999

100100

101101
class ContainerCredentialResolver(
102-
IdentityResolver[AWSCredentialsIdentity, AWSIdentityProperties]
102+
IdentityResolver[AWSCredentialsIdentity, IdentityProperties]
103103
):
104104
"""Resolves AWS Credentials from container credential sources."""
105105

@@ -134,7 +134,7 @@ async def _resolve_uri_from_env(self) -> URI:
134134
path=parsed.path,
135135
)
136136
else:
137-
raise SmithyIdentityError(
137+
raise SmithyIdentityException(
138138
f"Neither {self.ENV_VAR} or {self.ENV_VAR_FULL} environment "
139139
"variables are set. Unable to resolve credentials."
140140
)
@@ -146,7 +146,7 @@ async def _resolve_fields_from_env(self) -> Fields:
146146
filename = os.environ[self.ENV_VAR_AUTH_TOKEN_FILE]
147147
auth_token = await asyncio.to_thread(self._read_file, filename)
148148
except (FileNotFoundError, PermissionError) as e:
149-
raise SmithyIdentityError(
149+
raise SmithyIdentityException(
150150
f"Unable to open {os.environ[self.ENV_VAR_AUTH_TOKEN_FILE]}."
151151
) from e
152152

@@ -162,7 +162,7 @@ def _read_file(self, filename: str) -> str:
162162
return f.read().strip()
163163

164164
async def get_identity(
165-
self, *, properties: AWSIdentityProperties
165+
self, *, identity_properties: IdentityProperties
166166
) -> AWSCredentialsIdentity:
167167
uri = await self._resolve_uri_from_env()
168168
fields = await self._resolve_fields_from_env()
@@ -178,7 +178,7 @@ async def get_identity(
178178
expiration = datetime.fromisoformat(expiration).replace(tzinfo=UTC)
179179

180180
if access_key_id is None or secret_access_key is None:
181-
raise SmithyIdentityError(
181+
raise SmithyIdentityException(
182182
"AccessKeyId and SecretAccessKey are required for container credentials"
183183
)
184184

packages/smithy-aws-core/tests/unit/credentials_resolvers/test_container.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
import pytest
99
from smithy_aws_core.identity import AWSCredentialsIdentity
10-
from smithy_aws_core.identity.container import (
10+
from smithy_aws_core.credentials_resolvers.container import (
1111
ContainerCredentialConfig,
1212
ContainerCredentialResolver,
1313
ContainerMetadataClient,
1414
)
1515
from smithy_core import URI
16-
from smithy_core.exceptions import SmithyIdentityError
16+
from smithy_core.exceptions import SmithyIdentityException
1717
from smithy_http import Fields
1818

1919
if typing.TYPE_CHECKING:
@@ -67,7 +67,7 @@ async def test_metadata_client_invalid_host():
6767
# Invalid Host
6868
uri = URI(scheme="http", host="169.254.169.254")
6969

70-
with pytest.raises(SmithyIdentityError):
70+
with pytest.raises(SmithyIdentityException):
7171
await client.get_credentials(uri, Fields())
7272

7373

@@ -78,7 +78,7 @@ async def test_metadata_client_non_200_response():
7878
client = ContainerMetadataClient(http_client, config)
7979

8080
uri = URI(scheme="http", host="169.254.170.2")
81-
with pytest.raises(SmithyIdentityError) as e:
81+
with pytest.raises(SmithyIdentityException) as e:
8282
await client.get_credentials(uri, Fields())
8383

8484
# Ensure both the received retry error and underlying error are what we expect.
@@ -95,7 +95,7 @@ async def test_metadata_client_invalid_json():
9595
client = ContainerMetadataClient(http_client, config)
9696

9797
uri = URI(scheme="http", host="169.254.170.2")
98-
with pytest.raises(SmithyIdentityError):
98+
with pytest.raises(SmithyIdentityException):
9999
await client.get_credentials(uri, Fields())
100100

101101

@@ -113,7 +113,7 @@ async def test_metadata_client_retries():
113113
uri = URI(scheme="http", host="169.254.170.2", path="/task")
114114
http_client.send.side_effect = Exception()
115115

116-
with pytest.raises(SmithyIdentityError):
116+
with pytest.raises(SmithyIdentityException):
117117
await client.get_credentials(uri, Fields())
118118
assert http_client.send.call_count == 2
119119

@@ -271,5 +271,5 @@ async def test_resolver_missing_env():
271271

272272
with patch.dict(os.environ, {}):
273273
resolver = ContainerCredentialResolver(http_client)
274-
with pytest.raises(SmithyIdentityError):
274+
with pytest.raises(SmithyIdentityException):
275275
await resolver.get_identity(properties={})

0 commit comments

Comments
 (0)