HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/botocore/__pycache__/tokens.cpython-310.pyc
o

*we�*�@sddlZddlZddlZddlZddlmZmZddlmZmZddl	Z
ddlmZddl
mZddlmZddlmZddlmZmZmZdd	lmZmZmZe�e�Zd
d�Zdd
�Zdd�Z dd�Z!Gdd�de�Z"Gdd�d�Z#Gdd�d�Z$Gdd�d�Z%dS)�N)�datetime�	timedelta)�
NamedTuple�Optional)�tzutc)�UNSIGNED)�
total_seconds)�Config)�ClientError�InvalidConfigError�TokenRetrievalError)�CachedProperty�
JSONFileCache�SSOTokenLoadercCst�t��S�N)r�nowr�rr�H/home/arjun/projects/env/lib/python3.10/site-packages/botocore/tokens.py�_utc_now$srcCst|�g}t|d�S)N)�	providers)�SSOTokenProvider�TokenProviderChain)�sessionrrrr�create_token_resolver(s�
rcCst|t�r
|�d�S|S)Nz%Y-%m-%dT%H:%M:%SZ)�
isinstancer�strftime��objrrr�_serialize_utc_timestamp/s

rcCstj|td�S)N)�default)�json�dumpsrrrrr�_sso_json_dumps5sr"c@s&eZdZUeed<dZeeed<dS)�FrozenAuthToken�tokenN�
expiration)�__name__�
__module__�__qualname__�str�__annotations__r%rrrrrrr#9s
r#c@sLeZdZdZdZdZefdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�ZdS)�DeferredRefreshableToken�iX�<cCs,||_||_||_t��|_d|_d|_dSr)�
_time_fetcher�_refresh_using�method�	threading�Lock�
_refresh_lock�
_frozen_token�
_next_refresh)�selfr0�
refresh_using�time_fetcherrrr�__init__Gs

z!DeferredRefreshableToken.__init__cCs|��|jSr)�_refreshr4�r6rrr�get_frozen_tokenQsz)DeferredRefreshableToken.get_frozen_tokencCsN|��}|sdS|dk}|j�|�r%z|��W|j��dS|j��wdS)N�	mandatory)�_should_refreshr3�acquire�_protected_refresh�release)r6�refresh_type�block_for_refreshrrrr:Us
�z!DeferredRefreshableToken._refreshcCs�|��}|sdSz|��}|t|jd�|_|��|_Wnty2tj	d|dd�|dkr0�Ynw|�
�r>t|jdd��dS)N��secondsz5Refreshing token failed during the %s refresh period.T��exc_infor=z$Token has expired and refresh failed)�provider�	error_msg)
r>r.r�_attempt_timeoutr5r/r4�	Exception�logger�warning�_is_expiredrr0)r6rBrrrrr@cs.���
��z+DeferredRefreshableToken._protected_refreshcCs.|jdurdS|jj}t||���}|dkS)NFr)r4r%rr.)r6r%�	remainingrrrrNs

z$DeferredRefreshableToken._is_expiredcCsd|jdurdS|jj}|durdS|��}||jkrdSt||�}||jkr)dS||jkr0dSdS)Nr=�advisory)r4r%r.r5r�_mandatory_refresh_timeout�_advisory_refresh_timeout)r6r%rrOrrrr>�s



z(DeferredRefreshableToken._should_refreshN)
r&r'r(rRrQrJrr9r<r:r@rNr>rrrrr+>s
r+c@seZdZddd�Zdd�ZdS)rNcCs|durg}||_dSr)�
_providers)r6rrrrr9�s
zTokenProviderChain.__init__cCs(|jD]}|��}|dur|SqdSr)rS�
load_token)r6rHr$rrrrT�s
�zTokenProviderChain.load_tokenr)r&r'r(r9rTrrrrr�s
rc@s�eZdZdZdZej�ej�dddd��Z	ddgZ
dZeZ
d	ed	fd
d�Zdd
�Zedd��Zedd��Zdd�Zdd�Zdd�Zdd�Zd	S)r�ssor,�~z.aws�cache�
sso_start_url�
sso_region�
refresh_tokenNcCsR||_|dur|j|jtd�}||_||_t|jd�|_|p%|j�d�p%d|_	dS)N)�
dumps_func)rW�profiler)
�_session�DEFAULT_CACHE_CLS�_SSO_TOKEN_CACHE_DIRr"�_now�_cacher�
_token_loader�get_config_variable�
_profile_name)r6rrWr8�profile_namerrrr9�s�
��zSSOTokenProvider.__init__c
Cs�|jj}|�di�}|�di�}|�|ji�}d|vrdS|d}|�|d�}|s8d|j�d|�d�}t|d��g}|jD]}	|	|vrH|�|	�q=|rZd|j�d|�d	�}t|d��||d
|dd�S)
N�profiles�sso_sessions�sso_sessionz
The profile "z7" is configured to use the SSO token provider but the "z+" sso_session configuration does not exist.)rIzZ" is configured to use the SSO token provider but is missing the following configuration: �.rYrX)�session_namerYrX)r]�full_config�getrdr�_SSO_CONFIG_VARS�append)
r6�
loaded_configrfrg�profile_config�sso_session_name�
sso_configrI�missing_configs�varrrr�_load_sso_config�s:
��


�
��
�z!SSOTokenProvider._load_sso_configcCs|��Sr)rur;rrr�_sso_config�szSSOTokenProvider._sso_configcCs"t|jdtd�}|jjd|d�S)NrY)�region_name�signature_versionzsso-oidc)�config)r	rvrr]�
create_client)r6ryrrr�_client�s
�zSSOTokenProvider._clientcCs�|jj|j|d|d|dd�}t|dd�}|jd|jd|d	|��||d|d|d
d�}d|vr>|d|d<t�d�|S)
N�clientId�clientSecret�refreshToken)�	grantTyper|r}r~�	expiresInrDrXrY�accessToken�registrationExpiresAt)�startUrl�regionr��	expiresAtr|r}r�zSSO Token refresh succeeded)r{�create_token�_GRANT_TYPErrvr`rL�info)r6r$�response�
expires_in�	new_tokenrrr�_attempt_create_token�s&�
�

z&SSOTokenProvider._attempt_create_tokencs�d}�fdd�|D�}|rd|��}t�|�dStj��d�}t||���dkr5t�d|���dSz|���WStyLtj	dd	d
�YdSw)N)r~r|r}r�csg|]}|�vr|�qSrr)�.0�k�r$rr�
<listcomp>sz:SSOTokenProvider._refresh_access_token.<locals>.<listcomp>z+Unable to refresh SSO token: missing keys: r�rz"SSO token registration expired at z SSO token refresh attempt failedTrF)
rLr��dateutil�parser�parserr`r�r
rM)r6r$�keys�missing_keys�msg�expiryrr�r�_refresh_access_tokens 

�z&SSOTokenProvider._refresh_access_tokencCs�|jd}|jd}t�d|���|j||d�}tj�|d�}t�d|���t||�	��}||j
krN|�|�}|durN|}|d}|jj|||d�t
|d|d�S)	NrXrjzLoading cached SSO token for )rjr�zCached SSO token expires at r�)r%)rvrLr�rbr�r�r��debugrr`�_REFRESH_WINDOWr��
save_tokenr#)r6�	start_urlrj�
token_dictr%rO�new_token_dictrrr�
_refresher.s$



��zSSOTokenProvider._refreshercCs"|jdurdSt|j|j|jd�S)N)r8)rvr+�METHODr�r`r;rrrrTDs

�zSSOTokenProvider.load_token)r&r'r(r�r��os�path�
expanduser�joinr_rmr�rr^rr9rur
rvr{r�r�r�rTrrrrr�s,��
�'

r)&r �loggingr�r1rr�typingrr�dateutil.parserr��dateutil.tzr�botocorer�botocore.compatr�botocore.configr	�botocore.exceptionsr
rr�botocore.utilsr
rr�	getLoggerr&rLrrrr"r#r+rrrrrr�<module>s,
a