Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix refreshable credentials injection #1314

Merged
merged 6 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Changes
-------
2.21.1 (2025-03-04)
^^^^^^^^^^^^^^^^^^^
* fix for refreshable credential account-id lookup

2.21.0 (2025-02-28)
^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion aiobotocore/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.21.0'
__version__ = '2.21.1'
8 changes: 7 additions & 1 deletion aiobotocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import botocore.parsers
import botocore.serialize
from botocore.args import ClientArgsCreator
from botocore.args import ClientArgsCreator, EPRBuiltins

from .config import AioConfig
from .endpoint import DEFAULT_HTTP_SESSION_CLS, AioEndpointCreator
Expand Down Expand Up @@ -176,6 +176,12 @@ def _build_endpoint_resolver(
credentials=credentials,
account_id_endpoint_mode=account_id_endpoint_mode,
)

# replace with async version
resolver_builtins[EPRBuiltins.ACCOUNT_ID] = (
credentials.get_account_id if credentials else None
)

# Client context params for s3 conflict with the available settings
# in the `s3` parameter on the `Config` object. If the same parameter
# is set in both places, the value in the `s3` parameter takes priority.
Expand Down
37 changes: 33 additions & 4 deletions aiobotocore/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ async def call(self):


class AioCredentials(Credentials):
# Overrides for property accessors
def get_account_id(self):
return self.account_id

def get_access_key(self):
return self.access_key

def get_secret_key(self):
return self.secret_key

def get_token(self):
return self.token

async def get_frozen_credentials(self):
return ReadOnlyCredentials(
self.access_key, self.secret_key, self.token, self.account_id
Expand All @@ -258,14 +271,30 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._refresh_lock = asyncio.Lock()

async def get_account_id(self):
await self._refresh()
return self._account_id

async def get_access_key(self):
await self._refresh()
return self._access_key

async def get_secret_key(self):
await self._refresh()
return self._secret_key

async def get_token(self):
await self._refresh()
return self._token

# Redeclaring the properties so it doesn't call refresh
# Have to redeclare setter as we're overriding the getter
@property
def access_key(self):
# TODO: this needs to be resolved
raise NotImplementedError(
"missing call to self._refresh. "
"Use get_frozen_credentials instead"
"Use get_frozen_credentials or get_access_key"
)
return self._access_key

Expand All @@ -278,7 +307,7 @@ def secret_key(self):
# TODO: this needs to be resolved
raise NotImplementedError(
"missing call to self._refresh. "
"Use get_frozen_credentials instead"
"Use get_frozen_credentials or get_secret_key instead"
)
return self._secret_key

Expand All @@ -291,7 +320,7 @@ def token(self):
# TODO: this needs to be resolved
raise NotImplementedError(
"missing call to self._refresh. "
"Use get_frozen_credentials instead"
"Use get_frozen_credentials or get_token instead"
)
return self._token

Expand All @@ -304,7 +333,7 @@ def account_id(self):
# TODO: this needs to be resolved
raise NotImplementedError(
"missing call to self._refresh. "
"Use get_frozen_credentials instead"
"Use get_frozen_credentials or get_account_id instead"
)
return self._account_id

Expand Down
10 changes: 7 additions & 3 deletions aiobotocore/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from botocore.exceptions import EndpointProviderError
from botocore.regions import EndpointRulesetResolver

from aiobotocore._helpers import resolve_awaitable

LOG = logging.getLogger(__name__)


Expand Down Expand Up @@ -82,9 +84,11 @@ async def _get_provider_params(
call_args=call_args,
)
if param_val is None and param_def.builtin is not None:
param_val = self._resolve_param_as_builtin(
builtin_name=param_def.builtin,
builtins=customized_builtins,
param_val = await resolve_awaitable(
self._resolve_param_as_builtin(
builtin_name=param_def.builtin,
builtins=customized_builtins,
)
)
if param_val is not None:
provider_params[param_name] = param_val
Expand Down