HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/botocore/__pycache__/credentials.cpython-36.pyc
3

�T_�=�@sBddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZmZddlZddlZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddl%m&Z&m'Z'ddl%m(Z(ddl%m)Z)ddl%m*Z*ej+e,�Z-e	ddddg�Z.d]dd�Z/Gdd�de0�Z1d d!�Z2d"d#�Z3d$d%�Z4d^d'd(�Z5d)d*�Z6d+d,�Z7d-d.�Z8Gd/d0�d0e0�Z9Gd1d2�d2e0�Z:Gd3d4�d4e:�Z;Gd5d6�d6e;�Z<Gd7d8�d8e0�Z=Gd9d:�d:e=�Z>Gd;d<�d<e>�Z?Gd=d>�d>e>�Z@Gd?d@�d@e0�ZAGdAdB�dBeA�ZBGdCdD�dDeA�ZCGdEdF�dFeA�ZDGdGdH�dHeA�ZEGdIdJ�dJeA�ZFGdKdL�dLeA�ZGGdMdN�dNeA�ZHGdOdP�dPeA�ZIGdQdR�dReA�ZJGdSdT�dTe0�ZKGdUdV�dVeA�ZLGdWdX�dXe0�ZMGdYdZ�dZe=�ZNGd[d\�d\eA�ZOdS)_�N)�
namedtuple)�deepcopy)�sha1)�parse)�tzlocal�tzutc)�UNSIGNED)�
total_seconds)�compat_shell_split)�Config)�UnknownCredentialError)�PartialCredentialsError)�ConfigNotFound)�InvalidConfigError)�InfiniteLoopConfigError)�RefreshWithMFAUnsupportedError)�MetadataRetrievalError)�CredentialRetrievalError)�UnauthorizedSSOTokenError)�InstanceMetadataFetcher�parse_key_val_file)�ContainerMetadataFetcher)�FileWebIdentityTokenLoader)�SSOTokenLoader�ReadOnlyCredentials�
access_key�
secret_key�tokenc	s��jd�pd}�jd�}�jd�}�j�jd�dk	}|dkr@i}t�}t�}tt||�j�d�d�}	t�||d�}
t	�fd	d
�t
�|�||t|||	g�|
d�}||g}|
j||d�}
t
�t�||	g}||
|}|r�|j|�tjd
�t|d�}|S)z�Create a default credential resolver.

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

    �profile�defaultZmetadata_service_timeoutZmetadata_service_num_attemptsN)Ztimeout�num_attempts�
user_agent)�iam_role_fetcher)�cache�region_namecs�jS)N)�full_config�)�sessionr&�!/usr/lib/python3.6/credentials.py�<lambda>Ssz,create_credential_resolver.<locals>.<lambda>)�load_config�client_creatorr#�profile_name�credential_sourcer�profile_provider_builder)r,�disable_env_varszWSkipping environment variable credential check because profile name was explicitly set.)�	providers)�get_config_variableZinstance_variables�get�EnvProvider�ContainerProvider�InstanceMetadataProviderrr!�ProfileProviderBuilder�AssumeRoleProvider�_get_client_creator�CanonicalNameCredentialSourcerr0�OriginalEC2Provider�BotoProvider�remove�logger�debug�CredentialResolver)r'r#r$r,Zmetadata_timeoutr r/Zenv_providerZcontainer_providerZinstance_metadata_providerr.�assume_role_providerZpre_profile�profile_providersZpost_profiler0�resolverr&)r'r(�create_credential_resolver7sL






rCc@sLeZdZdZddd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dS)r6a�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.
    NcCs||_||_||_||_dS)N)�_session�_cache�_region_name�_sso_token_cache)�selfr'r#r$Zsso_token_cacher&r&r(�__init__�szProfileProviderBuilder.__init__FcCs.|j||�|j|�|j|�|j|�|j|�gS)N)�_create_web_identity_provider�_create_sso_provider�"_create_shared_credential_provider�_create_process_provider�_create_config_provider)rHr,r/r&r&r(r0�sz ProfileProviderBuilder.providerscst|�fdd�d�S)Ncs�jjS)N)rDr%r&)rHr&r(r)�szAProfileProviderBuilder._create_process_provider.<locals>.<lambda>)r,r*)�ProcessProvider)rHr,r&)rHr(rM�sz/ProfileProviderBuilder._create_process_providercCs|jjd�}t||d�S)NZcredentials_file)r,�creds_filename)rDr1�SharedCredentialProvider)rHr,Zcredential_filer&r&r(rL�sz9ProfileProviderBuilder._create_shared_credential_providercCs|jjd�}t||d�S)N�config_file)r,�config_filename)rDr1�ConfigProvider)rHr,rRr&r&r(rN�sz.ProfileProviderBuilder._create_config_providercs&t�fdd�t�j�j��j||d�S)Ncs�jjS)N)rDr%r&)rHr&r(r)�szFProfileProviderBuilder._create_web_identity_provider.<locals>.<lambda>)r*r+r#r,r/)�!AssumeRoleWithWebIdentityProviderr8rDrFrE)rHr,r/r&)rHr(rJ�s

z4ProfileProviderBuilder._create_web_identity_providercs"t�fdd��jj|�j�jd�S)Ncs�jjS)N)rDr%r&)rHr&r(r)�sz=ProfileProviderBuilder._create_sso_provider.<locals>.<lambda>)r*r+r,r#�token_cache)�SSOProviderrD�
create_clientrErG)rHr,r&)rHr(rK�s
z+ProfileProviderBuilder._create_sso_provider)NNN)F)�__name__�
__module__�__qualname__�__doc__rIr0rMrLrNrJrKr&r&r&r(r6�s	


r6cCst|�}|j�S)N)rC�load_credentials)r'rBr&r&r(�get_credentials�sr^cCstjjt��S)N)�datetimeZnowrr&r&r&r(�
_local_now�sr`cCst|tj�r|St|�S)N)�
isinstancer_r)�valuer&r&r(�_parse_if_needed�srcFcCs&t|tj�r"|r|j�S|jd�S|S)Nz%Y-%m-%dT%H:%M:%S%Z)rar_Z	isoformatZstrftime)rb�isor&r&r(�_serialize_if_needed�s

recs��fdd�}|S)Ncs"d�i}|jf|��j|f|�S)Nr$)�updaterX)Zservice_name�kwargsZcreate_client_kwargs)r$r'r&r(r+�sz+_get_client_creator.<locals>.client_creatorr&)r'r$r+r&)r$r'r(r8�sr8cs��fdd�}|S)Ncs6�jf��}|d}|d|d|dt|d�d�S)N�Credentials�AccessKeyId�SecretAccessKey�SessionToken�
Expiration)rrr�expiry_time)�assume_rolere)�response�credentials)�client�paramsr&r(�refresh�sz-create_assume_role_refresher.<locals>.refreshr&)rqrrrsr&)rqrrr(�create_assume_role_refresher�srtcCsGdd�dt�}||�S)Nc@seZdZdd�Zdd�ZdS)z/create_mfa_serial_refresher.<locals>._RefreshercSs||_d|_dS)NF)�_refresh�_has_been_called)rHrsr&r&r(rI�sz8create_mfa_serial_refresher.<locals>._Refresher.__init__cSs|jrt��d|_|j�S)NT)rvrru)rHr&r&r(�__call__sz8create_mfa_serial_refresher.<locals>._Refresher.__call__N)rYrZr[rIrwr&r&r&r(�
_Refresher�srx)�object)Zactual_refreshrxr&r&r(�create_mfa_serial_refresher�srzc@sVeZdZdZejjejjdddd��Zefdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dS)�
JSONFileCachez�JSON file cache.
    This provides a dict like interface that stores JSON serializable
    objects.
    The objects are serialized to JSON and stored in a file.  These
    values can be retrieved at a later time.
    �~z.awsZbotor#cCs
||_dS)N)�_working_dir)rHZworking_dirr&r&r(rIszJSONFileCache.__init__cCs|j|�}tjj|�S)N)�_convert_cache_key�os�path�isfile)rH�	cache_key�
actual_keyr&r&r(�__contains__s
zJSONFileCache.__contains__cCsP|j|�}yt|��}tj|�SQRXWn"tttfk
rJt|��YnXdS)z Retrieve value from a cache key.N)r~�open�json�load�OSError�
ValueError�IOError�KeyError)rHr�r��fr&r&r(�__getitem__s

zJSONFileCache.__getitem__cCs�|j|�}ytj|td�}Wn$ttfk
r@td|��YnXtjj|j	�s\tj
|j	�tjtj|tj
tjBd�d��}|j�|j|�WdQRXdS)N)rz5Value cannot be cached, must be JSON serializable: %si��w)r~r��dumpsre�	TypeErrorr�rr��isdirr}�makedirs�fdopenr��O_WRONLY�O_CREAT�truncate�write)rHr�rbZfull_keyZfile_contentr�r&r&r(�__setitem__'s

zJSONFileCache.__setitem__cCstjj|j|d�}|S)Nz.json)rr��joinr})rHr��	full_pathr&r&r(r~5sz JSONFileCache._convert_cache_keyN)rYrZr[r\rr��
expanduserr�Z	CACHE_DIRrIr�r�r�r~r&r&r&r(r{
s	r{c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
rha\
    Holds the credentials needed to authenticate requests.

    :ivar access_key: The access key part of the credentials.
    :ivar secret_key: The secret key part of the credentials.
    :ivar token: The security token, valid only for session credentials.
    :ivar method: A string which identifies where the credentials
        were found.
    NcCs0||_||_||_|dkrd}||_|j�dS)NZexplicit)rrr�method�
_normalize)rHrrrr�r&r&r(rIEszCredentials.__init__cCs$tjj|j�|_tjj|j�|_dS)N)�botocore�compat�ensure_unicoderr)rHr&r&r(r�QszCredentials._normalizecCst|j|j|j�S)N)rrrr)rHr&r&r(�get_frozen_credentials[sz"Credentials.get_frozen_credentials)NN)rYrZr[r\rIr�r�r&r&r&r(rh:s
	

rhc@s�eZdZdZd%Zd&Zefdd�Zdd�Ze	d	d
��Z
edd��Zej
d
d��Zedd��Zej
dd��Zedd��Zej
dd��Zdd�Zd'dd�Zdd�Zdd�Zdd�Zedd ��Zd!d"�Zd#d$�ZdS)(�RefreshableCredentialsa�
    Holds the credentials needed to authenticate requests. In addition, it
    knows how to refresh itself.

    :ivar access_key: The access key part of the credentials.
    :ivar secret_key: The secret key part of the credentials.
    :ivar token: The security token, valid only for session credentials.
    :ivar method: A string which identifies where the credentials
        were found.
    ��<�
cCsN||_||_||_||_||_||_tj�|_||_	t
|||�|_|j�dS)N)
�_refresh_using�_access_key�_secret_key�_token�_expiry_time�
_time_fetcher�	threading�Lock�
_refresh_lockr�r�_frozen_credentialsr�)rHrrrrm�
refresh_usingr��time_fetcherr&r&r(rIss
zRefreshableCredentials.__init__cCs$tjj|j�|_tjj|j�|_dS)N)r�r�r�r�r�)rHr&r&r(r��sz!RefreshableCredentials._normalizecCs.||d|d|d|j|d�||d�}|S)Nrrrrm)rrrrmr�r�)�_expiry_datetime)�cls�metadatar�r��instancer&r&r(�create_from_metadata�sz+RefreshableCredentials.create_from_metadatacCs|j�|jS)z�Warning: Using this property can lead to race conditions if you
        access another property subsequently along the refresh boundary.
        Please use get_frozen_credentials instead.
        )rur�)rHr&r&r(r�sz!RefreshableCredentials.access_keycCs
||_dS)N)r�)rHrbr&r&r(r�scCs|j�|jS)z�Warning: Using this property can lead to race conditions if you
        access another property subsequently along the refresh boundary.
        Please use get_frozen_credentials instead.
        )rur�)rHr&r&r(r�sz!RefreshableCredentials.secret_keycCs
||_dS)N)r�)rHrbr&r&r(r�scCs|j�|jS)z�Warning: Using this property can lead to race conditions if you
        access another property subsequently along the refresh boundary.
        Please use get_frozen_credentials instead.
        )rur�)rHr&r&r(r�szRefreshableCredentials.tokencCs
||_dS)N)r�)rHrbr&r&r(r�scCs|j|j�}t|�S)N)r�r�r	)rHZdeltar&r&r(�_seconds_remaining�sz)RefreshableCredentials._seconds_remainingNcCs:|jdkrdS|dkr|j}|j�|kr,dStjd�dS)a�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.

        NFz!Credentials need to be refreshed.T)r��_advisory_refresh_timeoutr�r=r>)rH�
refresh_inr&r&r(�refresh_needed�s

z%RefreshableCredentials.refresh_neededcCs|jdd�S)Nr)r�)r�)rHr&r&r(�_is_expired�sz"RefreshableCredentials._is_expiredc
Cs�|j|j�sdS|jjd�rXz,|j|j�s.dS|j|j�}|j|d�dS|jj�Xn:|j|j�r�|j�"|j|j�s|dS|jdd�WdQRXdS)NF)�is_mandatoryT)r�r�r��acquire�_mandatory_refresh_timeout�_protected_refresh�release)rHZis_mandatory_refreshr&r&r(ru�s zRefreshableCredentials._refreshcCs�y|j�}WnBtk
rN}z&|r&dnd}tjd|dd�|r@�dSd}~XnX|j|�t|j|j|j�|_	|j
�r�d}tj|�t|��dS)NZ	mandatoryZadvisoryzARefreshing temporary credentials failed during %s refresh period.T)�exc_infozLCredentials were refreshed, but the refreshed credentials are still expired.)r��	Exceptionr=Zwarning�_set_from_datarr�r�r�r�r��RuntimeError)rHr�r��eZperiod_name�msgr&r&r(r�s 


z)RefreshableCredentials._protected_refreshcCst|�S)N)r)Ztime_strr&r&r(r�!sz'RefreshableCredentials._expiry_datetimecs�ddddg}�s|}n�fdd�|D�}|rHd}t|j|dj|�d	���d|_�d|_�d|_t�d�|_tj	d
|j�|j
�dS)Nrrrrmcsg|]}|�kr|�qSr&r&)�.0�k)�datar&r(�
<listcomp>*sz9RefreshableCredentials._set_from_data.<locals>.<listcomp>z7Credential refresh failed, response did not contain: %sz, )�provider�	error_msgz(Retrieved credentials will expire at: %s)rr�r�rrrrr�r=r>r�)rHr�Z
expected_keysZmissing_keys�messager&)r�r(r�%s 


z%RefreshableCredentials._set_from_datacCs|j�|jS)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)

        )rur�)rHr&r&r(r�;s"z-RefreshableCredentials.get_frozen_credentialsi�iX)N)rYrZr[r\r�r�r`rIr��classmethodr��propertyr�setterrrr�r�r�rur��staticmethodr�r�r�r&r&r&r(r�as(

			
"!r�cs.eZdZdZefdd�Zd�fdd�	Z�ZS)�DeferredRefreshableCredentialszyRefreshable credentials that don't require initial credentials.

    refresh_using will be called upon first access.
    cCs>||_d|_d|_d|_d|_||_tj�|_||_	d|_
dS)N)r�r�r�r�r�r�r�r�r�r�r�)rHr�r�r�r&r&r(rIfs
z'DeferredRefreshableCredentials.__init__Ncs|jdkrdStt|�j|�S)NT)r��superr�r�)rHr�)�	__class__r&r(r�qs

z-DeferredRefreshableCredentials.refresh_needed)N)rYrZr[r\r`rIr��
__classcell__r&r&)r�r(r�asr�c@sZeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�ZdS)�CachedCredentialFetcherr�r�NcCs4|dkri}||_|j�|_|dkr*|j}||_dS)N)rE�_create_cache_key�
_cache_key�DEFAULT_EXPIRY_WINDOW_SECONDS�_expiry_window_seconds)rHr#�expiry_window_secondsr&r&r(rI|s
z CachedCredentialFetcher.__init__cCstd��dS)Nz_create_cache_key())�NotImplementedError)rHr&r&r(r��sz)CachedCredentialFetcher._create_cache_keycCs$|jdd�jtjjd�}|jdd�S)N�:�_�/)�replacerr��sep)rH�filenamer&r&r(�_make_file_safe�sz'CachedCredentialFetcher._make_file_safecCstd��dS)Nz_get_credentials())r�)rHr&r&r(�_get_credentials�sz(CachedCredentialFetcher._get_credentialscCs|j�S)N)�_get_cached_credentials)rHr&r&r(�fetch_credentials�sz)CachedCredentialFetcher.fetch_credentialscCs`|j�}|dkr$|j�}|j|�n
tjd�|d}t|ddd�}|d|d|d	|d
�S)z�Get up-to-date credentials.

        This will check the cache for up-to-date credentials, calling assume
        role if none are available.
        Nz*Credentials for role retrieved from cache.rhrlT)rdrirjrk)rrrrm)�_load_from_cacher��_write_to_cacher=r>re)rHro�creds�
expirationr&r&r(r��s
z/CachedCredentialFetcher._get_cached_credentialscCs8|j|jkr4t|j|j�}|j|�s*|Stjd�dS)Nz6Credentials were found in cache, but they are expired.)r�rErr�r=r>)rHr�r&r&r(r��s
z(CachedCredentialFetcher._load_from_cachecCst|�|j|j<dS)N)rrEr�)rHror&r&r(r��sz'CachedCredentialFetcher._write_to_cachecCs(t|dd�}t|t��}||jkS)z!Check if credentials are expired.rhrl)rcr	r`r�)rHrpZend_timeZsecondsr&r&r(r��sz#CachedCredentialFetcher._is_expiredi�)NN)
rYrZr[r�rIr�r�r�r�r�r�r�r�r&r&r&r(r�ys
	r�cs.eZdZd�fdd�	Zdd�Zdd�Z�ZS)	�BaseAssumeRoleCredentialFetcherNcsj||_||_|dkri|_n
t|�|_|j|jd<|jjd�|_d|_|jsT|j�tt	|�j
||�dS)NZRoleArn�RoleSessionNameF)�_client_creatorZ	_role_arn�_assume_kwargsrr2�_role_session_name�_using_default_session_name�_generate_assume_role_namer�r�rI)rHr+�role_arn�
extra_argsr#r�)r�r&r(rI�s

z(BaseAssumeRoleCredentialFetcher.__init__cCs(dttj��|_|j|jd<d|_dS)Nzbotocore-session-%sr�T)�int�timer�r�r�)rHr&r&r(r��sz:BaseAssumeRoleCredentialFetcher._generate_assume_role_namecCsZt|j�}|jr|d=d|kr0tj|d�|d<tj|dd�}t|jd��j�}|j	|�S)z�Create a predictable cache key for the current configuration.

        The cache key is intended to be compatible with file names.
        r�ZPolicyT)�	sort_keyszutf-8)
rr�r�r��loadsr�r�encode�	hexdigestr�)rH�args�
argument_hashr&r&r(r��s
z1BaseAssumeRoleCredentialFetcher._create_cache_key)NNN)rYrZr[rIr�r�r�r&r&)r�r(r��sr�cs6eZdZd
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�AssumeRoleCredentialFetcherNcs<||_||_|jdkrtj|_tt|�j|||||d�dS)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�r#r�)�_source_credentials�
_mfa_prompter�getpassr�r�rI)rHr+�source_credentialsr�r��mfa_prompterr#r�)r�r&r(rI�s"

z$AssumeRoleCredentialFetcher.__init__cCs|j�}|j�}|jf|�S)z'Get credentials by calling assume role.)�_assume_role_kwargs�_create_clientrn)rHrgrqr&r&r(r�sz,AssumeRoleCredentialFetcher._get_credentialscCsTt|j�}|jd�}|dk	r6d|}|j|�}||d<|jd�}|dk	rP||d<|S)zAGet the arguments for assume role based on current configuration.�SerialNumberNzEnter MFA code for %s: Z	TokenCode�DurationSeconds)rr�r2r�)rH�assume_role_kwargs�
mfa_serial�promptZ
token_code�duration_secondsr&r&r(r"s



z/AssumeRoleCredentialFetcher._assume_role_kwargscCs"|jj�}|jd|j|j|jd�S)z2Create an STS client using the source credentials.�sts)�aws_access_key_id�aws_secret_access_key�aws_session_token)r�r�r�rrr)rHZfrozen_credentialsr&r&r(r4s
z*AssumeRoleCredentialFetcher._create_client)NNNN)rYrZr[rIr�rrr�r&r&)r�r(r��s
*r�cs.eZdZd�fdd�	Zdd�Zdd�Z�ZS)	�*AssumeRoleWithWebIdentityCredentialFetcherNcs$||_tt|�j|||||d�dS)aG
        :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�r#r�N)�_web_identity_token_loaderr�rrI)rHr+�web_identity_token_loaderr�r�r#r�)r�r&r(rIBs
z3AssumeRoleWithWebIdentityCredentialFetcher.__init__cCs,|j�}ttd�}|jd|d�}|jf|�S)z'Get credentials by calling assume role.)�signature_versionr
)�config)rrrr�Zassume_role_with_web_identity)rHrgrrqr&r&r(r�fs
z;AssumeRoleWithWebIdentityCredentialFetcher._get_credentialscCst|j�}|j�}||d<|S)zAGet the arguments for assume role based on current configuration.ZWebIdentityToken)rr�r)rHrZidentity_tokenr&r&r(ros
z>AssumeRoleWithWebIdentityCredentialFetcher._assume_role_kwargs)NNN)rYrZr[rIr�rr�r&r&)r�r(r?s#	rc@s.eZdZdZdZddd�Zdd�Zdd�ZdS)	�CredentialProviderNcCs
||_dS)N)r')rHr'r&r&r(rI�szCredentialProvider.__init__cCsdS)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&)rHr&r&r(r��szCredentialProvider.loadcGsLg}xB|D]:}y|j||�Wq
tk
rBt|j|d��Yq
Xq
W|S)N)r��cred_var)�appendr�r
�METHOD)rH�mappingZ	key_names�foundZkey_namer&r&r(�_extract_creds_from_mapping�s
z.CredentialProvider._extract_creds_from_mapping)N)rYrZr[r�CANONICAL_NAMErIr�rr&r&r&r(rxs

rc@s:eZdZdZejfdd�Zdd�Zdd�Ze	dd	��Z
d
S)rOzcustom-processcCs||_||_d|_||_dS)N)�
_profile_name�_load_config�_loaded_config�_popen)rHr,r*�popenr&r&r(rI�szProcessProvider.__init__csd�j��dkrdS�j��}|jd�dk	rDtj|��fdd��j�St|d|d|jd��jd�S)Nrmcs
�j��S)N)�_retrieve_credentials_usingr&)�credential_processrHr&r(r)�sz&ProcessProvider.load.<locals>.<lambda>rrr)rrrr�)�_credential_processr r2r�r�rrh)rHZ
creds_dictr&)r!rHr(r��s
zProcessProvider.loadc	Cs�t|�}|j|tjtjd�}|j�\}}|jdkrFt|j|jd�d��t	j
jj|jd��}|j
dd�}|dkr�t|jd|d��y"|d	|d
|j
d�|j
d�d
�Stk
r�}zt|jd|d��WYdd}~XnXdS)N)�stdout�stderrrzutf-8)r�r�ZVersionz<Version key not provided>�zOUnsupported version '%s' for credential process provider, supported versions: 1rirjrkrl)rrrrmz$Missing required key in response: %s)r
r�
subprocess�PIPEZcommunicate�
returncoderr�decoder�r�r�r�r2r�)	rHr!Zprocess_list�pr#r$Zparsed�versionr�r&r&r(r �s0


z+ProcessProvider._retrieve_credentials_usingcCs6|jdkr|j�|_|jjdi�j|ji�}|jd�S)N�profilesr!)rrr2r)rH�profile_configr&r&r(r"�s


z#ProcessProvider._credential_processN)rYrZr[rr&�PopenrIr�r r�r"r&r&r&r(rO�s
rOc@s$eZdZdZdZdd�Zdd�ZdS)r5ziam-roleZEc2InstanceMetadatacCs
||_dS)N)�
_role_fetcher)rHr"r&r&r(rI�sz!InstanceMetadataProvider.__init__cCs>|j}|j�}|sdStjd|d�tj||j|jd�}|S)Nz#Found credentials from IAM Role: %s�	role_name)r�r�)r/Zretrieve_iam_role_credentialsr=r>r�r�r)rH�fetcherr�r�r&r&r(r��s

zInstanceMetadataProvider.loadN)rYrZr[rrrIr�r&r&r&r(r5�sr5c@sJeZdZdZdZdZdZddgZdZdd	d
�Z	dd�Z
d
d�Zdd�ZdS)r3�envZEnvironmentZAWS_ACCESS_KEY_IDZAWS_SECRET_ACCESS_KEYZAWS_SECURITY_TOKENZAWS_SESSION_TOKENZAWS_CREDENTIAL_EXPIRATIONNcCs$|dkrtj}||_|j|�|_dS)a�

        :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)rHr3rr&r&r(rIszEnvProvider.__init__cCs�i}|dkr6|j|d<|j|d<|j|d<|j|d<nd|jd|j�|d<|jd|j�|d<|jd|j�|d<t|dt�s�|dg|d<|jd|j�|d<|S)Nrrrrm)�
ACCESS_KEY�
SECRET_KEY�TOKENS�EXPIRY_TIMEr2ra�list)rHrZvar_mappingr&r&r(r4!s"


zEnvProvider._build_mappingcCs�|jj|jdd�}|r�tjd�|j�}|dd�}|d}|dk	rnt|�}t|d|d|d	|||jd
�St	|d|d|d	|jd�SdSdS)zK
        Search for credentials in explicit environment variables.
        r�z+Found credentials in environment variables.F)�require_expiryrmNrr)r�r�)r�)
r3r2r5r=�info�_create_credentials_fetcherrr�rrh)rHrr1rprmr&r&r(r�7s 

zEnvProvider.loadcs(|j�|j�|j�d���fdd�	}|S)NTcs�i}�j�dd�}|s(t��dd��||d<�j�dd�}|sTt��dd��||d<d|d<x*�dD]}�j|d�}|rn||d<PqnWd|d<�j�dd�}|r�||d<|r�|r�t��dd��|S)Nrr;)r�rrrrm)r2r
)r<rprrZ
token_env_varrrm)r3rr�r&r(r�Xs2
zBEnvProvider._create_credentials_fetcher.<locals>.fetch_credentials)T)r5rr3)rHr�r&)r3rr�r(r>Ss
 z'EnvProvider._create_credentials_fetcher)NN)
rYrZr[rrr6r7r8r9rIr4r�r>r&r&r&r(r3s
r3c@s2eZdZdZdZdZdZdZddd�Zd	d
�Z	dS)r:zec2-credentials-fileZ	Ec2Config�AWS_CREDENTIAL_FILEZAWSAccessKeyIdZAWSSecretKeyNcCs*|dkrtj}|dkrt}||_||_dS)N)rr3r�_environ�_parser)rHr3�parserr&r&r(rI�szOriginalEC2Provider.__init__cCshd|jkr`tjj|jd�}|j|�}|j|krdtjd�||j}||j}t	|||j
d�SndSdS)zN
        Search for a credential file used by original EC2 CLI tools.
        r?z)Found credentials in AWS_CREDENTIAL_FILE.)r�N)r@rr�r�rAr6r=r=r7rhr)rHr�r�rrr&r&r(r��s





zOriginalEC2Provider.load)NN)
rYrZr[rrZ
CRED_FILE_ENVr6r7rIr�r&r&r&r(r:{s
r:c@s>eZdZdZdZdZdZddgZddd	�Zd
d�Z	dd
�Z
dS)rQzshared-credentials-fileZSharedCredentialsrr�aws_security_tokenr
NcCs2||_|dkrd}||_|dkr(tjj}||_dS)Nr)�_creds_filenamerr��configloader�raw_config_parse�_ini_parser)rHrPr,�
ini_parserr&r&r(rI�sz!SharedCredentialProvider.__init__cCs�y|j|j�}Wntk
r$dSX|j|kr�||j}|j|kr�tjd|j�|j||j|j�\}}|j	|�}t
||||jd�SdS)Nz0Found credentials in shared credentials file: %s)r�)rGrDrrr6r=r=rr7�_get_session_tokenrhr)rHZavailable_credsrrrrr&r&r(r��s



zSharedCredentialProvider.loadcCs$x|jD]}||kr||SqWdS)N)r8)rHrZtoken_envvarr&r&r(rI�sz+SharedCredentialProvider._get_session_token)NN)rYrZr[rrr6r7r8rIr�rIr&r&r&r(rQ�s
	rQc@sBeZdZdZdZdZdZdZddgZdd	d
�Z	dd�Z
d
d�ZdS)rTz0INI based config provider with profile sections.zconfig-fileZSharedConfigrrrCr
NcCs&||_||_|dkrtjj}||_dS)a

        :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_filenamerr�rEr*�_config_parser)rHrSr,Z
config_parserr&r&r(rI�s
	zConfigProvider.__init__cCs�y|j|j�}Wntk
r$dSX|j|dkr�|d|j}|j|kr�tjd|j�|j||j|j�\}}|j	|�}t
||||jd�SndSdS)zr
        If there is are credentials in the configuration associated with
        the session, use those.
        Nr,z$Credentials found in config file: %s)r�)rKrJrrr6r=r=rr7rIrhr)rHr%r-rrrr&r&r(r��s

zConfigProvider.loadcCs$x|jD]}||kr||SqWdS)N)r8)rHr-Z
token_namer&r&r(rI�sz!ConfigProvider._get_session_token)N)rYrZr[r\rrr6r7r8rIr�rIr&r&r&r(rT�s
rTc@s:eZdZdZdZdZddgZdZdZd
d	d
�Z	dd�Z
dS)r;zboto-configZBoto2ConfigZBOTO_CONFIGz
/etc/boto.cfgz~/.botorrNcCs.|dkrtj}|dkrtjj}||_||_dS)N)rr3r�rErFr@rG)rHr3rHr&r&r(rIszBotoProvider.__init__cCs�|j|jkr|j|jg}n|j}x~|D]v}y|j|�}Wntk
rPw(YnXd|kr(|d}|j|kr(tjd|�|j||j|j	�\}}t
|||jd�Sq(WdS)z;
        Look for credentials in boto config file.
        rhz)Found credentials in boto config file: %s)r�N)�BOTO_CONFIG_ENVr@�DEFAULT_CONFIG_FILENAMESrGrr6r=r=rr7rhr)rHZpotential_locationsr�rrprrr&r&r(r�s"

zBotoProvider.load)NN)rYrZr[rrrLrMr6r7rIr�r&r&r&r(r;�s
r;c@s�eZdZdZdZdZdZd!Zejddfdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �ZdS)"r7zassume-roleNr��web_identity_token_filer�r�cCs>||_||_||_||_||_i|_||_||_|jg|_dS)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)	r#rr�r�	_prompterr�_credential_sourcer�_profile_provider_builder�_visited_profiles)rHr*r+r#r,Zprompterr-r.r&r&r(rI7s$zAssumeRoleProvider.__init__cCs@|j�|_|jjdi�}|j|ji�}|j|�r<|j|j�SdS)Nr,)rrr2r�_has_assume_role_config_vars�_load_creds_via_assume_role)rHr,rr&r&r(r�ns


zAssumeRoleProvider.loadcCs|j|ko|j|kS)N)�ROLE_CONFIG_VAR�WEB_IDENTITY_TOKE_FILE_VAR)rHrr&r&r(rSus
z/AssumeRoleProvider._has_assume_role_config_varscCs�|j|�}|j||�}i}|jd�}|dk	r4||d<|jd�}|dk	rN||d<|jd�}|dk	rh||d<|jd�}|dk	r�||d<t|j||d	||j|jd
�}	|	j}
|dk	r�t|
�}
t	|j
|
td�S)N�role_session_namer��external_idZ
ExternalIdrrr	rr�)r+rr�r�rr#)r�r�r�)�_get_role_config�_resolve_source_credentialsr2r�r�rOr#r�rzr�rr`)rHr,�role_configrr�rWrXrr	r1Z	refresherr&r&r(rTs<





z.AssumeRoleProvider._load_creds_via_assume_rolecCs|jjdi�}||}|jd�}|d}|jd�}|jd�}|jd�}|jd�}	|jd�}
||||	||d	�}|
d
k	r�yt|
�|d<Wntk
r�YnX|d
k	r�|d
k	r�td|d��nB|d
kr�|d
kr�t|jd
d��n"|d
k	r�|j||�n|j||�|S)z?Retrieves and validates the role configuration for the profile.r,�source_profiler��credential_sourcerrXrWr	)r�rXrrWr\r]NzDThe profile "%s" contains both source_profile and credential_source.)r�z#source_profile or credential_source)r�r)	rr2r�r�rr
r�_validate_credential_source�_validate_source_profile)rHr,r,rr\r�r]rrXrWr	r[r&r&r(rY�sB







z#AssumeRoleProvider._get_role_configcCs>|jdkrtd||fd��|jj|�s:td||fd��dS)Nz_The credential_source "%s" is specified in profile "%s", but no source provider was configured.)r�zCThe credential source "%s" referenced in profile "%s" is not valid.)rPr�is_supported)rHZparent_profiler]r&r&r(r^�s
z.AssumeRoleProvider._validate_credential_sourcecCst|j|�|j|�g�S)N)�any�_has_static_credentialsrS)rHrr&r&r(�_source_profile_has_credentials�sz2AssumeRoleProvider._source_profile_has_credentialscCsp|jjdi�}||kr(td||fd��||}||jkr>dS||krTt||jd��|j|�slt||jd��dS)Nr,zFThe source_profile "%s" referenced in the profile "%s" does not exist.)r�)r\Zvisited_profiles)rr2rrRrrb)rHZparent_profile_nameZsource_profile_namer,r\r&r&r(r_�s 


z+AssumeRoleProvider._validate_source_profilecsddg}t�fdd�|D��S)Nrrc3s|]}|�kVqdS)Nr&)r�Z
static_key)rr&r(�	<genexpr>sz=AssumeRoleProvider._has_static_credentials.<locals>.<genexpr>)ra)rHrZstatic_keysr&)rr(rbsz*AssumeRoleProvider._has_static_credentialscCs<|jd�}|dk	r|j||�S|d}|jj|�|j|�S)Nr]r\)r2� _resolve_credentials_from_sourcerRr�!_resolve_credentials_from_profile)rHr[r,r]r\r&r&r(rZs
z.AssumeRoleProvider._resolve_source_credentialscCs�|jjdi�}||}|j|�r2|jr2|j|�S|j|�sH|j|�r�|jj|dd�}t|�}|j�}|dkr�d}t	||d��|S|j
|�S)Nr,T)r,r/z.The source profile "%s" must have credentials.)r�)rr2rbrQ�(_resolve_static_credentials_from_profilerSr0r?r]rrT)rHr,r,rrAZ
profile_chainrpZ
error_messager&r&r(rf%s$


z4AssumeRoleProvider._resolve_credentials_from_profilecCsVyt|d|d|jd�d�Stk
rP}zt|jt|�d��WYdd}~XnXdS)Nrrr
)rrr)r�r)rhr2r�r
r�str)rHrr�r&r&r(rgCsz;AssumeRoleProvider._resolve_static_credentials_from_profilecCs(|jj|�}|dkr$t|d|d��|S)NzBNo credentials found in credential_source referenced in profile %s)r�r�)rPrr)rHr]r,rpr&r&r(reNs
z3AssumeRoleProvider._resolve_credentials_from_sourcei�)rYrZr[rrrUrVZEXPIRY_WINDOW_SECONDSr�rIr�rSrTrYr^rcr_rbrZrfrgrer&r&r&r(r7(s&5
,2
&r7c@sReZdZdZdZdddd�Zddd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)rUzassume-role-with-web-identityNZAWS_WEB_IDENTITY_TOKEN_FILEZAWS_ROLE_SESSION_NAMEZAWS_ROLE_ARN)rNrWr�FcCs:||_||_||_||_d|_||_|dkr0t}||_dS)N)r#rr�r�_profile_config�_disable_env_varsr�_token_loader_cls)rHr*r+r,r#r/Ztoken_loader_clsr&r&r(rIfs	z*AssumeRoleWithWebIdentityProvider.__init__cCs|j�S)N)�_assume_role_with_web_identity)rHr&r&r(r�ysz&AssumeRoleWithWebIdentityProvider.loadcCs:|jdkr.|j�}|jdi�}|j|ji�|_|jj|�S)Nr,)rirr2r)rH�key�
loaded_configr,r&r&r(�_get_profile_config|s

z5AssumeRoleWithWebIdentityProvider._get_profile_configcCs2|jr
dS|jj|�}|r.|tjkr.tj|SdS)N)rj�_CONFIG_TO_ENV_VARr2rr3)rHrmZenv_keyr&r&r(�_get_env_config�s
z1AssumeRoleWithWebIdentityProvider._get_env_configcCs |j|�}|dk	r|S|j|�S)N)rqro)rHrmZ	env_valuer&r&r(�_get_config�s
z-AssumeRoleWithWebIdentityProvider._get_configcCs||jd�}|sdS|j|�}|jd�}|s8d}t|d��i}|jd�}|dk	rV||d<t|j||||jd�}t|j|jd�S)	NrNr�z�The 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�rWr�)r+rr�r�r#)r�r�)	rrrkrrr�r#r�rr�)rHZ
token_path�token_loaderr�r�r�rWr1r&r&r(rl�s*





z@AssumeRoleWithWebIdentityProvider._assume_role_with_web_identity)NFN)rYrZr[rrrprIr�rorqrrrlr&r&r&r(rU]s
rUc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)r9cCs
||_dS)N)�
_providers)rHr0r&r&r(rI�sz'CanonicalNameCredentialSourcer.__init__cCs|dd�|jD�kS)aLValidates 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.
        cSsg|]
}|j�qSr&)r)r�r*r&r&r(r��sz?CanonicalNameCredentialSourcer.is_supported.<locals>.<listcomp>)rt)rH�source_namer&r&r(r`�sz+CanonicalNameCredentialSourcer.is_supportedcCs$|j|�}t|t�r|j�S|j�S)aLoads 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_providerrar?r]r�)rHru�sourcer&r&r(r�s	

z1CanonicalNameCredentialSourcer.source_credentialscCsV|j|�}|j�dkr@|jd�}|dk	r@|dkr4|St||g�S|dkrRt|d��|S)a#Return 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�sharedcredentialszassume-roleN)�name)rxry)�_get_provider_by_canonical_name�lower�_get_provider_by_methodr?r)rH�canonical_namer�r@r&r&r(rv�s



z,CanonicalNameCredentialSourcer._get_providercCs2x,|jD]"}|j}|r|j�|j�kr|SqWdS)z�Return a credential provider by its canonical name.

        This function is strict, it does not attempt to address
        compatibility issues.
        N)rtrr|)rHr~r�rzr&r&r(r{�sz>CanonicalNameCredentialSourcer._get_provider_by_canonical_namecCs"x|jD]}|j|kr|SqWdS)z0Return a credential provider by its METHOD name.N)rtr)rHr�r�r&r&r(r}s
z6CanonicalNameCredentialSourcer._get_provider_by_methodN)	rYrZr[rIr`rrvr{r}r&r&r&r(r9�s
&r9c@sReZdZdZdZdZdZdZddd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)r4zcontainer-roleZEcsContainerZ&AWS_CONTAINER_CREDENTIALS_RELATIVE_URIZ"AWS_CONTAINER_CREDENTIALS_FULL_URIZ!AWS_CONTAINER_AUTHORIZATION_TOKENNcCs,|dkrtj}|dkrt�}||_||_dS)N)rr3rr@�_fetcher)rHr3r1r&r&r(rIszContainerProvider.__init__cCs$|j|jks|j|jkr |j�SdS)N)�ENV_VARr@�ENV_VAR_FULL�_retrieve_or_fail)rHr&r&r(r�szContainerProvider.loadcCsn|j�r|jj|j|j�}n|j|j}|j�}|j||�}|�}t|d|d|d|j	t
|d�|d�S)Nrrrrm)rrrr�rmr�)�_provided_relative_urirZfull_urlr@r�r��_build_headers�_create_fetcherr�rrc)rH�full_uri�headersr1r�r&r&r(r�#s
z#ContainerProvider._retrieve_or_failcCs&i}|jj|j�}|dk	r"d|iSdS)NZ
Authorization)r@r2�ENV_VAR_AUTH_TOKEN)rHr�Z
auth_tokenr&r&r(r�4sz ContainerProvider._build_headerscs���fdd�}|S)Ncsxy�jj��d�}WnDtk
rX}z(tjd|dd�t�jt|�d��WYdd}~XnX|d|d|d|d	d
�S)N)r�z'Error retrieving container metadata: %sT)r�)r�r�rirj�Tokenrl)rrrrm)rZretrieve_full_urirr=r>rrrh)ror�)r�r�rHr&r(�fetch_creds=sz6ContainerProvider._create_fetcher.<locals>.fetch_credsr&)rHr�r�r�r&)r�r�rHr(r�<sz!ContainerProvider._create_fetchercCs|j|jkS)N)r�r@)rHr&r&r(r�Osz(ContainerProvider._provided_relative_uri)NN)rYrZr[rrr�r�r�rIr�r�r�r�r�r&r&r&r(r4s
r4c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)r?cCs
||_dS)zQ

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

        N)r0)rHr0r&r&r(rITszCredentialResolver.__init__cCsLydd�|jD�j|�}Wntk
r8t|d��YnX|jj||�dS)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``
        cSsg|]
}|j�qSr&)r)r�r*r&r&r(r�ksz4CredentialResolver.insert_before.<locals>.<listcomp>)rzN)r0�indexr�r�insert)rHrz�credential_provider�offsetr&r&r(�
insert_before\s
z CredentialResolver.insert_beforecCs |j|�}|jj|d|�dS)a9
        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_offsetr0r�)rHrzr�r�r&r&r(�insert_afterps
zCredentialResolver.insert_aftercCs6dd�|jD�}||krdS|j|�}|jj|�dS)z�
        Removes a given ``Credentials`` instance from the chain.

        :param name: The short name of the credentials instance to remove.
        :type name: string
        cSsg|]
}|j�qSr&)r)r�r*r&r&r(r��sz-CredentialResolver.remove.<locals>.<listcomp>N)r0r��pop)rHrzZavailable_methodsr�r&r&r(r<�s

zCredentialResolver.removecCs|j|j|�S)z�Return 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.
        )r0r�)rHrzr&r&r(�get_provider�s
zCredentialResolver.get_providercCs:ydd�|jD�j|�Stk
r4t|d��YnXdS)NcSsg|]
}|j�qSr&)r)r�r*r&r&r(r��sz;CredentialResolver._get_provider_offset.<locals>.<listcomp>)rz)r0r�r�r)rHrzr&r&r(r��sz'CredentialResolver._get_provider_offsetcCs6x0|jD]&}tjd|j�|j�}|dk	r|SqWdS)zw
        Goes through the credentials chain, returning the first ``Credentials``
        that could be loaded.
        zLooking for credentials via: %sN)r0r=r>rr�)rHr�r�r&r&r(r]�sz#CredentialResolver.load_credentialsN)
rYrZr[rIr�r�r<r�r�r]r&r&r&r(r?Ssr?cs6eZdZd
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�SSOCredentialFetcherNc		s:||_||_||_||_||_||_tt|�j||�dS)N)	r��_sso_region�
_role_name�_account_id�
_start_url�
_token_loaderr�r�rI)	rHZ	start_url�
sso_regionr0Z
account_idr+rsr#r�)r�r&r(rI�s
zSSOCredentialFetcher.__init__cCs>|j|j|jd�}tj|ddd�}t|jd��j�}|j|�S)z�Create a predictable cache key for the current configuration.

        The cache key is intended to be compatible with file names.
        )ZstartUrl�roleName�	accountIdT�,r�)r�Z
separatorszutf-8)r�r�)	r�r�r�r�r�rr�r�r�)rHr�r�r&r&r(r��s
z&SSOCredentialFetcher._create_cache_keycCs |d}tjj|t��}t|�S)Ng@�@)r_Z
fromtimestamprre)rHZtimestamp_msZtimestamp_secondsZ	timestampr&r&r(�_parse_timestamp�sz%SSOCredentialFetcher._parse_timestampcCs�tt|jd�}|jd|d�}|j|j|j|j�d�}y|jf|�}Wn|j	j
k
rbt��YnX|d}d|d|d|d|j|d	�d
�d�}|S)z4Get credentials by calling SSO get role credentials.)rr$�sso)r)r�r�ZaccessTokenZroleCredentialsZaccessKeyIdZsecretAccessKeyZsessionTokenr�)rirjrkrl)ZProviderTyperh)
rrr�r�r�r�r�r�Zget_role_credentials�
exceptionsZUnauthorizedExceptionrr�)rHrrqrgrorpr&r&r(r��s$
z%SSOCredentialFetcher._get_credentials)NNN)rYrZr[rIr�r�r�r�r&r&)r�r(r��s
r�c@sPeZdZdZejjejjdddd��ZddddgZ	dd
d�Z
dd
�Zdd�Zd	S)rWr�r|z.awsr#�
sso_start_urlr��
sso_role_name�sso_account_idNcCs@|dkrt|j�}||_|dkr$i}||_||_||_||_dS)N)r{�_SSO_TOKEN_CACHE_DIR�_token_cacher#rr�r)rHr*r+r,r#rVr&r&r(rIs
zSSOProvider.__init__cs�|j�}|jdi�}|j}|j|ji��t�fdd�|jD��rDdSi}g}x.|jD]$}|�krn�|||<qT|j|�qTW|r�dj|�}td||fd��|S)Nr,c3s|]}|�kVqdS)Nr&)r��c)r-r&r(rdsz/SSOProvider._load_sso_config.<locals>.<genexpr>z, zSThe profile "%s" is configured to use SSO but is missing required configuration: %s)r�)rr2r�all�_SSO_CONFIG_VARSrr�r)rHrnr,r,rZmissing_config_varsZ
config_varZmissingr&)r-r(�_load_sso_configs$
zSSOProvider._load_sso_configc	CsR|j�}|sdSt|d|d|d|d|jt|jd�|jd�}t|j|jd�S)Nr�r�r�r�)r#)rsr#)r�r�)	r�r�r�rr�r#r�rr�)rHZ
sso_configZsso_fetcherr&r&r(r�3s

zSSOProvider.load)NN)
rYrZr[rrr�r�r�r�r�rIr�r�r&r&r&r(rW�s
rW)NN)F)Pr�r_Zloggingrr�r�r�r&�collectionsr�copyrZhashlibrZdateutil.parserrZdateutil.tzrrZbotocore.configloaderr�Zbotocore.compatrr	r
Zbotocore.configrZbotocore.exceptionsrr
rrrrrrrZbotocore.utilsrrrrrZ	getLoggerrYr=rrCryr6r^r`rcrer8rtrzr{rhr�r�r�r�r�rrrOr5r3r:rQrTr;r7rUr9r4r?r�rWr&r&r&r(�<module>s�

ND
-'E1P
8-Ft"*7*7YXEdG