Skip to content

Commit

Permalink
Type hinted credential dict
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmarwitz committed Dec 10, 2024
1 parent 0bf5359 commit 611efdc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions minimalkv/net/_aws_refreshable_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from datetime import datetime
from logging import getLogger
from typing import Dict, Optional
from typing import Any, Callable, Coroutine, Dict, Optional, TypedDict

Check warning on line 6 in minimalkv/net/_aws_refreshable_session.py

View check run for this annotation

Codecov / codecov/patch

minimalkv/net/_aws_refreshable_session.py#L4-L6

Added lines #L4 - L6 were not covered by tests

from aiobotocore.credentials import (

Check warning on line 8 in minimalkv/net/_aws_refreshable_session.py

View check run for this annotation

Codecov / codecov/patch

minimalkv/net/_aws_refreshable_session.py#L8

Added line #L8 was not covered by tests
AioRefreshableCredentials,
Expand All @@ -17,6 +17,13 @@
logger = getLogger(__name__)

Check warning on line 17 in minimalkv/net/_aws_refreshable_session.py

View check run for this annotation

Codecov / codecov/patch

minimalkv/net/_aws_refreshable_session.py#L17

Added line #L17 was not covered by tests


class BotoCredentials(TypedDict):
access_key: str
secret_key: str
token: str
expiry_time: str

Check warning on line 24 in minimalkv/net/_aws_refreshable_session.py

View check run for this annotation

Codecov / codecov/patch

minimalkv/net/_aws_refreshable_session.py#L20-L24

Added lines #L20 - L24 were not covered by tests


class RefreshableAssumeRoleProvider(CredentialProvider):

Check warning on line 27 in minimalkv/net/_aws_refreshable_session.py

View check run for this annotation

Codecov / codecov/patch

minimalkv/net/_aws_refreshable_session.py#L27

Added line #L27 was not covered by tests
"""A credential provider that loads self-refreshing credentials using 'sts.assume_role'.
Expand Down Expand Up @@ -58,13 +65,13 @@ async def load(self) -> AioRefreshableCredentials:

return refreshable_credentials

Check warning on line 66 in minimalkv/net/_aws_refreshable_session.py

View check run for this annotation

Codecov / codecov/patch

minimalkv/net/_aws_refreshable_session.py#L66

Added line #L66 was not covered by tests

def create_refresh(self):
async def _refresh() -> Dict:
def create_refresh(self) -> Callable[[], Coroutine[Any, Any, BotoCredentials]]:
async def _refresh() -> BotoCredentials:
logger.info("Refreshing credentials")
sts_client = self.sts_session.create_client("sts")
refresh = create_assume_role_refresher(sts_client, self._assume_role_params)

Check warning on line 72 in minimalkv/net/_aws_refreshable_session.py

View check run for this annotation

Codecov / codecov/patch

minimalkv/net/_aws_refreshable_session.py#L68-L72

Added lines #L68 - L72 were not covered by tests

credentials = await refresh()
credentials: BotoCredentials = await refresh()
to_zone = tz.tzlocal()
local_expiry_time = (

Check warning on line 76 in minimalkv/net/_aws_refreshable_session.py

View check run for this annotation

Codecov / codecov/patch

minimalkv/net/_aws_refreshable_session.py#L74-L76

Added lines #L74 - L76 were not covered by tests
datetime.strptime(credentials["expiry_time"], "%Y-%m-%dT%H:%M:%S%Z")
Expand Down

0 comments on commit 611efdc

Please sign in to comment.