Skip to content

Commit 28cc2d5

Browse files
committed
Store Token value as a string instead of bytes
1 parent 3f79e6f commit 28cc2d5

File tree

1 file changed

+4
-4
lines changed
  • packages/smithy-aws-core/src/smithy_aws_core/credentials_resolvers

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Token:
7575
"""Represents an IMDSv2 session token with a value and method for checking
7676
expiration."""
7777

78-
def __init__(self, value: bytes, ttl: int):
78+
def __init__(self, value: str, ttl: int):
7979
self._value = value
8080
self._ttl = ttl
8181
self._created_time = datetime.now()
@@ -85,7 +85,7 @@ def is_expired(self) -> bool:
8585
return datetime.now() - self._created_time >= timedelta(seconds=self._ttl)
8686

8787
@property
88-
def value(self) -> bytes:
88+
def value(self) -> str:
8989
return self._value
9090

9191

@@ -133,7 +133,7 @@ async def _refresh(self) -> None:
133133
)
134134
response = await self._http_client.send(request)
135135
token_value = await response.consume_body_async()
136-
self._token = Token(token_value, self._config.token_ttl)
136+
self._token = Token(token_value.decode("utf-8"), self._config.token_ttl)
137137

138138
async def get_token(self) -> Token:
139139
"""Get the current token, refreshing it if expired."""
@@ -158,7 +158,7 @@ async def get(self, *, path: str) -> str:
158158
# TODO: Add user-agent
159159
Field(
160160
name="x-aws-ec2-metadata-token",
161-
values=[token.value.decode("utf-8")],
161+
values=[token.value],
162162
)
163163
]
164164
)

0 commit comments

Comments
 (0)