8
8
9
9
from smithy_core import URI
10
10
from smithy_core .aio .interfaces .identity import IdentityResolver
11
- from smithy_core .exceptions import SmithyIdentityError
11
+ from smithy_core .exceptions import SmithyIdentityException
12
12
from smithy_http import Field , Fields
13
13
from smithy_http .aio import HTTPRequest
14
14
from smithy_http .aio .interfaces import HTTPClient , HTTPResponse
15
15
16
- from smithy_aws_core .identity import AWSCredentialsIdentity , AWSIdentityProperties
16
+ from smithy_aws_core .identity import AWSCredentialsIdentity , IdentityProperties
17
17
18
18
_CONTAINER_METADATA_IP = "169.254.170.2"
19
19
_CONTAINER_METADATA_ALLOWED_HOSTS = {
@@ -47,7 +47,7 @@ def _validate_allowed_url(self, uri: URI) -> None:
47
47
return
48
48
49
49
if not self ._is_allowed_container_metadata_host (uri .host ):
50
- raise SmithyIdentityError (
50
+ raise SmithyIdentityException (
51
51
f"Unsupported host '{ uri .host } '. "
52
52
f"Can only retrieve metadata from a loopback address or "
53
53
f"one of: { ', ' .join (_CONTAINER_METADATA_ALLOWED_HOSTS )} "
@@ -69,22 +69,22 @@ async def get_credentials(self, uri: URI, fields: Fields) -> dict[str, str]:
69
69
response : HTTPResponse = await self ._http_client .send (request )
70
70
body = await response .consume_body_async ()
71
71
if response .status != 200 :
72
- raise SmithyIdentityError (
72
+ raise SmithyIdentityException (
73
73
f"Container metadata service returned { response .status } : "
74
74
f"{ body .decode ('utf-8' )} "
75
75
)
76
76
try :
77
77
return json .loads (body .decode ("utf-8" ))
78
78
except Exception as e :
79
- raise SmithyIdentityError (
79
+ raise SmithyIdentityException (
80
80
f"Unable to parse JSON from container metadata: { body .decode ('utf-8' )} "
81
81
) from e
82
82
except Exception as e :
83
83
last_exc = e
84
84
await asyncio .sleep (_SLEEP_SECONDS )
85
85
attempts += 1
86
86
87
- raise SmithyIdentityError (
87
+ raise SmithyIdentityException (
88
88
f"Failed to retrieve container metadata after { self ._config .retries } attempt(s)"
89
89
) from last_exc
90
90
@@ -99,7 +99,7 @@ def _is_allowed_container_metadata_host(self, hostname: str) -> bool:
99
99
100
100
101
101
class ContainerCredentialResolver (
102
- IdentityResolver [AWSCredentialsIdentity , AWSIdentityProperties ]
102
+ IdentityResolver [AWSCredentialsIdentity , IdentityProperties ]
103
103
):
104
104
"""Resolves AWS Credentials from container credential sources."""
105
105
@@ -134,7 +134,7 @@ async def _resolve_uri_from_env(self) -> URI:
134
134
path = parsed .path ,
135
135
)
136
136
else :
137
- raise SmithyIdentityError (
137
+ raise SmithyIdentityException (
138
138
f"Neither { self .ENV_VAR } or { self .ENV_VAR_FULL } environment "
139
139
"variables are set. Unable to resolve credentials."
140
140
)
@@ -146,7 +146,7 @@ async def _resolve_fields_from_env(self) -> Fields:
146
146
filename = os .environ [self .ENV_VAR_AUTH_TOKEN_FILE ]
147
147
auth_token = await asyncio .to_thread (self ._read_file , filename )
148
148
except (FileNotFoundError , PermissionError ) as e :
149
- raise SmithyIdentityError (
149
+ raise SmithyIdentityException (
150
150
f"Unable to open { os .environ [self .ENV_VAR_AUTH_TOKEN_FILE ]} ."
151
151
) from e
152
152
@@ -162,7 +162,7 @@ def _read_file(self, filename: str) -> str:
162
162
return f .read ().strip ()
163
163
164
164
async def get_identity (
165
- self , * , properties : AWSIdentityProperties
165
+ self , * , identity_properties : IdentityProperties
166
166
) -> AWSCredentialsIdentity :
167
167
uri = await self ._resolve_uri_from_env ()
168
168
fields = await self ._resolve_fields_from_env ()
@@ -178,7 +178,7 @@ async def get_identity(
178
178
expiration = datetime .fromisoformat (expiration ).replace (tzinfo = UTC )
179
179
180
180
if access_key_id is None or secret_access_key is None :
181
- raise SmithyIdentityError (
181
+ raise SmithyIdentityException (
182
182
"AccessKeyId and SecretAccessKey are required for container credentials"
183
183
)
184
184
0 commit comments