1
1
import asyncio
2
- import datetime
3
- import json
4
2
import logging
5
3
import os
6
4
import subprocess
7
5
from copy import deepcopy
8
- from hashlib import sha1
9
6
10
7
import botocore .compat
11
8
from botocore import UNSIGNED
27
24
CredentialResolver ,
28
25
CredentialRetrievalError ,
29
26
Credentials ,
27
+ DeferredRefreshableCredentials ,
30
28
EnvProvider ,
31
29
InstanceMetadataProvider ,
32
30
InvalidConfigError ,
39
37
RefreshableCredentials ,
40
38
RefreshWithMFAUnsupportedError ,
41
39
SharedCredentialProvider ,
40
+ SSOCredentialFetcher ,
42
41
SSOProvider ,
43
42
SSOTokenLoader ,
44
43
UnauthorizedSSOTokenError ,
50
49
parse ,
51
50
resolve_imds_endpoint_mode ,
52
51
)
53
- from dateutil .tz import tzutc
54
52
55
53
from aiobotocore ._helpers import resolve_awaitable
56
54
from aiobotocore .config import AioConfig
@@ -364,7 +362,9 @@ async def get_frozen_credentials(self):
364
362
return self ._frozen_credentials
365
363
366
364
367
- class AioDeferredRefreshableCredentials (AioRefreshableCredentials ):
365
+ class AioDeferredRefreshableCredentials (
366
+ DeferredRefreshableCredentials , AioRefreshableCredentials
367
+ ):
368
368
def __init__ (self , refresh_using , method , time_fetcher = _local_now ):
369
369
self ._refresh_using = refresh_using
370
370
self ._access_key = None
@@ -376,11 +376,6 @@ def __init__(self, refresh_using, method, time_fetcher=_local_now):
376
376
self .method = method
377
377
self ._frozen_credentials = None
378
378
379
- def refresh_needed (self , refresh_in = None ):
380
- if self ._frozen_credentials is None :
381
- return True
382
- return super ().refresh_needed (refresh_in )
383
-
384
379
385
380
class AioCachedCredentialFetcher (CachedCredentialFetcher ):
386
381
async def _get_credentials (self ):
@@ -747,11 +742,14 @@ async def _resolve_source_credentials(self, role_config, profile_name):
747
742
async def _resolve_credentials_from_profile (self , profile_name ):
748
743
profiles = self ._loaded_config .get ('profiles' , {})
749
744
profile = profiles [profile_name ]
750
-
751
745
if (
752
746
self ._has_static_credentials (profile )
753
747
and not self ._profile_provider_builder
754
748
):
749
+ # This is only here for backwards compatibility. If this provider
750
+ # isn't given a profile provider builder we still want to be able
751
+ # handle the basic static credential case as we would before the
752
+ # provile provider builder parameter was added.
755
753
return self ._resolve_static_credentials_from_profile (profile )
756
754
elif self ._has_static_credentials (
757
755
profile
@@ -770,7 +768,6 @@ async def _resolve_credentials_from_profile(self, profile_name):
770
768
error_msg = error_message % profile_name ,
771
769
)
772
770
return credentials
773
-
774
771
return await self ._load_creds_via_assume_role (profile_name )
775
772
776
773
def _resolve_static_credentials_from_profile (self , profile ):
@@ -971,52 +968,9 @@ async def load_credentials(self):
971
968
return None
972
969
973
970
974
- class AioSSOCredentialFetcher (AioCachedCredentialFetcher ):
975
- _UTC_DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
976
-
977
- def __init__ (
978
- self ,
979
- start_url ,
980
- sso_region ,
981
- role_name ,
982
- account_id ,
983
- client_creator ,
984
- token_loader = None ,
985
- cache = None ,
986
- expiry_window_seconds = None ,
987
- token_provider = None ,
988
- sso_session_name = None ,
989
- ):
990
- self ._client_creator = client_creator
991
- self ._sso_region = sso_region
992
- self ._role_name = role_name
993
- self ._account_id = account_id
994
- self ._start_url = start_url
995
- self ._token_loader = token_loader
996
- self ._token_provider = token_provider
997
- self ._sso_session_name = sso_session_name
998
- super ().__init__ (cache , expiry_window_seconds )
999
-
1000
- def _create_cache_key (self ):
1001
- args = {
1002
- 'roleName' : self ._role_name ,
1003
- 'accountId' : self ._account_id ,
1004
- }
1005
- if self ._sso_session_name :
1006
- args ['sessionName' ] = self ._sso_session_name
1007
- else :
1008
- args ['startUrl' ] = self ._start_url
1009
-
1010
- args = json .dumps (args , sort_keys = True , separators = (',' , ':' ))
1011
- argument_hash = sha1 (args .encode ('utf-8' )).hexdigest ()
1012
- return self ._make_file_safe (argument_hash )
1013
-
1014
- def _parse_timestamp (self , timestamp_ms ):
1015
- # fromtimestamp expects seconds so: milliseconds / 1000 = seconds
1016
- timestamp_seconds = timestamp_ms / 1000.0
1017
- timestamp = datetime .datetime .fromtimestamp (timestamp_seconds , tzutc ())
1018
- return timestamp .strftime (self ._UTC_DATE_FORMAT )
1019
-
971
+ class AioSSOCredentialFetcher (
972
+ SSOCredentialFetcher , AioCachedCredentialFetcher
973
+ ):
1020
974
async def _get_credentials (self ):
1021
975
"""Get credentials by calling SSO get role credentials."""
1022
976
config = Config (
0 commit comments