
    vKg,K                       S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	  S SK
Jr  S SKJr  S SKJr  S SKJrJr  S SKrS SKrS SKJr  S SKJrJr  S S	KJr  S S
KJrJrJrJrJ r J!r!J"r"J#r#J$r$  S SK%J&r&  S SK'J(r(J)r)J*r*J+r+J,r,J-r-J.r.  \R^                  " \05      r1\	" S/ SQ5      r2Sr3Sr4SGS jr5 " S S5      r6S r7S r8S r9SHS jr:S r;S r<S r= " S S5      r> " S S\>5      r? " S S \?5      r@ " S! S"5      rA " S# S$\A5      rB " S% S&\B5      rC " S' S(\B5      rD " S) S*5      rE " S+ S,\E5      rF " S- S.\E5      rG " S/ S0\E5      rH " S1 S2\E5      rI " S3 S4\E5      rJ " S5 S6\E5      rK " S7 S8\E5      rL " S9 S:\E5      rM " S; S<\E5      rN " S= S>5      rO " S? S@\E5      rP " SA SB5      rQ " SC SD\A5      rR " SE SF\E5      rSg)I    N)
namedtuple)deepcopy)sha1parse)tzlocaltzutc)UNSIGNED)compat_shell_splittotal_seconds)Config)	ConfigNotFoundCredentialRetrievalErrorInfiniteLoopConfigErrorInvalidConfigErrorMetadataRetrievalErrorPartialCredentialsErrorRefreshWithMFAUnsupportedErrorUnauthorizedSSOTokenErrorUnknownCredentialError)SSOTokenProvider)ContainerMetadataFetcherFileWebIdentityTokenLoaderInstanceMetadataFetcherJSONFileCacheSSOTokenLoaderparse_key_val_fileresolve_imds_endpoint_modeReadOnlyCredentials
access_key
secret_keytokeniX    c                   ^  T R                  S5      =(       d    SnT R                  S5      nT R                  S5      nT R                  5       R                  S5      SLnT R                  S5      [        T 5      [        T R                  S5      S.nUc  0 n[        5       n[        5       n	[        [        UUT R                  5       US	9S
9n
[        T XS9n[        U 4S j[        T U5      UU[        XU
/5      US9nUU/nUR                  UUS9n[        5       [!        5       U	U
/nX-   U-   nU(       a&  UR#                  U5        [$        R'                  S5        [)        US9nU$ )zCreate a default credential resolver.

This creates a pre-configured credential resolver
that includes the default lookup chain for
credentials.

profiledefaultmetadata_service_timeoutmetadata_service_num_attemptsNec2_metadata_service_endpointec2_metadata_v1_disabled)r*   "ec2_metadata_service_endpoint_modeec2_credential_refresh_windowr+   )timeoutnum_attempts
user_agentconfig)iam_role_fetcher)cacheregion_namec                     > T R                   $ N)full_configsessions   T/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/botocore/credentials.py<lambda>,create_credential_resolver.<locals>.<lambda>m   s    G//    )load_configclient_creatorr3   profile_namecredential_sourcerprofile_provider_builderr@   disable_env_varszWSkipping environment variable credential check because profile name was explicitly set.	providers)get_config_variableinstance_variablesgetr   !_DEFAULT_ADVISORY_REFRESH_TIMEOUTEnvProviderContainerProviderInstanceMetadataProviderr   r0   ProfileProviderBuilderAssumeRoleProvider_get_client_creatorCanonicalNameCredentialSourcerrF   OriginalEC2ProviderBotoProviderremoveloggerdebugCredentialResolver)r9   r3   r4   r@   metadata_timeoutr/   rD   imds_configenv_providercontainer_providerinstance_metadata_providerrB   assume_role_providerpre_profileprofile_providerspost_profilerF   resolvers   `                 r:   create_credential_resolverrb   A   s    ..y9FYL223MN../NOL11377	B$N *1)D)D+*
 /I/
 *K$+$?$?&%
K }=L*,!90$%))+	
"  6u  ./*7K@!9/IJ
 ":	 	K 1::!) ; 
 	"	L /,>I  	&8	

 "I6HOr=   c                   L    \ rS rSrSr SS jrSS jrS rS rS r	S	 r
S
 rSrg)rN      a  This class handles the creation of profile based providers.

NOTE: This class is only intended for internal use.

This class handles the creation and ordering of the various credential
providers that primarly source their configuration from the shared config.
This is needed to enable sharing between the default credential chain and
the source profile chain created by the assume role provider.
Nc                 4    Xl         X l        X0l        X@l        g r6   )_session_cache_region_name_sso_token_cache)selfr9   r3   r4   sso_token_caches        r:   __init__ProfileProviderBuilder.__init__   s      ' /r=   c                     U R                  UU5      U R                  U5      U R                  U5      U R                  U5      U R	                  U5      /$ r6   )_create_web_identity_provider_create_sso_provider"_create_shared_credential_provider_create_process_provider_create_config_providerrj   r@   rD   s      r:   rF    ProfileProviderBuilder.providers   sZ    ..  %%l333LA)),7((6	
 		
r=   c                     ^  [        UU 4S jS9$ )Nc                  0   > T R                   R                  $ r6   rf   r7   rj   s   r:   r;   AProfileProviderBuilder._create_process_provider.<locals>.<lambda>        9 9r=   )r@   r>   )ProcessProviderrj   r@   s   ` r:   rr   /ProfileProviderBuilder._create_process_provider   s    %9
 	
r=   c                 L    U R                   R                  S5      n[        UUS9$ )Ncredentials_file)r@   creds_filename)rf   rG   SharedCredentialProvider)rj   r@   credential_files      r:   rq   9ProfileProviderBuilder._create_shared_credential_provider   s*    --;;<NO'%*
 	
r=   c                 L    U R                   R                  S5      n[        UUS9$ )Nconfig_file)r@   config_filename)rf   rG   ConfigProvider)rj   r@   r   s      r:   rs   .ProfileProviderBuilder._create_config_provider   s)    mm77F%'
 	
r=   c                 v   ^  [        U 4S j[        T R                  T R                  5      T R                  UUS9$ )Nc                  0   > T R                   R                  $ r6   rx   ry   s   r:   r;   FProfileProviderBuilder._create_web_identity_provider.<locals>.<lambda>   r{   r=   )r>   r?   r3   r@   rD   )!AssumeRoleWithWebIdentityProviderrP   rf   rh   rg   rt   s   `  r:   ro   4ProfileProviderBuilder._create_web_identity_provider   s9    09.t00 ++%-
 	
r=   c                    ^  [        U 4S jT R                  R                  UT R                  T R                  [        T R                  T R                  US9S9$ )Nc                  0   > T R                   R                  $ r6   rx   ry   s   r:   r;   =ProfileProviderBuilder._create_sso_provider.<locals>.<lambda>   r{   r=   )r3   r@   )r>   r?   r@   r3   token_cachetoken_provider)SSOProviderrf   create_clientrg   ri   r   r}   s   ` r:   rp   +ProfileProviderBuilder._create_sso_provider   sN    9==66%++--+++)
 	
r=   )rg   rh   rf   ri   NNNF)__name__
__module____qualname____firstlineno____doc__rl   rF   rr   rq   rs   ro   rp   __static_attributes__ r=   r:   rN   rN      s1     FJ0




	

r=   rN   c                 8    [        U 5      nUR                  5       $ r6   )rb   load_credentials)r9   ra   s     r:   get_credentialsr      s    )'2H$$&&r=   c                  P    [         R                   R                  [        5       5      $ r6   )datetimenowr   r   r=   r:   
_local_nowr      s      ++r=   c                 Z    [        U [        R                  5      (       a  U $ [        U 5      $ r6   )
isinstancer   r   )values    r:   _parse_if_neededr      s$    %**++<r=   c                     [        U [        R                  5      (       a(  U(       a  U R                  5       $ U R                  S5      $ U $ )Nz%Y-%m-%dT%H:%M:%S%Z)r   r   	isoformatstrftime)r   isos     r:   _serialize_if_neededr      s:    %**++??$$~~344Lr=   c                    ^ ^ UU 4S jnU$ )Nc                 V   > ST0nUR                   " S0 UD6  TR                  " U 40 UD6$ )Nr4   r   )updater   )service_namekwargscreate_client_kwargsr4   r9   s      r:   r?   +_get_client_creator.<locals>.client_creator  s6     -{;##-f-$$\J5IJJr=   r   )r9   r4   r?   s   `` r:   rP   rP     s    K
 r=   c                    ^ ^ U U4S jnU$ )Nc                  j   > TR                   " S0 TD6n U S   nUS   US   US   [        US   5      S.$ )NCredentialsAccessKeyIdSecretAccessKeySessionToken
Expirationr!   r"   r#   expiry_timer   )assume_roler   )responsecredentialsclientparamss     r:   refresh-create_assume_role_refresher.<locals>.refresh  sR    %%//}- &m4%&78 0/L0IJ	
 	
r=   r   )r   r   r   s   `` r:   create_assume_role_refresherr     s    

 Nr=   c                 &     " S S5      nU" U 5      $ )Nc                        \ rS rSrS rS rSrg)/create_mfa_serial_refresher.<locals>._Refresheri  c                     Xl         SU l        g )NF)_refresh_has_been_called)rj   r   s     r:   rl   8create_mfa_serial_refresher.<locals>._Refresher.__init__   s    #M$)D!r=   c                 f    U R                   (       a
  [        5       eSU l         U R                  5       $ NT)r   r   r   ry   s    r:   __call__8create_mfa_serial_refresher.<locals>._Refresher.__call__$  s*    $$ 566$(D!==?"r=   )r   r   N)r   r   r   r   rl   r   r   r   r=   r:   
_Refresherr     s    	*	#r=   r   r   )actual_refreshr   s     r:   create_mfa_serial_refresherr     s    # # n%%r=   c                   .    \ rS rSrSrSS jrS rS rSrg)	r   i0  aT  
Holds the credentials needed to authenticate requests.

:param str access_key: The access key part of the credentials.
:param str secret_key: The secret key part of the credentials.
:param str token: The security token, valid only for session credentials.
:param str method: A string which identifies where the credentials
    were found.
Nc                 ^    Xl         X l        X0l        Uc  SnX@l        U R	                  5         g )Nexplicit)r!   r"   r#   method
_normalize)rj   r!   r"   r#   r   s        r:   rl   Credentials.__init__;  s*    $$
>Fr=   c                     [         R                  R                  U R                  5      U l        [         R                  R                  U R                  5      U l        g r6   )botocorecompatensure_unicoder!   r"   ry   s    r:   r   Credentials._normalizeF  s8     #//88I"//88Ir=   c                 X    [        U R                  U R                  U R                  5      $ r6   )r   r!   r"   r#   ry   s    r:   get_frozen_credentials"Credentials.get_frozen_credentialsP  s"    "OOT__djj
 	
r=   )r!   r   r"   r#   NN)	r   r   r   r   r   rl   r   r   r   r   r=   r:   r   r   0  s    	J
r=   r   c                   (   \ rS rSrSr\r\r\	SS4S jr
S r\  SS j5       r\S 5       r\R                   S 5       r\S	 5       r\R                   S
 5       r\S 5       r\R                   S 5       rS rSS jrS rS rS r\S 5       rS rS rSrg)RefreshableCredentialsiV  a]  
Holds the credentials needed to authenticate requests. In addition, it
knows how to refresh itself.

:param str access_key: The access key part of the credentials.
:param str secret_key: The secret key part of the credentials.
:param str token: The security token, valid only for session credentials.
:param datetime expiry_time: The expiration time of the credentials.
:param function refresh_using: Callback function to refresh the credentials.
:param str method: A string which identifies where the credentials
    were found.
:param function time_fetcher: Callback function to retrieve current time.
Nc
                     XPl         Xl        X l        X0l        X@l        Xpl        [        R                  " 5       U l        X`l	        [        XU5      U l        U R                  5         Ub  Xl        U	b  Xl        g g r6   )_refresh_using_access_key_secret_key_token_expiry_time_time_fetcher	threadingLock_refresh_lockr   r   _frozen_credentialsr   _advisory_refresh_timeout_mandatory_refresh_timeout)
rj   r!   r"   r#   r   refresh_usingr   time_fetcheradvisory_timeoutmandatory_timeouts
             r:   rl   RefreshableCredentials.__init__l  sv     ,%%')&^^-#6E$
  	'-=*(.?+ )r=   c                     [         R                  R                  U R                  5      U l        [         R                  R                  U R                  5      U l        g r6   )r   r   r   r   r   ry   s    r:   r   !RefreshableCredentials._normalize  s<    #??99$:J:JK#??99$:J:JKr=   c           
      z    0 nUb  XFS'   Ub  XVS'   U " SUS   US   US   U R                  US   5      UUS.UD6nU$ )	Nr   r   r!   r"   r#   r   )r!   r"   r#   r   r   r   r   )_expiry_datetime)clsmetadatar   r   r   r   r   instances           r:   create_from_metadata+RefreshableCredentials.create_from_metadata  sx     ')9%&(*;&' 
--7#,,Xm-DE'
 
 r=   c                 :    U R                  5         U R                  $ zWarning: Using this property can lead to race conditions if you
access another property subsequently along the refresh boundary.
Please use get_frozen_credentials instead.
)r   r   ry   s    r:   r!   !RefreshableCredentials.access_key       	r=   c                     Xl         g r6   )r   rj   r   s     r:   r!   r         r=   c                 :    U R                  5         U R                  $ r  )r   r   ry   s    r:   r"   !RefreshableCredentials.secret_key  r  r=   c                     Xl         g r6   )r   r  s     r:   r"   r
    r  r=   c                 :    U R                  5         U R                  $ r  )r   r   ry   s    r:   r#   RefreshableCredentials.token  s     	{{r=   c                     Xl         g r6   )r   r  s     r:   r#   r    s    r=   c                 R    U R                   U R                  5       -
  n[        U5      $ r6   )r   r   r   )rj   deltas     r:   _seconds_remaining)RefreshableCredentials._seconds_remaining  s&    !!D$6$6$88U##r=   c                     U R                   c  gUc  U R                  nU R                  5       U:  a  g[        R	                  S5        g)aK  Check if a refresh is needed.

A refresh is needed if the expiry time associated
with the temporary credentials is less than the
provided ``refresh_in``.  If ``time_delta`` is not
provided, ``self.advisory_refresh_needed`` will be used.

For example, if your temporary credentials expire
in 10 minutes and the provided ``refresh_in`` is
``15 * 60``, then this function will return ``True``.

:type refresh_in: int
:param refresh_in: The number of seconds before the
    credentials expire in which refresh attempts should
    be made.

:return: True if refresh needed, False otherwise.

Fz!Credentials need to be refreshed.T)r   r   r  rU   rV   )rj   
refresh_ins     r:   refresh_needed%RefreshableCredentials.refresh_needed  sJ    ( $77J ""$
289r=   c                      U R                  SS9$ )Nr   )r  )r  ry   s    r:   _is_expired"RefreshableCredentials._is_expired  s    ""a"00r=   c                    U R                  U R                  5      (       d  g U R                  R                  S5      (       a   U R                  U R                  5      (       d   U R                  R	                  5         g U R                  U R
                  5      nU R                  US9   U R                  R	                  5         g U R                  U R
                  5      (       aO  U R                     U R                  U R
                  5      (       d
   S S S 5        g U R                  SS9  S S S 5        g g ! U R                  R	                  5         f = f! , (       d  f       g = f)NF)is_mandatoryT)r  r   r   acquirereleaser   _protected_refresh)rj   is_mandatory_refreshs     r:   r   RefreshableCredentials._refresh  s3    ""4#A#ABB %%e,,	-**4+I+IJJ ""**, (,':':33($ ''5I'J""**,  !@!@AA ##**4+J+JKK $# ''T': $# B ""**, $#s$    D5 ?*D5 1"EE5E
E"c                     U R                  5       nU R	                  U5        [        U R                  U R                  U R                  5      U l	        U R                  5       (       a"  Sn[        R                  U5        [        U5      eg ! [         a+    U(       a  SOSn[        R                  SUSS9  U(       a  e  g f = f)N	mandatoryadvisoryzARefreshing temporary credentials failed during %s refresh period.Texc_infozLCredentials were refreshed, but the refreshed credentials are still expired.)r   	ExceptionrU   warning_set_from_datar   r   r   r   r   r  RuntimeError)rj   r  r   period_namemsgs        r:   r  )RefreshableCredentials._protected_refresh  s    	**,H$ 	H%#6d..$
  ;  NN3s## +  	)5+:KNN,	     !	s   B 2C ?C c                     [        U 5      $ r6   r   )time_strs    r:   r   'RefreshableCredentials._expiry_datetime=  s    Xr=   c                 z   / SQnU(       d  UnOU Vs/ sH  oDU;  d  M
  UPM     nnU(       a(  Sn[        U R                  USR                  U5      -  S9eUS   U l        US   U l        US   U l        [        US   5      U l        [        R                  S	U R                  5        U R                  5         g s  snf )
Nr   z7Credential refresh failed, response did not contain: %s, provider	error_msgr!   r"   r#   r   z(Retrieved credentials will expire at: %s)r   r   joinr!   r"   r#   r   r   rU   rV   r   )rj   dataexpected_keysmissing_keyskmessages         r:   r(  %RefreshableCredentials._set_from_dataA  s    L(L'4F}!A}LFOG*!DIIl$;; 
 |,|,']
!$}"5668I8I	
 	! Gs
   B8B8c                 :    U R                  5         U R                  $ )a  Return immutable credentials.

The ``access_key``, ``secret_key``, and ``token`` properties
on this class will always check and refresh credentials if
needed before returning the particular credentials.

This has an edge case where you can get inconsistent
credentials.  Imagine this:

    # Current creds are "t1"
    tmp.access_key  ---> expired? no, so return t1.access_key
    # ---- time is now expired, creds need refreshing to "t2" ----
    tmp.secret_key  ---> expired? yes, refresh and return t2.secret_key

This means we're using the access key from t1 with the secret key
from t2.  To fix this issue, you can request a frozen credential object
which is guaranteed not to change.

The frozen credentials returned from this method should be used
immediately and then discarded.  The typical usage pattern would
be::

    creds = RefreshableCredentials(...)
    some_code = SomeSignerObject()
    # I'm about to sign the request.
    # The frozen credentials are only used for the
    # duration of generate_presigned_url and will be
    # immediately thrown away.
    request = some_code.sign_some_request(
        with_credentials=creds.get_frozen_credentials())
    print("Signed request:", request)

)r   r   ry   s    r:   r   -RefreshableCredentials.get_frozen_credentialsX  s    D 	'''r=   )r   r   r   r   r   r   r   r   r   r   r!   r   r"   r#   r   r6   )r   r   r   r   r   rJ   r   "_DEFAULT_MANDATORY_REFRESH_TIMEOUTr   r   rl   r   classmethodr   propertyr!   setterr"   r#   r  r  r  r   r  staticmethodr   r(  r   r   r   r=   r:   r   r   V  s     !B "D  @:L   2     ! !     ! !   \\ $ D1;<%$N  .#(r=   r   c                   <   ^  \ rS rSrSr\4S jrSU 4S jjrSrU =r	$ )DeferredRefreshableCredentialsi~  zqRefreshable credentials that don't require initial credentials.

refresh_using will be called upon first access.
c                     Xl         S U l        S U l        S U l        S U l        X0l        [        R                  " 5       U l        X l	        S U l
        g r6   )r   r   r   r   r   r   r   r   r   r   r   )rj   r   r   r   s       r:   rl   'DeferredRefreshableCredentials.__init__  sI    + )&^^-#' r=   c                 >   > U R                   c  g[        TU ]	  U5      $ r   )r   superr  )rj   r  	__class__s     r:   r  -DeferredRefreshableCredentials.refresh_needed  s"    ##+w%j11r=   )	r   r   r   r   r   r   r   r   r   r6   )
r   r   r   r   r   r   rl   r  r   __classcell__rI  s   @r:   rD  rD  ~  s    
 <F 	(2 2r=   rD  c                   R    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rS rSrg)CachedCredentialFetcheri  r$   Nc                 n    Uc  0 nXl         U R                  5       U l        Uc  U R                  nX l        g r6   )rg   _create_cache_key
_cache_keyDEFAULT_EXPIRY_WINDOW_SECONDS_expiry_window_seconds)rj   r3   expiry_window_secondss      r:   rl    CachedCredentialFetcher.__init__  s9    =E002 ($($F$F!&;#r=   c                     [        S5      e)Nz_create_cache_key()NotImplementedErrorry   s    r:   rP  )CachedCredentialFetcher._create_cache_key  s    !"788r=   c                     UR                  SS5      R                  [        R                  S5      nUR                  SS5      $ )N:_/)replaceossep)rj   filenames     r:   _make_file_safe'CachedCredentialFetcher._make_file_safe  s8    ##C-55bffcBS))r=   c                     [        S5      e)Nz_get_credentials()rW  ry   s    r:   _get_credentials(CachedCredentialFetcher._get_credentials  s    !"677r=   c                 "    U R                  5       $ r6   )_get_cached_credentialsry   s    r:   fetch_credentials)CachedCredentialFetcher.fetch_credentials  s    ++--r=   c                     U R                  5       nUc"  U R                  5       nU R                  U5        O[        R	                  S5        US   n[        US   SS9nUS   US   US   US	.$ )
z~Get up-to-date credentials.

This will check the cache for up-to-date credentials, calling assume
role if none are available.
z*Credentials for role retrieved from cache.r   r   T)r   r   r   r   r   )_load_from_cachere  _write_to_cacherU   rV   r   )rj   r   creds
expirations       r:   rh  /CachedCredentialFetcher._get_cached_credentials  s     ((*,,.H  *LLEF')%*=4H
. 12>*%	
 	
r=   c                     U R                   U R                  ;   aO  [        U R                  U R                      5      nU R                  U5      (       d  U$ [        R                  S5        g )Nz6Credentials were found in cache, but they are expired.)rQ  rg   r   r  rU   rV   )rj   rn  s     r:   rl  (CachedCredentialFetcher._load_from_cache  sS    ??dkk)T[[9:E##E**L r=   c                 H    [        U5      U R                  U R                  '   g r6   )r   rg   rQ  )rj   r   s     r:   rm  'CachedCredentialFetcher._write_to_cache  s    '/'9DOO$r=   c                 l    [        US   S   5      n[        U[        5       -
  5      nX0R                  :  $ )z!Check if credentials are expired.r   r   )r   r   r   rS  )rj   r   end_timesecondss       r:   r  #CachedCredentialFetcher._is_expired  s6    #K$>|$LM:< 784444r=   )rg   rQ  rS  r   )r   r   r   r   rR  rl   rP  rb  re  ri  rh  rl  rm  r  r   r   r=   r:   rN  rN    s5    $+!<9*
8.
,	:5r=   rN  c                   >   ^  \ rS rSr   SU 4S jjrS rS rSrU =r$ )BaseAssumeRoleCredentialFetcheri  c                 4  > Xl         X l        Uc  0 U l        O[        U5      U l        U R                  U R                  S'   U R                  R	                  S5      U l        SU l        U R
                  (       d  U R                  5         [        TU ]%  XE5        g )NRoleArnRoleSessionNameF)
_client_creator	_role_arn_assume_kwargsr   rI   _role_session_name_using_default_session_name_generate_assume_role_namerH  rl   )rj   r?   role_arn
extra_argsr3   rT  rI  s         r:   rl   (BaseAssumeRoleCredentialFetcher.__init__  s      .!"$D"*:"6D)-I&"&"5"5"9"9:K"L+0(&&++-6r=   c                     S[        [        R                  " 5       5       3U l        U R                  U R                  S'   SU l        g )Nzbotocore-session-r}  T)inttimer  r  r  ry   s    r:   r  :BaseAssumeRoleCredentialFetcher._generate_assume_role_name  s<    $5c$))+6F5G"H151H1H-.+/(r=   c                 4   [        U R                  5      nU R                  (       a  US	 SU;   a  [        R                  " US   5      US'   [        R
                  " USS9n[        UR                  S5      5      R                  5       nU R                  U5      $ ){Create a predictable cache key for the current configuration.

The cache key is intended to be compatible with file names.
r}  PolicyT)	sort_keysutf-8)
r   r  r  jsonloadsdumpsr   encode	hexdigestrb  rj   argsargument_hashs      r:   rP  1BaseAssumeRoleCredentialFetcher._create_cache_key  s    
 ++, ++&'t "ZZX7DNzz$$/T[[12<<>##M22r=   )r  r~  r  r  r  r   )	r   r   r   r   rl   r  rP  r   rK  rL  s   @r:   rz  rz    s"    
 "700
3 3r=   rz  c                   F   ^  \ rS rSr    SU 4S jjrS rS rS rSrU =r	$ )AssumeRoleCredentialFetcheri  c                    > X l         XPl        U R                  c  [        R                  U l        [        TU ]  UUUUUS9  g)a)  
:type client_creator: callable
:param client_creator: A callable that creates a client taking
    arguments like ``Session.create_client``.

:type source_credentials: Credentials
:param source_credentials: The credentials to use to create the
    client for the call to AssumeRole.

:type role_arn: str
:param role_arn: The ARN of the role to be assumed.

:type extra_args: dict
:param extra_args: Any additional arguments to add to the assume
    role request using the format of the botocore operation.
    Possible keys include, but may not be limited to,
    DurationSeconds, Policy, SerialNumber, ExternalId and
    RoleSessionName.

:type mfa_prompter: callable
:param mfa_prompter: A callable that returns input provided by the
    user (i.e raw_input, getpass.getpass, etc.).

:type cache: dict
:param cache: An object that supports ``__getitem__``,
    ``__setitem__``, and ``__contains__``.  An example of this is
    the ``JSONFileCache`` class in aws-cli.

:type expiry_window_seconds: int
:param expiry_window_seconds: The amount of time, in seconds,
Nr  r3   rT  )_source_credentials_mfa_promptergetpassrH  rl   )	rj   r?   source_credentialsr  r  mfa_prompterr3   rT  rI  s	           r:   rl   $AssumeRoleCredentialFetcher.__init__  sK    R $6 )%!(D!"7 	 	
r=   c                 f    U R                  5       nU R                  5       nUR                  " S0 UD6$ )'Get credentials by calling assume role.r   )_assume_role_kwargs_create_clientr   )rj   r   r   s      r:   re  ,AssumeRoleCredentialFetcher._get_credentialsF  s2    ))+$$&!!+F++r=   c                     [        U R                  5      nUR                  S5      nUb  SU S3nU R                  U5      nXAS'   UR                  S5      nUb  XQS'   U$ )AGet the arguments for assume role based on current configuration.SerialNumberzEnter MFA code for z: 	TokenCodeDurationSeconds)r   r  rI   r  )rj   assume_role_kwargs
mfa_serialprompt
token_codeduration_secondss         r:   r  /AssumeRoleCredentialFetcher._assume_role_kwargsL  sv    %d&9&9:'++N;
!*:,b9F++F3J.8{+-112CD'4D01!!r=   c                     U R                   R                  5       nU R                  SUR                  UR                  UR
                  S9$ )z2Create an STS client using the source credentials.sts)aws_access_key_idaws_secret_access_keyaws_session_token)r  r   r~  r!   r"   r#   )rj   frozen_credentialss     r:   r  *AssumeRoleCredentialFetcher._create_client^  sM    !55LLN##0;;"4"?"?066	 $ 
 	
r=   )r  r  )NNNN)
r   r   r   r   rl   re  r  r  r   rK  rL  s   @r:   r  r    s+     "4
l,"$
 
r=   r  c                   >   ^  \ rS rSr   SU 4S jjrS rS rSrU =r$ )*AssumeRoleWithWebIdentityCredentialFetcherii  c                 4   > X l         [        TU ]	  UUUUUS9  g)a  
:type client_creator: callable
:param client_creator: A callable that creates a client taking
    arguments like ``Session.create_client``.

:type web_identity_token_loader: callable
:param web_identity_token_loader: A callable that takes no arguments
and returns a web identity token str.

:type role_arn: str
:param role_arn: The ARN of the role to be assumed.

:type extra_args: dict
:param extra_args: Any additional arguments to add to the assume
    role request using the format of the botocore operation.
    Possible keys include, but may not be limited to,
    DurationSeconds, Policy, SerialNumber, ExternalId and
    RoleSessionName.

:type cache: dict
:param cache: An object that supports ``__getitem__``,
    ``__setitem__``, and ``__contains__``.  An example of this is
    the ``JSONFileCache`` class in aws-cli.

:type expiry_window_seconds: int
:param expiry_window_seconds: The amount of time, in seconds,
r  N)_web_identity_token_loaderrH  rl   )rj   r?   web_identity_token_loaderr  r  r3   rT  rI  s          r:   rl   3AssumeRoleWithWebIdentityCredentialFetcher.__init__l  s.    H +D'!"7 	 	
r=   c                     U R                  5       n[        [        S9nU R                  SUS9nUR                  " S0 UD6$ )r  )signature_versionr  r1   r   )r  r   r
   r~  assume_role_with_web_identity)rj   r   r1   r   s       r:   re  ;AssumeRoleWithWebIdentityCredentialFetcher._get_credentials  sE    ))+ (3%%eF%;33=f==r=   c                 X    [        U R                  5      nU R                  5       nX!S'   U$ )r  WebIdentityToken)r   r  r  )rj   r  identity_tokens      r:   r  >AssumeRoleWithWebIdentityCredentialFetcher._assume_role_kwargs  s0    %d&9&9:88:1?-.!!r=   )r  r   )	r   r   r   r   rl   re  r  r   rK  rL  s   @r:   r  r  i  s#     ",
\>" "r=   r  c                   2    \ rS rSrSrSrSS jrS rS rSr	g)CredentialProvideri  Nc                     Xl         g r6   r8   )rj   r9   s     r:   rl   CredentialProvider.__init__  s    r=   c                     g)a&  
Loads the credentials from their source & sets them on the object.

Subclasses should implement this method (by reading from disk, the
environment, the network or wherever), returning ``True`` if they were
found & loaded.

If not found, this method should return ``False``, indictating that the
``CredentialResolver`` should fall back to the next available method.

The default implementation does nothing, assuming the user has set the
``access_key/secret_key/token`` themselves.

:returns: Whether credentials were found & set
:rtype: Credentials
Tr   ry   s    r:   loadCredentialProvider.load  s    " r=   c                     / nU H  n UR                  X   5        M     U$ ! [         a    [        U R                  US9ef = f)Nr3  cred_var)appendKeyErrorr   METHOD)rj   mapping	key_namesfoundkey_names        r:   _extract_creds_from_mapping.CredentialProvider._extract_creds_from_mapping  sS    !HW./ " 	  -![[8 s	   "Ar8   r6   )
r   r   r   r   r  CANONICAL_NAMErl   r  r  r   r   r=   r:   r  r    s    F N&	r=   r  c                   T    \ rS rSrSr\R                  4S jrS rS r	\
S 5       rSrg)	r|   i  zcustom-processc                 6    Xl         X l        S U l        X0l        g r6   )_profile_name_load_config_loaded_config_popen)rj   r@   r>   popens       r:   rl   ProcessProvider.__init__  s    )'"r=   c                   ^ ^ T R                   mTc  g T R                  T5      nUR                  S5      b&  [        R	                  UUU 4S jT R
                  5      $ [        US   US   UR                  S5      T R
                  S9$ )Nr   c                  &   > TR                  T 5      $ r6   )_retrieve_credentials_using)credential_processrj   s   r:   r;   &ProcessProvider.load.<locals>.<lambda>  s    889KLr=   r!   r"   r#   )r!   r"   r#   r   )_credential_processr  rI   r   r   r  r   )rj   
creds_dictr  s   ` @r:   r  ProcessProvider.load  s    !55%556HI
>>-(4)>>L  !,/!,/..);;	
 	
r=   c                 v   [        U5      nU R                  U[        R                  [        R                  S9nUR	                  5       u  pEUR
                  S:w  a#  [        U R                  UR                  S5      S9e[        R                  R                  R                  UR                  S5      5      nUR                  SS5      nUS:w  a  [        U R                  SU S	3S9e US
   US   UR                  S5      UR                  S5      S.$ ! [         a  n[        U R                  SU 3S9eS nAff = f)N)stdoutstderrr   r  r2  Versionz<Version key not provided>   zUnsupported version 'z8' for credential process provider, supported versions: 1r   r   r   r   r   z"Missing required key in response: )r   r  
subprocessPIPEcommunicate
returncoder   r  decoder   r   r  r  rI   r  )	rj   r  process_listpr  r  parsedversiones	            r:   r  +ProcessProvider._retrieve_credentials_using  s5    **<=KK  
 <<1*g0F  %%++FMM',BC**Y(DEa<*+G9 56 7 	$]3$%67N3%zz,7	   	*>qcB 	s   '*D 
D8D33D8c                     U R                   c  U R                  5       U l         U R                   R                  S0 5      R                  U R                  0 5      nUR                  S5      $ )Nprofilesr  )r  r  rI   r  )rj   profile_configs     r:   r  #ProcessProvider._credential_process  sa    &"&"3"3"5D,,00R@DD
 !!"677r=   )r  r  r  r  N)r   r   r   r   r  r  Popenrl   r  r  r@  r  r   r   r=   r:   r|   r|     s4    F8B8H8H 
(!F 8 8r=   r|   c                   (    \ rS rSrSrSrS rS rSrg)rM   i$  ziam-roleEc2InstanceMetadatac                     Xl         g r6   _role_fetcher)rj   r2   s     r:   rl   !InstanceMetadataProvider.__init__(  s    -r=   c                     U R                   nUR                  5       nU(       d  g [        R                  SUS   5        [        R                  UU R                  UR                  S9nU$ )Nz#Found credentials from IAM Role: %s	role_namer   r   )r  retrieve_iam_role_credentialsrU   infor   r   r  )rj   fetcherr   rn  s       r:   r  InstanceMetadataProvider.load+  sj    $$ 88:18K3H	
 ';;;;!?? < 

 r=   r  N)	r   r   r   r   r  r  rl   r  r   r   r=   r:   rM   rM   $  s    F*N.r=   rM   c                   L    \ rS rSrSrSrSrSrSS/rSr	SS
 jr
S rS rS rSrg	)rK   iA  envEnvironmentAWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_SECURITY_TOKENAWS_SESSION_TOKENAWS_CREDENTIAL_EXPIRATIONNc                 b    Uc  [         R                  nXl        U R                  U5      U l        g)aq  

:param environ: The environment variables (defaults to
    ``os.environ`` if no value is provided).
:param mapping: An optional mapping of variable names to
    environment variable names.  Use this if you want to
    change the mapping of access_key->AWS_ACCESS_KEY_ID, etc.
    The dict can have up to 3 keys: ``access_key``, ``secret_key``,
    ``session_token``.
N)r_  environ_build_mapping_mapping)rj   r  r  s      r:   rl   EnvProvider.__init__K  s)     ?jjG++G4r=   c                    0 nUc>  U R                   US'   U R                  US'   U R                  US'   U R                  US'   U$ UR	                  SU R                   5      US'   UR	                  SU R                  5      US'   UR	                  SU R                  5      US'   [        US   [        5      (       d	  US   /US'   UR	                  SU R                  5      US'   U$ )Nr!   r"   r#   r   )
ACCESS_KEY
SECRET_KEYTOKENSEXPIRY_TIMErI   r   list)rj   r  var_mappings      r:   r  EnvProvider._build_mapping[  s    ?(,K%(,K%#';;K )-)9)9K&  )0doo)K% )0doo)K% $+;;w#DK k'2D99(3G(<'=G$)0t//*K& r=   c           	      `   U R                   R                  U R                  S   S5      nU(       a~  [        R	                  S5        U R                  5       nU" SS9nUS   nUb,  [        U5      n[        US   US   US	   UUU R                  S
9$ [        US   US   US	   U R                  S9$ g)z;
Search for credentials in explicit environment variables.
r!    z+Found credentials in environment variables.F)require_expiryr   Nr"   r#   )r   r   r   )
r  rI   r  rU   r  _create_credentials_fetcherr   r   r  r   )rj   r!   r  r   r   s        r:   r  EnvProvider.loads  s    
 \\%%dmmL&A2F
KKEF668G!7K%m4K&#K0---(");;  L)L)G${{	  r=   c                 h   ^^^ U R                   mU R                  mU R                  mSUUU4S jjnU$ )Nc                   > 0 nTR                  TS   S5      nU(       d  [        T	TS   S9eX!S'   TR                  TS   S5      nU(       d  [        T	TS   S9eX1S'   S US'   TS    H"  nTR                  US5      nU(       d  M  XQS'     O   S US'   TR                  TS   S5      nU(       a  XaS'   U (       a  U(       d  [        T	TS   S9eU$ )Nr!   r%  r  r"   r#   r   )rI   r   )
r&  r   r!   r"   token_env_varr#   r   r  r  r   s
          r:   ri  BEnvProvider._create_credentials_fetcher.<locals>.fetch_credentials  s   K W\%:B?J-#gl.C  )3% W\%:B?J-#gl.C  )3%#'K !(!1M265+0(	 "2 *.K&!++gm&<bAK-8M*k-#gm.D  r=   )T)r  r  r  )rj   ri  r  r  r   s     @@@r:   r(  'EnvProvider._create_credentials_fetcher  s1    --,,!	 !	F ! r=   )r  r  r   )r   r   r   r   r  r  r  r  r  r   rl   r  r  r(  r   r   r=   r:   rK   rK   A  s=    F"N$J(J #$78F-K5 0B(!r=   rK   c                   8    \ rS rSrSrSrSrSrSrSS jr	S	 r
S
rg)rR   i  zec2-credentials-file	Ec2ConfigAWS_CREDENTIAL_FILEAWSAccessKeyIdAWSSecretKeyNc                 T    Uc  [         R                  nUc  [        nXl        X l        g r6   )r_  r  r   _environ_parser)rj   r  parsers      r:   rl   OriginalEC2Provider.__init__  s$    ?jjG>'Fr=   c                 J   SU R                   ;   a  [        R                  R                  U R                   S   5      nU R	                  U5      nU R
                  U;   aE  [        R                  S5        X R
                     nX R                     n[        X4U R                  S9$ gg)z>
Search for a credential file used by original EC2 CLI tools.
r1  z)Found credentials in AWS_CREDENTIAL_FILE.r'  N)r5  r_  path
expanduserr6  r  rU   r  r  r   r  )rj   	full_pathrn  r!   r"   s        r:   r  OriginalEC2Provider.load  s     !DMM1**34I LL+E%'GH"??3
"??3
":$++NN ( r=   )r5  r6  r   )r   r   r   r   r  r  CRED_FILE_ENVr  r  rl   r  r   r   r=   r:   rR   rR     s%    #F N)M!JJr=   rR   c                   B    \ rS rSrSrSrSrSrSS/rSS	 jr	S
 r
S rSrg)r   i  zshared-credentials-fileSharedCredentialsr  r  aws_security_tokenr  Nc                 l    Xl         Uc  SnX l        Uc  [        R                  R                  nX0l        g )Nr'   )_creds_filenamer  r   configloaderraw_config_parse_ini_parser)rj   r   r@   
ini_parsers       r:   rl   !SharedCredentialProvider.__init__  s6    -$L)!..??J%r=   c                     U R                  U R                  5      nU R                  U;   a  XR                     nU R                  U;   am  [
        R                  SU R                  5        U R                  X R                  U R                  5      u  p4U R                  U5      n[        X4XPR                  S9$ g g ! [         a     g f = f)Nz0Found credentials in shared credentials file: %sr'  )rF  rC  r   r  r  rU   r  r  r  _get_session_tokenr   r  )rj   available_credsr1   r!   r"   r#   s         r:   r  SharedCredentialProvider.load  s    	"..t/C/CDO 0$%7%78F&(F(( *.)I)IOOT__*&
 //7"E++  ) 1  		s   B: :
CCc                 @    U R                    H  nX!;   d  M
  X   s  $    g r6   r  )rj   r1   token_envvars      r:   rJ  +SharedCredentialProvider._get_session_token
  s     KKL%++ (r=   )rC  rF  r  r   )r   r   r   r   r  r  r  r  r  rl   r  rJ  r   r   r=   r:   r   r     s2    &F(N$J(J #$78F&(,r=   r   c                   F    \ rS rSrSrSrSrSrSrSS/r	SS
 jr
S rS rSrg	)r   i  z0INI based config provider with profile sections.zconfig-fileSharedConfigr  r  rA  r  Nc                 b    Xl         X l        Uc  [        R                  R                  nX0l        g)z

:param config_filename: The session configuration scoped to the current
    profile.  This is available via ``session.config``.
:param profile_name: The name of the current profile.
:param config_parser: A config parser callable.

N)_config_filenamer  r   rD  r>   _config_parser)rj   r   r@   config_parsers       r:   rl   ConfigProvider.__init__  s-     !0) $11==M+r=   c                     U R                  U R                  5      nU R                  US   ;   a  US   U R                     nU R                  U;   am  [
        R                  SU R                  5        U R                  X R                  U R                  5      u  p4U R                  U5      n[        X4XPR                  S9$ gg! [         a     gf = f)zZ
If there is are credentials in the configuration associated with
the session, use those.
Nr  z$Credentials found in config file: %sr'  )rU  rT  r   r  r  rU   r  r  r  rJ  r   r  )rj   r7   r  r!   r"   r#   s         r:   r  ConfigProvider.load,  s    
	--d.C.CDK Z!88(4T5G5GHN.0:)) *.)I)I"OOT__*&
 //?"E++  1 #  		s   C 
CCc                 @    U R                    H  nX!;   d  M
  X   s  $    g r6   rN  )rj   r  
token_names      r:   rJ  !ConfigProvider._get_session_tokenF  s    ++J+%11 &r=   )rT  rU  r  r6   )r   r   r   r   r   r  r  r  r  r  rl   r  rJ  r   r   r=   r:   r   r     s5    :F#N$J(J #$78F,42r=   r   c                   @    \ rS rSrSrSrSrSS/rSrSr	SS
 jr
S rSrg	)rS   iL  zboto-configBoto2ConfigBOTO_CONFIGz/etc/boto.cfgz~/.botor  r  Nc                 |    Uc  [         R                  nUc  [        R                  R                  nXl        X l        g r6   )r_  r  r   rD  rE  r5  rF  )rj   r  rG  s      r:   rl   BotoProvider.__init__U  s2    ?jjG!..??J%r=   c                    U R                   U R                  ;   a  U R                  U R                      /nOU R                  nU H  n U R                  U5      nSU;   d  M  US   nU R
                  U;   d  M4  [        R                  SU5        U R                  X@R
                  U R                  5      u  pV[        XVU R                  S9s  $    g! [         a     M  f = f)z+
Look for credentials in boto config file.
r   z)Found credentials in boto config file: %sr'  N)BOTO_CONFIG_ENVr5  DEFAULT_CONFIG_FILENAMESrF  r   r  rU   r  r  r  r   r  )rj   potential_locationsra  r1   r   r!   r"   s          r:   r  BotoProvider.load]  s     4==0#'==1E1E#F"G"&"?"?+H))(3 &$]3??k1KKCX .2-M-M#__doo.*J '"t{{  , " s   C
CC)r5  rF  r   )r   r   r   r   r  r  rc  rd  r  r  rl   r  r   r   r=   r:   rS   rS   L  s0    F"N#O /;$J(J&r=   rS   c                       \ rS rSrSrSrSrSrSr\	R                  SS4S jr
S rS	 rS
 rS rS rS rS rS rS rS rS rS rSrg)rO   iy  assume-roleNr  web_identity_token_filer$   c                     X0l         Xl        X l        X@l        XPl        0 U l        X`l        Xpl        U R                  /U l        g)a  
:type load_config: callable
:param load_config: A function that accepts no arguments, and
    when called, will return the full configuration dictionary
    for the session (``session.full_config``).

:type client_creator: callable
:param client_creator: A factory function that will create
    a client when called.  Has the same interface as
    ``botocore.session.Session.create_client``.

:type cache: dict
:param cache: An object that supports ``__getitem__``,
    ``__setitem__``, and ``__contains__``.  An example
    of this is the ``JSONFileCache`` class in the CLI.

:type profile_name: str
:param profile_name: The name of the profile.

:type prompter: callable
:param prompter: A callable that returns input provided
    by the user (i.e raw_input, getpass.getpass, etc.).

:type credential_sourcer: CanonicalNameCredentialSourcer
:param credential_sourcer: A credential provider that takes a
    configuration, which is used to provide the source credentials
    for the STS call.
N)	r3   r  r~  r  	_prompterr  _credential_sourcer_profile_provider_builder_visited_profiles)rj   r>   r?   r3   r@   prompterrA   rB   s           r:   rl   AssumeRoleProvider.__init__  sJ    V 
'  .)! !#5 )A&"&"4"4!5r=   c                     U R                  5       U l        U R                  R                  S0 5      nUR                  U R                  0 5      nU R	                  U5      (       a  U R                  U R                  5      $ g Nr  )r  r  rI   r  _has_assume_role_config_vars_load_creds_via_assume_role)rj   r  r&   s      r:   r  AssumeRoleProvider.load  sn    "//1&&**:r:,,t1126,,W5533D4F4FGG 6r=   c                 L    U R                   U;   =(       a    U R                  U;  $ r6   )ROLE_CONFIG_VARWEB_IDENTITY_TOKE_FILE_VARrj   r&   s     r:   rs  /AssumeRoleProvider._has_assume_role_config_vars  s*      G+ ; ++7:	
r=   c           	         U R                  U5      nU R                  X!5      n0 nUR                  S5      nUb  XTS'   UR                  S5      nUb  XdS'   UR                  S5      nUb  XtS'   UR                  S5      nUb  XS'   [        U R                  UUS	   UU R
                  U R                  S
9n	U	R                  n
Ub  [        U
5      n
[        U R                  U
[        S9$ )Nrole_session_namer}  external_id
ExternalIdr  r  r  r  r  )r?   r  r  r  r  r3   )r   r   r   )_get_role_config_resolve_source_credentialsrI   r  r~  rk  r3   ri  r   rD  r  r   )rj   r@   role_configr  r  r|  r}  r  r  r  	refreshers              r:   rt  .AssumeRoleProvider._load_creds_via_assume_role  s   ++L9!==
 
'OO,?@(,=()!oom4"'2|$ __\2
!)3~&&??+=>',<()-//1 ,!**
 --	!3I>I
 .;;##
 	
r=   c                    U R                   R                  S0 5      nX!   nUR                  S5      nUS   nUR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      n	UR                  S5      n
UUUU	UUS	.nU
b   [        U
5      US'   Ub  Ub  [	        S
U S3S9eUc  Uc  [        U R                  SS9eUb  U R                  X5        U$ U R                  X5        U$ ! [         a     Nbf = f)z?Retrieves and validates the role configuration for the profile.r  source_profiler  credential_sourcer  r}  r|  r  )r  r}  r  r|  r  r  The profile "z5" contains both source_profile and credential_source.r4  z#source_profile or credential_sourcer  )	r  rI   r  
ValueErrorr   r   r  _validate_credential_source_validate_source_profile)rj   r@   r  r&   r  r  r  r  r}  r|  r  r  s               r:   r  #AssumeRoleProvider._get_role_config  sW   &&**:r:( %56:&#KK(;<[[.
kk-0#KK(;<";;'9: !&$!2,!2
 '256F2G./ (^-G$#L> 2< <  &>+A)>  *,,\M  )),G-  s   C= =
D
	D
c                     U R                   c  [        SU SU S3S9eU R                   R                  U5      (       d  [        SU SU S3S9eg )NzThe credential_source "z" is specified in profile "z)", but no source provider was configured.r  zThe credential source "z" referenced in profile "z" is not valid.)rl  r   is_supported)rj   parent_profiler  s      r:   r  .AssumeRoleProvider._validate_credential_source5  s    ##+$./@.A B$$2#3 4=>  ''445FGG$./@.A B$$2#33CE  Hr=   c                 X    [        U R                  U5      U R                  U5      /5      $ r6   )any_has_static_credentialsrs  ry  s     r:   _source_profile_has_credentials2AssumeRoleProvider._source_profile_has_credentialsF  s0    ,,W511':
 	
r=   c                    U R                   R                  S0 5      nX#;  a  [        SU SU S3S9eX2   nX R                  ;  a  g X!:w  a  [	        UU R                  S9eU R                  U5      (       d  [	        UU R                  S9eg )Nr  zThe source_profile "z" referenced in the profile "z" does not exist.r  )r  visited_profiles)r  rI   r   rn  r   r  )rj   parent_profile_namesource_profile_namer  r  s        r:   r  +AssumeRoleProvider._validate_source_profileN  s     &&**:r:.$+,?+@ A%%8$99KM  "6 &<&<< 5)2!%!7!7  ++N;;)2!%!7!7  <r=   c                 6   ^ SS/n[        U4S jU 5       5      $ )Nr  r  c              3   *   >#    U H	  oT;   v   M     g 7fr6   r   ).0
static_keyr&   s     r:   	<genexpr>=AssumeRoleProvider._has_static_credentials.<locals>.<genexpr>v  s     G;Z(;   )r  )rj   r&   static_keyss    ` r:   r  *AssumeRoleProvider._has_static_credentialst  s    .0CDG;GGGr=   c                     UR                  S5      nUb  U R                  X25      $ US   nU R                  R                  U5        U R	                  U5      $ )Nr  r  )rI    _resolve_credentials_from_sourcern  r  !_resolve_credentials_from_profile)rj   r  r@   r  r  s        r:   r  .AssumeRoleProvider._resolve_source_credentialsx  s`    'OO,?@(88!  %%56%%n555nEEr=   c                    U R                   R                  S0 5      nX!   nU R                  U5      (       a"  U R                  (       d  U R	                  U5      $ U R                  U5      (       d  U R                  U5      (       dG  U R                  R                  USS9n[        U5      nUR                  5       nUc  Sn[        Xq-  S9eU$ U R                  U5      $ )Nr  TrC   z.The source profile "%s" must have credentials.r  )r  rI   r  rm  (_resolve_static_credentials_from_profilers  rF   rW   r   r   rt  )rj   r@   r  r&   r_   profile_chainr   error_messages           r:   r  4AssumeRoleProvider._resolve_credentials_from_profile  s    &&**:r:( ((1122 @@II))
 
227;; $ > > H H)!% !I ! //@AM'88:K"D  )+:  //==r=   c                      [        US   US   UR                  S5      S9$ ! [         a"  n[        U R                  [        U5      S9eS nAff = f)Nr  r  r  r    r  )r   rI   r  r   r  str)rj   r&   r  s      r:   r  ;AssumeRoleProvider._resolve_static_credentials_from_profile  s_    		"#67"#:;kk"56 
  	)s1v 	s   " 
AA		Ac                 \    U R                   R                  U5      nUc  [        USU 3S9eU$ )Nz@No credentials found in credential_source referenced in profile r2  )rl  r  r   )rj   r  r@   r   s       r:   r  3AssumeRoleProvider._resolve_credentials_from_source  sL     ..AA
 **"".1  r=   )	r~  rl  r  r  r  rm  rk  rn  r3   )r   r   r   r   r  r  rw  rx  EXPIRY_WINDOW_SECONDSr  rl   r  rs  rt  r  r  r  r  r  r  r  r  r  r   r   r=   r:   rO   rO   y  sy    F N O!: $ !%<6|H	
*
X/b"
$LH	F>B
r=   rO   c                   V    \ rS rSrSrSrSSSS.r   SS jrS	 rS
 r	S r
S rS rSrg)r   i  zassume-role-with-web-identityNAWS_WEB_IDENTITY_TOKEN_FILEAWS_ROLE_SESSION_NAMEAWS_ROLE_ARN)ri  r|  r  c                 l    X@l         Xl        X l        X0l        S U l        XPl        Uc  [        nX`l        g r6   )r3   r  r~  r  _profile_config_disable_env_varsr   _token_loader_cls)rj   r>   r?   r@   r3   rD   token_loader_clss          r:   rl   *AssumeRoleWithWebIdentityProvider.__init__  s;     
'-)#!1#9!1r=   c                 "    U R                  5       $ r6   )_assume_role_with_web_identityry   s    r:   r  &AssumeRoleWithWebIdentityProvider.load  s    2244r=   c                     U R                   cC  U R                  5       nUR                  S0 5      nUR                  U R                  0 5      U l         U R                   R                  U5      $ rr  )r  r  rI   r  )rj   keyloaded_configr  s       r:   _get_profile_config5AssumeRoleWithWebIdentityProvider._get_profile_config  s^    ' --/M$((R8H#+<<0B0BB#GD ##'',,r=   c                     U R                   (       a  g U R                  R                  U5      nU(       a'  U[        R                  ;   a  [        R                  U   $ g r6   )r  _CONFIG_TO_ENV_VARrI   r_  r  )rj   r  env_keys      r:   _get_env_config1AssumeRoleWithWebIdentityProvider._get_env_config  sD    !!))--c2w"**,::g&&r=   c                 P    U R                  U5      nUb  U$ U R                  U5      $ r6   )r  r  )rj   r  	env_values      r:   _get_config-AssumeRoleWithWebIdentityProvider._get_config  s/    ((-	 '',,r=   c                 N   U R                  S5      nU(       d  g U R                  U5      nU R                  S5      nU(       d  Sn[        US9e0 nU R                  S5      nUb  XeS'   [        U R                  UUUU R
                  S9n[        U R                  UR                  S9$ )	Nri  r  zThe provided profile or the current environment is configured to assume role with web identity but has no role ARN configured. Ensure that the profile has the role_arnconfiguration set or the AWS_ROLE_ARN env var is set.r  r|  r}  )r?   r  r  r  r3   r
  )	r  r  r   r  r~  r3   rD  r  ri  )rj   
token_pathtoken_loaderr  r4  r  r|  r  s           r:   r  @AssumeRoleWithWebIdentityProvider._assume_role_with_web_identity  s    %%&?@
--j9##J/H  %y99
 ,,-@A(,=()<//&2!**
 .;;!33
 	
r=   )r~  r  r  r  r  r  r3   )NFN)r   r   r   r   r  r  r  rl   r  r  r  r  r  r   r   r=   r:   r   r     sF    ,FN#@4" 2&5--"
r=   r   c                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)
rQ   i  c                     Xl         g r6   
_providersrj   rF   s     r:   rl   'CanonicalNameCredentialSourcer.__init__  s    #r=   c                 Z    XR                    Vs/ sH  o"R                  PM     sn;   $ s  snf )a  Validates a given source name.

:type source_name: str
:param source_name: The value of credential_source in the config
    file. This is the canonical name of the credential provider.

:rtype: bool
:returns: True if the credential provider is supported,
    False otherwise.
)r  r  )rj   source_namer  s      r:   r  +CanonicalNameCredentialSourcer.is_supported  s'     IA//IIIIs   (c                     U R                  U5      n[        U[        5      (       a  UR                  5       $ UR	                  5       $ )zLoads source credentials based on the provided configuration.

:type source_name: str
:param source_name: The value of credential_source in the config
    file. This is the canonical name of the credential provider.

:rtype: Credentials
)_get_providerr   rW   r   r  )rj   r  sources      r:   r  1CanonicalNameCredentialSourcer.source_credentials+  s=     ##K0f011**,,{{}r=   c                     U R                  U5      nUR                  5       S;   a%  U R                  S5      nUb  Uc  U$ [        X2/5      $ Uc	  [	        US9eU$ )zReturn a credential provider by its canonical name.

:type canonical_name: str
:param canonical_name: The canonical name of the provider.

:raises UnknownCredentialError: Raised if no
    credential provider by the provided name
    is found.
)sharedconfigsharedcredentialsrh  name)_get_provider_by_canonical_namelower_get_provider_by_methodrW   r   )rj   canonical_namer3  r]   s       r:   r  ,CanonicalNameCredentialSourcer._get_provider9  st     77G !%JJ#'#?#?#N #/
 #//
 *+?*JKK(n==r=   c                     U R                    H>  nUR                  nU(       d  M  UR                  5       UR                  5       :X  d  M<  Us  $    g)zReturn a credential provider by its canonical name.

This function is strict, it does not attempt to address
compatibility issues.
N)r  r  r  )rj   r  r3  r  s       r:   r  >CanonicalNameCredentialSourcer._get_provider_by_canonical_name_  s=     H**Dt

(<(<(>>	 (r=   c                 R    U R                    H  nUR                  U:X  d  M  Us  $    g)z0Return a credential provider by its METHOD name.N)r  r  )rj   r   r3  s      r:   r  6CanonicalNameCredentialSourcer._get_provider_by_methodk  s!    H&( (r=   r  N)r   r   r   r   rl   r  r  r  r  r  r   r   r=   r:   rQ   rQ     s"    $J$L
  r=   rQ   c                   Z    \ rS rSrSrSrSrSrSrSr	SS	 jr
S
 rS rS rS rS rS rSrg)rL   ir  zcontainer-roleEcsContainer&AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"AWS_CONTAINER_CREDENTIALS_FULL_URI!AWS_CONTAINER_AUTHORIZATION_TOKEN&AWS_CONTAINER_AUTHORIZATION_TOKEN_FILENc                 \    Uc  [         R                  nUc
  [        5       nXl        X l        g r6   )r_  r  r   r5  _fetcher)rj   r  r  s      r:   rl   ContainerProvider.__init__z  s'    ?jjG?.0Gr=   c                     U R                   U R                  ;   d  U R                  U R                  ;   a  U R                  5       $ g r6   )ENV_VARr5  ENV_VAR_FULL_retrieve_or_failry   s    r:   r  ContainerProvider.load  s:     <<4==(D,=,=,N))++ -Or=   c           
      N   U R                  5       (       a3  U R                  R                  U R                  U R                     5      nOU R                  U R
                     nU R                  U5      nU" 5       n[        US   US   US   U R                  [        US   5      US9$ )Nr!   r"   r#   r   )r!   r"   r#   r   r   r   )
_provided_relative_urir  full_urlr5  r  r  _create_fetcherr   r  r   )rj   full_urir  rn  s       r:   r  #ContainerProvider._retrieve_or_fail  s    &&((}}--dmmDLL.IJH}}T%6%67H&&x0	%\*\*.;;(})=>!
 	
r=   c                 p   S nU R                   U R                  ;   a>  U R                  U R                      n[        U5       nUR                  5       nS S S 5        O3U R                  U R                  ;   a  U R                  U R                     nUb  U R                  U5        SU0$ g ! , (       d  f       N'= f)NAuthorization)ENV_VAR_AUTH_TOKEN_FILEr5  openreadENV_VAR_AUTH_TOKEN_validate_auth_token)rj   
auth_tokenauth_token_file_path
token_files       r:   _build_headers ContainerProvider._build_headers  s    
''4==8#'==1M1M#N *+z'__.
 ,+$$5t'>'>?J!%%j1#Z00 "	 ,+s   B''
B5c                 2    SU;   d  SU;   a  [        S5      eg )N
z,Auth token value is not a legal header value)r  )rj   r  s     r:   r  &ContainerProvider._validate_auth_token  s"    :!3KLL "4r=   c                    ^ ^ UU 4S jnU$ )Nc                    >  TR                  5       n TR                  R                  TU S9nUS   US   US   US	   S
.$ ! [         a7  n[        R                  SUSS9  [        TR                  [        U5      S9eS nAff = f)N)headersz'Error retrieving container metadata: %sTr$  r2  r   r   Tokenr   r   )	r  r  retrieve_full_urir   rU   rV   r   r  r  )r  r   r  r  rj   s      r:   fetch_creds6ContainerProvider._create_fetcher.<locals>.fetch_creds  s    --/==::g ;  '}5&'89!'*'5	  * =q4   /![[CF 	s   *A   
B
2A<<Br   )rj   r  r  r   r  s   ``   r:   r  !ContainerProvider._create_fetcher  s    	( r=   c                 4    U R                   U R                  ;   $ r6   )r  r5  ry   s    r:   r  (ContainerProvider._provided_relative_uri  s    ||t}},,r=   )r5  r  r   )r   r   r   r   r  r  r  r  r  r  rl   r  r  r  r  r  r  r   r   r=   r:   rL   rL   r  sF    F#N6G7L<F ,
 
1M.-r=   rL   c                   >    \ rS rSrS rS rS rS rS rS r	S r
S	rg
)rW   i  c                     Xl         g)zA

:param providers: A list of ``CredentialProvider`` instances.

NrE   r  s     r:   rl   CredentialResolver.__init__  s	     #r=   c                      U R                    Vs/ sH  o3R                  PM     snR                  U5      nU R                   R                  XB5        gs  snf ! [         a
    [	        US9ef = f)a  
Inserts a new instance of ``CredentialProvider`` into the chain that
will be tried before an existing one.

:param name: The short name of the credentials you'd like to insert the
    new credentials before. (ex. ``env`` or ``config``). Existing names
    & ordering can be discovered via ``self.available_methods``.
:type name: string

:param cred_instance: An instance of the new ``Credentials`` object
    you'd like to add to the chain.
:type cred_instance: A subclass of ``Credentials``
r  N)rF   r  indexr  r   insert)rj   r  credential_providerr  offsets        r:   insert_before CredentialResolver.insert_before  s_    	4(,71hh7==dCF 	f: 8 	4(d33	4s   A AA A A+c                 d    U R                  U5      nU R                  R                  US-   U5        g)a  
Inserts a new type of ``Credentials`` instance into the chain that will
be tried after an existing one.

:param name: The short name of the credentials you'd like to insert the
    new credentials after. (ex. ``env`` or ``config``). Existing names
    & ordering can be discovered via ``self.available_methods``.
:type name: string

:param cred_instance: An instance of the new ``Credentials`` object
    you'd like to add to the chain.
:type cred_instance: A subclass of ``Credentials``
r  N)_get_provider_offsetrF   r   )rj   r  r!  r"  s       r:   insert_afterCredentialResolver.insert_after  s-     **40fqj*=>r=   c                     U R                    Vs/ sH  o"R                  PM     nnX;  a  gUR                  U5      nU R                   R                  U5        gs  snf )z
Removes a given ``Credentials`` instance from the chain.

:param name: The short name of the credentials instance to remove.
:type name: string
N)rF   r  r  pop)rj   r  r  available_methodsr"  s        r:   rT   CredentialResolver.remove  sO     04~~>~!XX~>("((.6" ?s   Ac                 >    U R                   U R                  U5         $ )zReturn a credential provider by name.

:type name: str
:param name: The name of the provider.

:raises UnknownCredentialError: Raised if no
    credential provider by the provided name
    is found.
)rF   r&  )rj   r  s     r:   get_providerCredentialResolver.get_provider   s     ~~d77=>>r=   c                      U R                    Vs/ sH  o"R                  PM     snR                  U5      $ s  snf ! [         a
    [	        US9ef = f)Nr  )rF   r  r  r  r   )rj   r  r  s      r:   r&  'CredentialResolver._get_provider_offset  sJ    	4&*nn5nHHn5;;DAA5 	4(d33	4s   ; 6; ; Ac                     U R                    H:  n[        R                  SUR                  5        UR	                  5       nUc  M8  Us  $    g)z_
Goes through the credentials chain, returning the first ``Credentials``
that could be loaded.
zLooking for credentials via: %sN)rF   rU   rV   r  r  )rj   r3  rn  s      r:   r   #CredentialResolver.load_credentials  s@     HLL:HOOLMMOE 	 ' r=   rE   N)r   r   r   r   rl   r#  r'  rT   r.  r&  r   r   r   r=   r:   rW   rW     s%    #;(?"#
?4r=   rW   c                   L   ^  \ rS rSrSr     SU 4S jjrS rS rS rSr	U =r
$ )	SSOCredentialFetcheri'  z%Y-%m-%dT%H:%M:%SZc                    > XPl         X l        X0l        X@l        Xl        X`l        Xl        Xl        [        TU ]%  Xx5        g r6   )
r~  _sso_region
_role_name_account_id
_start_url_token_loader_token_provider_sso_session_namerH  rl   )rj   	start_url
sso_regionr	  
account_idr?   r  r3   rT  r   sso_session_namerI  s              r:   rl   SSOCredentialFetcher.__init__*  s@      .%#%#)-!16r=   c                 2   U R                   U R                  S.nU R                  (       a  U R                  US'   OU R                  US'   [        R
                  " USSS9n[        UR                  S5      5      R                  5       nU R                  U5      $ )r  )roleName	accountIdsessionNamestartUrlT),r[  )r  
separatorsr  )
r8  r9  r=  r:  r  r  r   r  r  rb  r  s      r:   rP  &SSOCredentialFetcher._create_cache_keyA  s     ))
 !!"&"8"8D#D zz$$:FT[[12<<>##M22r=   c                     US-  n[         R                   R                  U[        5       5      nUR                  U R                  5      $ )Ng     @@)r   fromtimestampr	   r   _UTC_DATE_FORMAT)rj   timestamp_mstimestamp_seconds	timestamps       r:   _parse_timestamp%SSOCredentialFetcher._parse_timestampW  s?    (61%%334EuwO	!!$"7"788r=   c                    [        [        U R                  S9nU R                  SUS9nU R                  (       a5  U R                  R                  5       nUR                  5       R                  nOU R                  U R                  5      S   nU R                  U R                  US.n UR                  " S0 UD6nUS   nSUS   US   US	   U R!                  US
   5      S.S.nU$ ! UR                  R                   a    [        5       ef = f)z4Get credentials by calling SSO get role credentials.)r  r4   ssor  accessToken)rD  rE  rU  roleCredentialsaccessKeyIdsecretAccessKeysessionTokenro  )r   r   r   r   )ProviderTyper   r   )r   r
   r7  r~  r<  
load_tokenget_frozen_tokenr#   r;  r:  r8  r9  get_role_credentials
exceptionsUnauthorizedExceptionr   rQ  )rj   r1   r   initial_token_datar#   r   r   r   s           r:   re  %SSOCredentialFetcher._get_credentials]  s&   &((
 %%eF%;!%!5!5!@!@!B&779??E&&t7FE )) 

	.22<V<H 01 "*=9#./@#A +N ;"33K4MN	
    66 	.+--	.s   (C& &%D)r9  r~  r8  r7  r=  r:  r;  r<  )NNNNN)r   r   r   r   rM  rl   rP  rQ  re  r   rK  rL  s   @r:   r5  r5  '  s3    + "7.3,9! !r=   r5  c                       \ rS rSrSr\R                  R                  \R                  R                  SSSS5      5      r	Sr
Sr\
\-   r   SS	 jrS
 rS rS rSrg)r   i  rT  ~z.awsr3   )sso_role_namesso_account_id)sso_start_urlr?  Nc                     Uc  [        U R                  5      nXPl        X`l        Uc  0 nX@l        Xl        X l        X0l        g r6   )r   _SSO_TOKEN_CACHE_DIR_token_cacher<  r3   r  r~  r  )rj   r>   r?   r@   r3   r   r   s          r:   rl   SSOProvider.__init__  sG     '(A(ABK'-=E
'-)r=   c                   ^ U R                  5       nUR                  S0 5      nU R                  nUR                  U R                  0 5      mUR                  S0 5      n[        U4S jU R                   5       5      (       a  g U R                  TU5      u  pV0 n/ nU R                  U-   n	U	 H!  n
X;   a  XZ   Xz'   M  UR                  U
5        M#     U(       a   SR                  U5      n[        SU SU 3S9eU$ )Nr  sso_sessionsc              3   *   >#    U H	  oT;  v   M     g 7fr6   r   )r  cr  s     r:   r  /SSOProvider._load_sso_config.<locals>.<genexpr>  s      
-O^#-Or  r1  r  zB" is configured to use SSO but is missing required configuration: r  )
r  rI   r  all_PROFILE_REQUIRED_CONFIG_VARS_resolve_sso_session_reference_ALL_REQUIRED_CONFIG_VARSr  r5  r   )rj   r  r  r@   rl  resolved_config
extra_reqsr1   missing_config_varsall_required_configs
config_varmissingr  s               @r:   _load_sso_configSSOProvider._load_sso_config  s   ))+ $$Z4))!d&8&8"=$((<  
-1-O-O
 
 
 &*&I&IL'
#  #==
J.J,%4%@"#**:6	 / ii 34G$#L> 2>>EYH  r=   c                    UR                  S5      nUc  US4$ X2;  a  SU S3n[        US9eUR                  5       nX#   nUR                  5        H5  u  pxUR                  Xx5      U:w  a  SU SXW    SU S	3n[        US9eXU'   M7     US
4$ )Nsso_sessionr   z+The specified sso-session does not exist: ""r  zThe value for z" is inconsistent between profile (z) and sso-session (z).)r}  )rI   r   copyitems)	rj   r  rl  rA  r4  r1   r9   rx  vals	            r:   rr  *SSOProvider._resolve_sso_session_reference  s    )--m<#!2%%/EFVEWWXYI$y99$$&0&}}OJzz**c1$ZL 1  & 233Fse2O  )9==!$:  / '''r=   c           	      4   U R                  5       nU(       d  g US   US   US   US   U R                  [        U R                  S9U R                  S.nSU;   a  US   US'   U R
                  US	'   [        S0 UD6n[        U R                  UR                  S
9$ )Nrf  r?  rd  re  )r3   )r>  r?  r	  r@  r?   r  r3   r}  rA  r   r
  r   )
rz  r~  r   ri  r3   r<  r5  rD  r  ri  )rj   
sso_configfetcher_kwargssso_fetchers       r:   r  SSOProvider.load  s    **,
 $O4$\2#O4$%56"22*1B1BCZZ
 J&1;M1JN-./3/C/CN+,*<^<-;;%77
 	
r=   )r~  r  r  ri  r<  r3   r   )r   r   r   r   r  r_  r:  r;  r5  rh  rq  _SSO_REQUIRED_CONFIG_VARSrs  rl   rz  rr  r  r   r   r=   r:   r   r     sr    F77--
S&%1%!!
 	&(AA  *("H(.
r=   r   r   r   )Tr   r  r  loggingr_  r  r   r  collectionsr   r  r   hashlibr   dateutil.parserr   dateutil.tzr   r	   botocore.compatr   botocore.configloaderr
   r   r   botocore.configr   botocore.exceptionsr   r   r   r   r   r   r   r   r   botocore.tokensr   botocore.utilsr   r   r   r   r   r   r   	getLoggerr   rU   r   r>  rJ   rb   rN   r   r   r   r   rP   r   r   r   r   rD  rN  rz  r  r  r  r|   rM   rK   rR   r   r   rS   rO   r   rQ   rL   rW   r5  r   r   r=   r:   <module>r     s       	    "   ! &    = "
 
 
 -   
		8	$ @  &- "$+ !]@J
 J
Z'
, &$#
 #
Le([ e(P	2%; 2.B5 B5J23&= 23jW
"A W
t@"#@"F+ +\G8( G8T1 :{!$ {!| ,  F+,1 +,\92' 92x*% *ZE+ EP
V
(: V
rU  U pN-* N-ba aHW2 Wtx
$ x
r=   