HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: sport3497 (1034)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib64/python3.10/site-packages/botocore/__pycache__/credentials.cpython-310.pyc
o

�h,K�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZmZddlZddlZddlmZddlmZmZdd	lmZdd
lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.e�/e0�Z1e	d
gd��Z2dZ3dZ4dPdd�Z5Gdd�d�Z6dd�Z7dd�Z8dd�Z9dQdd�Z:dd�Z;d d!�Z<d"d#�Z=Gd$d%�d%�Z>Gd&d'�d'e>�Z?Gd(d)�d)e?�Z@Gd*d+�d+�ZAGd,d-�d-eA�ZBGd.d/�d/eB�ZCGd0d1�d1eB�ZDGd2d3�d3�ZEGd4d5�d5eE�ZFGd6d7�d7eE�ZGGd8d9�d9eE�ZHGd:d;�d;eE�ZIGd<d=�d=eE�ZJGd>d?�d?eE�ZKGd@dA�dAeE�ZLGdBdC�dCeE�ZMGdDdE�dEeE�ZNGdFdG�dG�ZOGdHdI�dIeE�ZPGdJdK�dK�ZQGdLdM�dMeA�ZRGdNdO�dOeE�ZSdS)R�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	s��d�pd}��d�}��d�}����d�du}��d�t��t��d�d�}|dur/i}t�}t�}	tt||��	�|d	�d
�}
t
�||d�}t�fdd
�t�|�||t
||	|
g�|d�}||g}
|j||d�}t�t�|	|
g}|
||}|r�|�|�t�d�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�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_namecs�jS�N)�full_config���sessionr5�G/usr/local/CyberCP/lib/python3.10/site-packages/botocore/credentials.py�<lambda>msz,create_credential_resolver.<locals>.<lambda>)�load_config�client_creatorr1�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�InstanceMetadataProviderrr.�ProfileProviderBuilder�AssumeRoleProvider�_get_client_creator�CanonicalNameCredentialSourcerrB�OriginalEC2Provider�BotoProvider�remove�logger�debug�CredentialResolver)r7r1r2r<�metadata_timeoutr-r@�imds_config�env_provider�container_provider�instance_metadata_providerr>�assume_role_provider�pre_profile�profile_providers�post_profilerB�resolverr5r6r8�create_credential_resolverAsx

����
��	�
�����
�
r^c@sNeZdZdZ	ddd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dS)rJa�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||_||_||_||_dSr3)�_session�_cache�_region_name�_sso_token_cache)�selfr7r1r2�sso_token_cacher5r5r8�__init__�s
zProfileProviderBuilder.__init__FcCs.|�||�|�|�|�|�|�|�|�|�gSr3)�_create_web_identity_provider�_create_sso_provider�"_create_shared_credential_provider�_create_process_provider�_create_config_provider�rcr<r@r5r5r8rB�s��z ProfileProviderBuilder.providerscst|�fdd�d�S)Nc��jjSr3�r_r4r5�rcr5r8r9��zAProfileProviderBuilder._create_process_provider.<locals>.<lambda>)r<r:)�ProcessProvider�rcr<r5rnr8ri�s
�z/ProfileProviderBuilder._create_process_providercC�|j�d�}t||d�S)N�credentials_file)r<�creds_filename)r_rC�SharedCredentialProvider)rcr<�credential_filer5r5r8rh��
�z9ProfileProviderBuilder._create_shared_credential_providercCrr)N�config_file)r<�config_filename)r_rC�ConfigProvider)rcr<rxr5r5r8rj�rwz.ProfileProviderBuilder._create_config_providercs&t�fdd�t�j�j��j||d�S)Ncrlr3rmr5rnr5r8r9�rozFProfileProviderBuilder._create_web_identity_provider.<locals>.<lambda>)r:r;r1r<r@)�!AssumeRoleWithWebIdentityProviderrLr_rar`rkr5rnr8rf�s
��z4ProfileProviderBuilder._create_web_identity_providercs2t�fdd��jj|�j�jt�j�j|d�d�S)Ncrlr3rmr5rnr5r8r9�roz=ProfileProviderBuilder._create_sso_provider.<locals>.<lambda>)r1r<)r:r;r<r1�token_cache�token_provider)�SSOProviderr_�
create_clientr`rbrrqr5rnr8rg�s
��z+ProfileProviderBuilder._create_sso_provider�NNN�F)�__name__�
__module__�__qualname__�__doc__rerBrirhrjrfrgr5r5r5r8rJ�s
�
rJcCst|�}|��Sr3)r^�load_credentials)r7r]r5r5r8�get_credentials�sr�cCstj�t��Sr3)�datetime�nowrr5r5r5r8�
_local_now�sr�cCst|tj�r|St|�Sr3)�
isinstancer�r)�valuer5r5r8�_parse_if_needed�sr�FcCs&t|tj�r|r|��S|�d�S|S)Nz%Y-%m-%dT%H:%M:%S%Z)r�r��	isoformat�strftime)r��isor5r5r8�_serialize_if_needed�s

r�c���fdd�}|S)Ncs*d�i}|jdi|���j|fi|��S)Nr2r5)�updater)�service_name�kwargs�create_client_kwargs�r2r7r5r8r;sz+_get_client_creator.<locals>.client_creatorr5)r7r2r;r5r�r8rLsrLcr�)Ncs:�jdi���}|d}|d|d|dt|d�d�S)N�Credentials�AccessKeyId�SecretAccessKey�SessionToken�
Expiration�r r!r"�expiry_timer5)�assume_roler�)�response�credentials��client�paramsr5r8�refreshs
�z-create_assume_role_refresher.<locals>.refreshr5)r�r�r�r5r�r8�create_assume_role_refreshersr�cCsGdd�d�}||�S)Nc@seZdZdd�Zdd�ZdS)z/create_mfa_serial_refresher.<locals>._RefreshercSs||_d|_dS)NF)�_refresh�_has_been_called)rcr�r5r5r8re s
z8create_mfa_serial_refresher.<locals>._Refresher.__init__cSs|jrt��d|_|��S�NT)r�rr�rnr5r5r8�__call__$sz8create_mfa_serial_refresher.<locals>._Refresher.__call__N)r�r�r�rer�r5r5r5r8�
_Refreshersr�r5)�actual_refreshr�r5r5r8�create_mfa_serial_refreshersr�c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
r�ap
    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.
    NcCs0||_||_||_|durd}||_|��dS)N�explicit)r r!r"�method�
_normalize)rcr r!r"r�r5r5r8re;szCredentials.__init__cC�$tj�|j�|_tj�|j�|_dSr3)�botocore�compat�ensure_unicoder r!rnr5r5r8r�FszCredentials._normalizecCst|j|j|j�Sr3)rr r!r"rnr5r5r8�get_frozen_credentialsPs�z"Credentials.get_frozen_credentials�NN)r�r�r�r�rer�r�r5r5r5r8r�0s



r�c@s�eZdZdZeZeZeddfdd�Z	dd�Z
e		d"dd��Ze
d	d
��Zejdd
��Ze
dd
��Zejdd
��Ze
dd��Zejdd��Zdd�Zd#dd�Zdd�Zdd�Zdd�Zedd��Zdd�Zd d!�ZdS)$�RefreshableCredentialsa�
    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

Csn||_||_||_||_||_||_t��|_||_	t
|||�|_|��|dur,||_
|	dur5|	|_dSdSr3)�_refresh_using�_access_key�_secret_key�_token�_expiry_time�
_time_fetcher�	threading�Lock�
_refresh_lockr�r�_frozen_credentialsr��_advisory_refresh_timeout�_mandatory_refresh_timeout)
rcr r!r"r��
refresh_usingr��time_fetcher�advisory_timeout�mandatory_timeoutr5r5r8rels"
�
�zRefreshableCredentials.__init__cCr�r3)r�r�r�r�r�rnr5r5r8r��sz!RefreshableCredentials._normalizec	CsZi}|dur
||d<|dur||d<|d|d|d|d|�|d�||d�|��}|S)	Nr�r�r r!r"r�)r r!r"r�r�r�r5)�_expiry_datetime)�cls�metadatar�r�r�r�r��instancer5r5r8�create_from_metadata�s 	��	z+RefreshableCredentials.create_from_metadatacC�|��|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.
        )r�r�rnr5r5r8r ��z!RefreshableCredentials.access_keycC�
||_dSr3)r��rcr�r5r5r8r ��
cCr�r�)r�r�rnr5r5r8r!�r�z!RefreshableCredentials.secret_keycCr�r3)r�r�r5r5r8r!�r�cCr�r�)r�r�rnr5r5r8r"�r�zRefreshableCredentials.tokencCr�r3)r�r�r5r5r8r"�r�cCs|j|��}t|�Sr3)r�r�r)rc�deltar5r5r8�_seconds_remaining�sz)RefreshableCredentials._seconds_remainingcCs:|jdurdS|dur|j}|��|krdSt�d�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�r�r�rQrR�rc�
refresh_inr5r5r8�refresh_needed�s

z%RefreshableCredentials.refresh_neededcCs|jdd�S)Nr)r�)r�rnr5r5r8�_is_expired�sz"RefreshableCredentials._is_expiredcCs�|�|j�sdS|j�d�r7z"|�|j�sW|j��dS|�|j�}|j|d�W|j��dS|j��w|�|j�rh|j�|�|j�sP	Wd�dS|jdd�Wd�dS1sawYdSdS)NF)�is_mandatoryT)r�r�r��acquire�releaser��_protected_refresh)rc�is_mandatory_refreshr5r5r8r��s*���"��zRefreshableCredentials._refreshcCs�z|��}Wnty!|rdnd}tjd|dd�|r�YdSw|�|�t|j|j|j�|_	|�
�r@d}t�|�t|��dS)N�	mandatory�advisoryzARefreshing temporary credentials failed during %s refresh period.T��exc_infozLCredentials were refreshed, but the refreshed credentials are still expired.)r��	ExceptionrQ�warning�_set_from_datarr�r�r�r�r��RuntimeError)rcr�r��period_name�msgr5r5r8r�s.��
��
�z)RefreshableCredentials._protected_refreshcCst|�Sr3r)�time_strr5r5r8r�=sz'RefreshableCredentials._expiry_datetimecs�gd�}�s	|}n	�fdd�|D�}|r"d}t|j|d�|�d���d|_�d|_�d	|_t�d
�|_t�	d|j�|�
�dS)Nr�csg|]}|�vr|�qSr5r5)�.0�k��datar5r8�
<listcomp>Fsz9RefreshableCredentials._set_from_data.<locals>.<listcomp>z7Credential refresh failed, response did not contain: %s�, ��provider�	error_msgr r!r"r�z(Retrieved credentials will expire at: %s)rr��joinr r!r"rr�rQrRr�)rcr��
expected_keys�missing_keys�messager5r�r8r�As$�


�z%RefreshableCredentials._set_from_datacCr�)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�rnr5r5r8r�Xs"z-RefreshableCredentials.get_frozen_credentialsr�r3)r�r�r�r�rFr��"_DEFAULT_MANDATORY_REFRESH_TIMEOUTr�r�rer��classmethodr��propertyr �setterr!r"r�r�r�r�r��staticmethodr�r�r�r5r5r5r8r�VsD

��






"'
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|_||_t��|_||_	d|_
dSr3)r�r�r�r�r�r�r�r�r�r�r�)rcr�r�r�r5r5r8re�s

z'DeferredRefreshableCredentials.__init__Ncs|jdurdSt��|�Sr�)r��superr�r���	__class__r5r8r��s
z-DeferredRefreshableCredentials.refresh_neededr3)r�r�r�r�r�rer��
__classcell__r5r5r�r8r�~sr�c@sZeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�CachedCredentialFetcherr#NcCs4|duri}||_|��|_|dur|j}||_dSr3)r`�_create_cache_key�
_cache_key�DEFAULT_EXPIRY_WINDOW_SECONDS�_expiry_window_seconds)rcr1�expiry_window_secondsr5r5r8re�s

z CachedCredentialFetcher.__init__cC�td��)Nz_create_cache_key()��NotImplementedErrorrnr5r5r8r��z)CachedCredentialFetcher._create_cache_keycCs"|�dd��tjd�}|�dd�S)N�:�_�/)�replace�os�sep)rc�filenamer5r5r8�_make_file_safe�sz'CachedCredentialFetcher._make_file_safecCr)Nz_get_credentials()rrnr5r5r8�_get_credentials�r	z(CachedCredentialFetcher._get_credentialscC�|��Sr3)�_get_cached_credentialsrnr5r5r8�fetch_credentials�r	z)CachedCredentialFetcher.fetch_credentialscCs`|��}|dur|��}|�|�nt�d�|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.r�r�T)r�r�r�r�r�)�_load_from_cacher�_write_to_cacherQrRr�)rcr��creds�
expirationr5r5r8r�s
�z/CachedCredentialFetcher._get_cached_credentialscCs8|j|jvrt|j|j�}|�|�s|St�d�dS)Nz6Credentials were found in cache, but they are expired.)rr`rr�rQrR)rcrr5r5r8r�s
�z(CachedCredentialFetcher._load_from_cachecCst|�|j|j<dSr3)rr`r)rcr�r5r5r8r�sz'CachedCredentialFetcher._write_to_cachecCs(t|dd�}t|t��}||jkS)z!Check if credentials are expired.r�r�)r�rr�r)rcr��end_time�secondsr5r5r8r��s
z#CachedCredentialFetcher._is_expiredr�)
r�r�r�rrerrrrrrrr�r5r5r5r8r�s
	rc�4eZdZ			d�fdd�	Zdd�Zdd�Z�ZS)	�BaseAssumeRoleCredentialFetcherNcsf||_||_|duri|_nt|�|_|j|jd<|j�d�|_d|_|js*|��t��	||�dS)N�RoleArn�RoleSessionNameF)
�_client_creator�	_role_arn�_assume_kwargsrrE�_role_session_name�_using_default_session_name�_generate_assume_role_namer�re)rcr;�role_arn�
extra_argsr1rr�r5r8re�s
z(BaseAssumeRoleCredentialFetcher.__init__cCs*dtt�����|_|j|jd<d|_dS)Nzbotocore-session-rT)�int�timer#r"r$rnr5r5r8r%�s
z:BaseAssumeRoleCredentialFetcher._generate_assume_role_namecCsZt|j�}|jr|d=d|vrt�|d�|d<tj|dd�}t|�d����}|�	|�S)��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)
rr"r$�json�loads�dumpsr�encode�	hexdigestr�rc�args�
argument_hashr5r5r8r�s

z1BaseAssumeRoleCredentialFetcher._create_cache_keyr�)r�r�r�rer%rr�r5r5r�r8r�s�rcs>eZdZ				d
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�AssumeRoleCredentialFetcherNcs8||_||_|jdurtj|_t�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'r1r)�_source_credentials�
_mfa_prompter�getpassr�re)rcr;�source_credentialsr&r'�mfa_prompterr1rr�r5r8res)

�z$AssumeRoleCredentialFetcher.__init__cCs |��}|��}|jdi|��S)�'Get credentials by calling assume role.Nr5)�_assume_role_kwargs�_create_clientr�)rcr�r�r5r5r8rFsz,AssumeRoleCredentialFetcher._get_credentialscCsXt|j�}|�d�}|durd|�d�}|�|�}||d<|�d�}|dur*||d<|S)�AGet the arguments for assume role based on current configuration.�SerialNumberNzEnter MFA code for z: �	TokenCode�DurationSeconds)rr"rEr9)rc�assume_role_kwargs�
mfa_serial�prompt�
token_code�duration_secondsr5r5r8r>Ls



z/AssumeRoleCredentialFetcher._assume_role_kwargscCs"|j��}|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)r8r�r r r!r")rc�frozen_credentialsr5r5r8r?^s
�z*AssumeRoleCredentialFetcher._create_client)NNNN)r�r�r�rerr>r?r�r5r5r�r8r6s�6r6cr)	�*AssumeRoleWithWebIdentityCredentialFetcherNcs ||_t�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,
        r7N)�_web_identity_token_loaderr�re)rcr;�web_identity_token_loaderr&r'r1rr�r5r8rels$
�z3AssumeRoleWithWebIdentityCredentialFetcher.__init__cCs0|��}ttd�}|jd|d�}|jdi|��S)r=)�signature_versionrI�r/Nr5)r>rr	r �assume_role_with_web_identity)rcr�r/r�r5r5r8r�s
z;AssumeRoleWithWebIdentityCredentialFetcher._get_credentialscCst|j�}|��}||d<|S)r@�WebIdentityToken)rr"rO)rcrD�identity_tokenr5r5r8r>�s
z>AssumeRoleWithWebIdentityCredentialFetcher._assume_role_kwargsr�)r�r�r�rerr>r�r5r5r�r8rNis�.	rNc@s.eZdZdZdZddd�Zdd�Zdd�ZdS)	�CredentialProviderNcCr�r3r6)rcr7r5r5r8re��
zCredentialProvider.__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
        Tr5rnr5r5r8�load�szCredentialProvider.loadc	Gs@g}|D]}z	|�||�Wqtyt|j|d��w|S)N�r��cred_var)�append�KeyErrorr�METHOD)rc�mapping�	key_names�found�key_namer5r5r8�_extract_creds_from_mapping�s��z.CredentialProvider._extract_creds_from_mappingr3)r�r�r�r]�CANONICAL_NAMErerXrbr5r5r5r8rV�s
rVc@s:eZdZdZejfdd�Zdd�Zdd�Ze	dd	��Z
d
S)rpzcustom-processcCs||_||_d|_||_dSr3)�
_profile_name�_load_config�_loaded_config�_popen)rcr<r:�popenr5r5r8re�s
zProcessProvider.__init__csd�j��dur	dS����}|�d�dur"t�|��fdd��j�St|d|d|�d��jd�S)Nr�cs
����Sr3)�_retrieve_credentials_usingr5��credential_processrcr5r8r9�s
z&ProcessProvider.load.<locals>.<lambda>r r!r")r r!r"r�)�_credential_processrirEr�r�r]r�)rc�
creds_dictr5rjr8rX�s 
��zProcessProvider.loadc	
Cs�t|�}|j|tjtjd�}|��\}}|jdkr#t|j|�d�d��t	j
j�|�d��}|�
dd�}|dkrBt|jd|�d	�d��z|d
|d|�
d�|�
d
�d�WStyj}z
t|jd|��d��d}~ww)N)�stdout�stderrrr-r��Versionz<Version key not provided>�zUnsupported version 'z8' for credential process provider, supported versions: 1r�r�r�r�r�z"Missing required key in response: )r
rg�
subprocess�PIPE�communicate�
returncoderr]�decoder�r�r.r/rEr\)	rcrk�process_list�prnro�parsed�version�er5r5r8ri�s:
�
�
�����z+ProcessProvider._retrieve_credentials_usingcCs6|jdur
|��|_|j�di��|ji�}|�d�S)N�profilesrk)rfrerErd)rc�profile_configr5r5r8rls

�
z#ProcessProvider._credential_processN)r�r�r�r]rr�PopenrerXrir�rlr5r5r5r8rp�s#rpc@s$eZdZdZdZdd�Zdd�ZdS)rIziam-role�Ec2InstanceMetadatacCr�r3)�
_role_fetcher)rcr0r5r5r8re(rWz!InstanceMetadataProvider.__init__cCs>|j}|��}|sdSt�d|d�tj||j|jd�}|S)Nz#Found credentials from IAM Role: %s�	role_name�r�r�)r��retrieve_iam_role_credentialsrQ�infor�r�r])rc�fetcherr�rr5r5r8rX+s��zInstanceMetadataProvider.loadN)r�r�r�r]rcrerXr5r5r5r8rI$s
rIc@sJeZdZdZdZdZdZddgZdZdd	d
�Z	dd�Z
d
d�Zdd�ZdS)rG�env�Environment�AWS_ACCESS_KEY_ID�AWS_SECRET_ACCESS_KEY�AWS_SECURITY_TOKEN�AWS_SESSION_TOKEN�AWS_CREDENTIAL_EXPIRATIONNcCs$|durtj}||_|�|�|_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)rcr�r^r5r5r8reKszEnvProvider.__init__cCs�i}|dur|j|d<|j|d<|j|d<|j|d<|S|�d|j�|d<|�d|j�|d<|�d|j�|d<t|dt�sE|dg|d<|�d|j�|d<|S)Nr r!r"r�)�
ACCESS_KEY�
SECRET_KEY�TOKENS�EXPIRY_TIMErEr��list)rcr^�var_mappingr5r5r8r�[s(



����zEnvProvider._build_mappingcCs�|j�|jdd�}|rFt�d�|��}|dd�}|d}|dur7t|�}t|d|d|d	|||jd
�St	|d|d|d	|jd�SdS)zK
        Search for credentials in explicit environment variables.
        r �z+Found credentials in environment variables.F)�require_expiryr�Nr!r")r�r��r�)
r�rEr�rQr��_create_credentials_fetcherrr�r]r�)rcr r�r�r�r5r5r8rXss.

�	�zEnvProvider.loadcs(|j�|j�|j�d���fdd�	}|S)NTcs�i}���dd�}|st��dd��||d<���dd�}|s*t��dd��||d<d|d<�dD]}��|d�}|rF||d<nq6d|d<���dd�}|rY||d<|re|set��dd��|S)Nr r�rYr!r"r�)rEr)r�r�r r!�
token_env_varr"r��r�r^r�r5r8r�s:����zBEnvProvider._create_credentials_fetcher.<locals>.fetch_credentials)T)r�r]r�)rcrr5r�r8r��s
#z'EnvProvider._create_credentials_fetcherr�)
r�r�r�r]rcr�r�r�r�rer�rXr�r5r5r5r8rGAs
!rGc@s2eZdZdZdZdZdZdZddd�Zd	d
�Z	dS)rNzec2-credentials-file�	Ec2Config�AWS_CREDENTIAL_FILE�AWSAccessKeyId�AWSSecretKeyNcCs*|durtj}|dur
t}||_||_dSr3)rr�r�_environ�_parser)rcr��parserr5r5r8re�s
zOriginalEC2Provider.__init__cCsfd|jvr1tj�|jd�}|�|�}|j|vr/t�d�||j}||j}t	|||j
d�SdSdS)zN
        Search for a credential file used by original EC2 CLI tools.
        r�z)Found credentials in AWS_CREDENTIAL_FILE.r�N)r�r�path�
expanduserr�r�rQr�r�r�r])rc�	full_pathrr r!r5r5r8rX�s
�




�zOriginalEC2Provider.loadr�)
r�r�r�r]rc�
CRED_FILE_ENVr�r�rerXr5r5r5r8rN�s
rNc@s>eZdZdZdZdZdZddgZddd	�Zd
d�Z	dd
�Z
dS)ruzshared-credentials-file�SharedCredentialsrJrK�aws_security_tokenrLNcCs2||_|dur	d}||_|durtjj}||_dS)Nr%)�_creds_filenamerdr��configloader�raw_config_parse�_ini_parser)rcrtr<�
ini_parserr5r5r8re�s
z!SharedCredentialProvider.__init__cCs�z|�|j�}Wn
tyYdSw|j|vrB||j}|j|vrDt�d|j�|�||j|j�\}}|�	|�}t
||||jd�SdSdS)Nz0Found credentials in shared credentials file: %sr�)r�r�r
rdr�rQr�rbr��_get_session_tokenr�r])rc�available_credsr/r r!r"r5r5r8rX�s*�


�
�

��zSharedCredentialProvider.loadcC�$|jD]}||vr||SqdSr3�r�)rcr/�token_envvarr5r5r8r�
�

��z+SharedCredentialProvider._get_session_tokenr�)r�r�r�r]rcr�r�r�rerXr�r5r5r5r8ru�s
	ruc@sBeZdZdZdZdZdZdZddgZdd	d
�Z	dd�Z
d
d�ZdS)rzz0INI based config provider with profile sections.zconfig-file�SharedConfigrJrKr�rLNcCs&||_||_|durtjj}||_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_filenamerdr�r�r:�_config_parser)rcryr<�
config_parserr5r5r8res
	
zConfigProvider.__init__cCs�z|�|j�}Wn
tyYdSw|j|dvrH|d|j}|j|vrFt�d|j�|�||j|j�\}}|�	|�}t
||||jd�SdSdS)zr
        If there is are credentials in the configuration associated with
        the session, use those.
        Nr|z$Credentials found in config file: %sr�)r�r�r
rdr�rQr�rbr�r�r�r])rcr4r}r r!r"r5r5r8rX,s*�
�
�

��
zConfigProvider.loadcCr�r3r�)rcr}�
token_namer5r5r8r�Fr�z!ConfigProvider._get_session_tokenr3)r�r�r�r�r]rcr�r�r�rerXr�r5r5r5r8rzs
rzc@s:eZdZdZdZdZddgZdZdZd
d	d
�Z	dd�Z
dS)rOzboto-config�Boto2Config�BOTO_CONFIGz
/etc/boto.cfgz~/.botorJrKNcCs.|durtj}|durtjj}||_||_dSr3)rr�r�r�r�r�r�)rcr�r�r5r5r8reUs
zBotoProvider.__init__c	Cs�|j|jvr|j|jg}n|j}|D];}z|�|�}Wn	ty%Yqwd|vrN|d}|j|vrNt�d|�|�||j|j	�\}}t
|||jd�SqdS)z;
        Look for credentials in boto config file.
        r�z)Found credentials in boto config file: %sr�N)�BOTO_CONFIG_ENVr��DEFAULT_CONFIG_FILENAMESr�r
r�rQr�rbr�r�r])rc�potential_locationsrr/r�r r!r5r5r8rX]s.�
�
�
���zBotoProvider.loadr�)r�r�r�r]rcr�r�r�r�rerXr5r5r5r8rOLs
rOc@s�eZdZdZdZdZdZdZejddfdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS) rK�assume-roleNr&�web_identity_token_filer#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)	r1rer rd�	_prompterrf�_credential_sourcer�_profile_provider_builder�_visited_profiles)rcr:r;r1r<�prompterr=r>r5r5r8re�s+zAssumeRoleProvider.__init__cCs@|��|_|j�di�}|�|ji�}|�|�r|�|j�SdS�Nr|)rerfrErd�_has_assume_role_config_vars�_load_creds_via_assume_role)rcr|r$r5r5r8rX�s

�zAssumeRoleProvider.loadcCs|j|vo	|j|vSr3)�ROLE_CONFIG_VAR�WEB_IDENTITY_TOKE_FILE_VAR�rcr$r5r5r8r��s
�z/AssumeRoleProvider._has_assume_role_config_varscCs�|�|�}|�||�}i}|�d�}|dur||d<|�d�}|dur'||d<|�d�}|dur4||d<|�d�}|durA||d<t|j||d	||j|jd
�}	|	j}
|dur[t|
�}
t	|j
|
td�S)N�role_session_namer�external_id�
ExternalIdrErArHrCr&)r;r;r&r'r<r1)r�r�r�)�_get_role_config�_resolve_source_credentialsrEr6r r�r1rr�r�r]r�)rcr<�role_configr;r'r�r�rErHr��	refresherr5r5r8r��sB
�



��z.AssumeRoleProvider._load_creds_via_assume_rolecCs|j�di�}||}|�d�}|d}|�d�}|�d�}|�d�}|�d�}	|�d�}
||||	||d	�}|
d
urLzt|
�|d<Wn	tyKYnw|d
ur]|d
ur]td|�d�d
��|d
url|d
urlt|jdd��|d
urx|�||�|S|�||�|S)z?Retrieves and validates the role configuration for the profile.r|�source_profiler&�credential_sourcerEr�r�rH)r&r�rEr�r�r�N�
The profile "z5" contains both source_profile and credential_source.�r�z#source_profile or credential_sourcerY)	rfrEr(�
ValueErrorrrr]�_validate_credential_source�_validate_source_profile)rcr<r|r$r�r&r�rEr�r�rHr�r5r5r8r�sH





�	�
���z#AssumeRoleProvider._get_role_configcCsJ|jdurtd|�d|�d�d��|j�|�s#td|�d|�d�d��dS)NzThe credential_source "z" is specified in profile "z)", but no source provider was configured.r�zThe credential source "z" referenced in profile "z" is not valid.)r�r�is_supported)rc�parent_profiler�r5r5r8r�5s
�����z.AssumeRoleProvider._validate_credential_sourcecCst|�|�|�|�g�Sr3)�any�_has_static_credentialsr�r�r5r5r8�_source_profile_has_credentialsFs
��z2AssumeRoleProvider._source_profile_has_credentialscCsv|j�di�}||vrtd|�d|�d�d��||}||jvr"dS||kr-t||jd��|�|�s9t||jd��dS)Nr|zThe source_profile "z" referenced in the profile "z" does not exist.r�)r��visited_profiles)rfrErr�rr�)rc�parent_profile_name�source_profile_namer|r�r5r5r8r�Ns*��
�

��z+AssumeRoleProvider._validate_source_profilecsddg}t�fdd�|D��S)NrKrJc3s�|]}|�vVqdSr3r5)r��
static_key�r$r5r8�	<genexpr>vs�z=AssumeRoleProvider._has_static_credentials.<locals>.<genexpr>)r�)rcr$�static_keysr5r�r8r�tsz*AssumeRoleProvider._has_static_credentialscCs<|�d�}|dur|�||�S|d}|j�|�|�|�S)Nr�r�)rE� _resolve_credentials_from_sourcer�r[�!_resolve_credentials_from_profile)rcr�r<r�r�r5r5r8r�xs
�
z.AssumeRoleProvider._resolve_source_credentialscCs�|j�di�}||}|�|�r|js|�|�S|�|�s"|�|�sA|jj|dd�}t|�}|��}|dur?d}t	||d��|S|�
|�S)Nr|Tr?z.The source profile "%s" must have credentials.r�)rfrEr�r��(_resolve_static_credentials_from_profiler�rBrSr�rr�)rcr<r|r$r[�
profile_chainr��
error_messager5r5r8r��s4��
�����
z4AssumeRoleProvider._resolve_credentials_from_profilec
CsJzt|d|d|�d�d�WSty$}z	t|jt|�d��d}~ww)NrJrKrLrrY)r�rEr\rr]�str)rcr$r{r5r5r8r��s�
���z;AssumeRoleProvider._resolve_static_credentials_from_profilecCs*|j�|�}|durt|d|��d��|S)Nz@No credentials found in credential_source referenced in profile r�)r�r;r)rcr�r<r�r5r5r8r��s���z3AssumeRoleProvider._resolve_credentials_from_source)r�r�r�r]rcr�r��EXPIRY_WINDOW_SECONDSr:rerXr�r�r�r�r�r�r�r�r�r�r�r5r5r5r8rKys,
�>,1&!rKc@sXeZdZdZdZdddd�Z			ddd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)r{zassume-role-with-web-identityN�AWS_WEB_IDENTITY_TOKEN_FILE�AWS_ROLE_SESSION_NAME�AWS_ROLE_ARN)r�r�r&FcCs:||_||_||_||_d|_||_|durt}||_dSr3)r1rer rd�_profile_config�_disable_env_varsr�_token_loader_cls)rcr:r;r<r1r@�token_loader_clsr5r5r8re�s	
z*AssumeRoleWithWebIdentityProvider.__init__cCrr3)�_assume_role_with_web_identityrnr5r5r8rX�r	z&AssumeRoleWithWebIdentityProvider.loadcCs:|jdur|��}|�di�}|�|ji�|_|j�|�Sr�)r�rerErd)rc�key�
loaded_configr|r5r5r8�_get_profile_config�s

z5AssumeRoleWithWebIdentityProvider._get_profile_configcCs2|jrdS|j�|�}|r|tjvrtj|SdSr3)r��_CONFIG_TO_ENV_VARrErr�)rcr��env_keyr5r5r8�_get_env_config�s
z1AssumeRoleWithWebIdentityProvider._get_env_configcCs |�|�}|dur|S|�|�Sr3)r�r�)rcr��	env_valuer5r5r8�_get_config�s

z-AssumeRoleWithWebIdentityProvider._get_configcCs||�d�}|s	dS|�|�}|�d�}|sd}t|d��i}|�d�}|dur+||d<t|j||||jd�}t|j|jd�S)	Nr�r&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�r�r)r;rPr&r'r1r�)	r�r�rrNr r1r�r]r)rc�
token_path�token_loaderr&r�r'r�r�r5r5r8r��s0


�

�
�z@AssumeRoleWithWebIdentityProvider._assume_role_with_web_identity)NFN)r�r�r�r]rcr�rerXr�r�r�r�r5r5r5r8r{�s �
�r{c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)rMcCr�r3��
_providers�rcrBr5r5r8rerWz'CanonicalNameCredentialSourcer.__init__cCs|dd�|jD�vS)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.
        cS�g|]}|j�qSr5)rc�r�rxr5r5r8r�)�z?CanonicalNameCredentialSourcer.is_supported.<locals>.<listcomp>r�)rc�source_namer5r5r8r�sz+CanonicalNameCredentialSourcer.is_supportedcCs$|�|�}t|t�r|��S|��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_providerr�rSr�rX)rcr�sourcer5r5r8r;+s
	
z1CanonicalNameCredentialSourcer.source_credentialscCsV|�|�}|��dvr |�d�}|dur |dur|St||g�S|dur)t|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�sharedcredentialsr�N��name)�_get_provider_by_canonical_name�lower�_get_provider_by_methodrSr)rc�canonical_namer�rYr5r5r8r9s

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

        This function is strict, it does not attempt to address
        compatibility issues.
        N)r�rcr)rcrr�r
r5r5r8r_s
��z>CanonicalNameCredentialSourcer._get_provider_by_canonical_namecCs"|jD]}|j|kr|SqdS)z0Return a credential provider by its METHOD name.N)r�r])rcr�r�r5r5r8r
ks


��z6CanonicalNameCredentialSourcer._get_provider_by_methodN)	r�r�r�rer�r;rrr
r5r5r5r8rMs
&rMc@s^eZdZdZdZdZdZdZdZddd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�ZdS)rHzcontainer-role�EcsContainer�&AWS_CONTAINER_CREDENTIALS_RELATIVE_URI�"AWS_CONTAINER_CREDENTIALS_FULL_URI�!AWS_CONTAINER_AUTHORIZATION_TOKEN�&AWS_CONTAINER_AUTHORIZATION_TOKEN_FILENcCs,|durtj}|durt�}||_||_dSr3)rr�rr��_fetcher)rcr�r�r5r5r8rezs
zContainerProvider.__init__cCs$|j|jvs|j|jvr|��SdSr3)�ENV_VARr��ENV_VAR_FULL�_retrieve_or_failrnr5r5r8rX�s�zContainerProvider.loadcCsd|��r|j�|j|j�}n|j|j}|�|�}|�}t|d|d|d|jt	|d�|d�S)Nr r!r"r�)r r!r"r�r�r�)
�_provided_relative_urir�full_urlr�rr�_create_fetcherr�r]r�)rc�full_urir�rr5r5r8r�s

�z#ContainerProvider._retrieve_or_failcCs�d}|j|jvr'|j|j}t|��}|��}Wd�n1s!wYn|j|jvr3|j|j}|dur@|�|�d|iSdS)N�
Authorization)�ENV_VAR_AUTH_TOKEN_FILEr��open�read�ENV_VAR_AUTH_TOKEN�_validate_auth_token)rc�
auth_token�auth_token_file_path�
token_filer5r5r8�_build_headers�s

��
�z ContainerProvider._build_headerscCsd|vsd|vrtd��dS)N�
�
z,Auth token value is not a legal header value)r�)rcr"r5r5r8r!�s�z&ContainerProvider._validate_auth_tokencs��fdd�}|S)Nc
svz���}�jj�|d�}Wnty+}ztjd|dd�t�jt|�d��d}~ww|d|d|d|d	d
�S)N)�headersz'Error retrieving container metadata: %sTr�r�r�r��Tokenr�r�)	r%r�retrieve_full_urirrQrRrr]r�)r(r�r{�rrcr5r8�fetch_creds�s&
��
����z6ContainerProvider._create_fetcher.<locals>.fetch_credsr5)rcrr4r�r,r5r+r8r�sz!ContainerProvider._create_fetchercCs|j|jvSr3)rr�rnr5r5r8r�sz(ContainerProvider._provided_relative_urir�)r�r�r�r]rcrrr rrerXrr%r!rrr5r5r5r8rHrs
rHc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)rScCs
||_dS)zQ

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

        NrArr5r5r8re�s
zCredentialResolver.__init__cCsFz
dd�|jD��|�}Wntyt|d��w|j�||�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``
        cSrr5�r]rr5r5r8r��rz4CredentialResolver.insert_before.<locals>.<listcomp>r	N)rB�indexr�r�insert�rcr
�credential_provider�offsetr5r5r8�
insert_before�s
�z CredentialResolver.insert_beforecCs |�|�}|j�|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``
        rqN)�_get_provider_offsetrBr/r0r5r5r8�insert_after�s
zCredentialResolver.insert_aftercCs6dd�|jD�}||vrdS|�|�}|j�|�dS)z�
        Removes a given ``Credentials`` instance from the chain.

        :param name: The short name of the credentials instance to remove.
        :type name: string
        cSrr5r-rr5r5r8r��rz-CredentialResolver.remove.<locals>.<listcomp>N)rBr.�pop)rcr
�available_methodsr2r5r5r8rP�s

zCredentialResolver.removecCs|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.
        )rBr4�rcr
r5r5r8�get_providers
zCredentialResolver.get_providercCs2zdd�|jD��|�WStyt|d��w)NcSrr5r-rr5r5r8r�rz;CredentialResolver._get_provider_offset.<locals>.<listcomp>r	)rBr.r�rr8r5r5r8r4s

�z'CredentialResolver._get_provider_offsetcCs6|jD]}t�d|j�|��}|dur|SqdS)zw
        Goes through the credentials chain, returning the first ``Credentials``
        that could be loaded.
        zLooking for credentials via: %sN)rBrQrRr]rX)rcr�rr5r5r8r�s
�	z#CredentialResolver.load_credentialsN)
r�r�r�rer3r5rPr9r4r�r5r5r5r8rS�srScsDeZdZdZ					d�fdd�	Zdd�Zdd�Zd	d
�Z�ZS)�SSOCredentialFetcherz%Y-%m-%dT%H:%M:%SZNcsB||_||_||_||_||_||_|	|_|
|_t��	||�dSr3)
r �_sso_region�
_role_name�_account_id�
_start_url�
_token_loader�_token_provider�_sso_session_namer�re)rc�	start_url�
sso_regionr��
account_idr;r�r1rr}�sso_session_namer�r5r8re*s
zSSOCredentialFetcher.__init__cCsV|j|jd�}|jr|j|d<n|j|d<tj|ddd�}t|�d����}|�	|�S)r*)�roleName�	accountId�sessionName�startUrlT)�,r
)r,�
separatorsr-)
r<r=rAr>r.r0rr1r2rr3r5r5r8rAs�

z&SSOCredentialFetcher._create_cache_keycCs$|d}tj�|t��}|�|j�S)Ng@�@)r��
fromtimestamprr��_UTC_DATE_FORMAT)rc�timestamp_ms�timestamp_seconds�	timestampr5r5r8�_parse_timestampWsz%SSOCredentialFetcher._parse_timestampcCs�tt|jd�}|jd|d�}|jr|j��}|��j}n|�|j	�d}|j
|j|d�}z
|jdi|��}Wn|j
jyBt��w|d}d|d|d|d	|�|d
�d�d�}|S)z4Get credentials by calling SSO get role credentials.)rQr2�ssorR�accessToken)rFrGrS�roleCredentials�accessKeyId�secretAccessKey�sessionTokenr)r�r�r�r�)�ProviderTyper�Nr5)rr	r;r r@�
load_token�get_frozen_tokenr"r?r>r<r=�get_role_credentials�
exceptions�UnauthorizedExceptionrrQ)rcr/r��initial_token_datar"r�r�r�r5r5r8r]s6�
����	z%SSOCredentialFetcher._get_credentials)NNNNN)	r�r�r�rMrerrQrr�r5r5r�r8r:'s	�r:c@sbeZdZdZej�ej�dddd��ZdZ	dZ
e	e
Z			ddd	�Zd
d�Z
dd
�Zdd�ZdS)r~rR�~z.awsr1)�
sso_role_name�sso_account_id)�
sso_start_urlrCNcCsF|dur	t|j�}||_||_|duri}||_||_||_||_dSr3)r�_SSO_TOKEN_CACHE_DIR�_token_cacher@r1rer rd)rcr:r;r<r1r|r}r5r5r8re�s	

zSSOProvider.__init__cs�|��}|�di�}|j}|�|ji��|�di�}t�fdd�|jD��r(dS|��|�\}}i}g}|j|}	|	D]}
|
|vrH||
||
<q;|�|
�q;|r`d�|�}t	d|�d|��d��|S)	Nr|�sso_sessionsc3s�|]}|�vVqdSr3r5)r��c�r}r5r8r��s�
�z/SSOProvider._load_sso_config.<locals>.<genexpr>r�r�zB" is configured to use SSO but is missing required configuration: r�)
rerErd�all�_PROFILE_REQUIRED_CONFIG_VARS�_resolve_sso_session_reference�_ALL_REQUIRED_CONFIG_VARSr[r�r)rcr�r|r<re�resolved_config�
extra_reqsr/�missing_config_vars�all_required_configs�
config_var�missingr5rgr8�_load_sso_config�s6��

��zSSOProvider._load_sso_configc	Cs�|�d�}|dur
|dfS||vrd|�d�}t|d��|��}||}|��D]#\}}|�||�|krGd|�d||�d|�d	�}t|d��|||<q(|d
fS)N�sso_sessionr5z+The specified sso-session does not exist: "�"r�zThe value for z" is inconsistent between profile (z) and sso-session (z).)rs)rEr�copy�items)	rcr}rerEr�r/r7rp�valr5r5r8rj�s&

���

z*SSOProvider._resolve_sso_session_referencecCs||��}|sdS|d|d|d|d|jt|jd�|jd�}d|vr/|d|d<|j|d	<tdi|��}t|j|j	d
�S)NrbrCr`ra)r1)rBrCr�rDr;r�r1rsrEr}r�r5)
rrr rrdr1r@r:r�r]r)rc�
sso_config�fetcher_kwargs�sso_fetcherr5r5r8rX�s&
�	
�zSSOProvider.loadr�)r�r�r�r]rr�r�r�rcri�_SSO_REQUIRED_CONFIG_VARSrkrerrrjrXr5r5r5r8r~�s ��	
�$r~r�r�)Tr�r:r.�loggingrrrr�r)�collectionsrrur�hashlibr�dateutil.parserr�dateutil.tzrr�botocore.compatr��botocore.configloaderr	r
r�botocore.configr�botocore.exceptionsr
rrrrrrrr�botocore.tokensr�botocore.utilsrrrrrrr�	getLoggerr�rQrr�rFr^rJr�r�r�r�rLr�r�r�r�r�rrr6rNrVrprIrGrNrurzrOrKr{rMrHrSr:r~r5r5r5r8�<module>s�
,$

�
`M
	&*E5
Z�C.J~#.<-JYXQdZ