
    E0j                         d dl Z d dlZd dlZd dlmZmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d
edefdZ G d de          ZdS )    N)urlparseparse_qs)CredentialsRefreshResultRefreshCachedSupplier)HttpOptions)TeaCore)ICredentialsProvider)	auth_util)parameter_helper)CredentialException
expirationreturnc                     | dk     r5t          t          j        t          j                                        dz   S | dz
  S )Nr   i  i  )inttimemktime	localtime)r   s    m/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/alibabacloud_credentials/provider/uri.py_get_stale_timer      s;    A~~4;t~//0011G;;    c                       e Zd ZdZdZdddddededefd	Zd
efdZ	d
efdZ
d
ee         fdZd
ee         fdZd
efdZdS )URLCredentialsProvideri  i'  Nhttp)uriprotocolhttp_optionsr   r   r   c                   |pt           j        | _        | j        | j        dk    rt          d          || _        ||nt                      | _        | j        j        | j        j        nt          j	        | j        j
        | j        j
        nt          j        | j        j        d| _        t          | j        | j                  | _        d S )N zIuri or environment variable ALIBABA_CLOUD_CREDENTIALS_URI cannot be empty)connectTimeoutreadTimeout
httpsProxy)refresh_callablerefresh_callable_async)auenvironment_credentials_uri_uri
ValueError	_protocolr   _http_optionsconnect_timeoutr   DEFAULT_CONNECT_TIMEOUTread_timeoutDEFAULT_READ_TIMEOUTproxy_runtime_optionsr   _refresh_credentials_refresh_credentials_async_credentials_cache)selfr   r   r   s       r   __init__zURLCredentialsProvider.__init__   s    
 929	9	Rhiii!-9-E\\;==DHDVDfDrd0@@  yO  yg>B>P>]>i4-::  pF  p[,2!
 !

 #8!6#'#B#
 #
 #
r   r   c                 4    | j                                         S N)r3   
_sync_callr4   s    r   get_credentialsz&URLCredentialsProvider.get_credentials.   s    &11333r   c                 D   K   | j                                          d {V S r7   )r3   _async_callr9   s    r   get_credentials_asyncz,URLCredentialsProvider.get_credentials_async1   s-      ,88:::::::::r   c           
         t          | j                  }t          j                    }|j        |j        d<   |j        |_        |j        p| j        pd|_	        d|_
        |j        |_        t          |j                                                  D ]\  }}|D ]}||j        |<   t!          j        || j                  }|j        dk    rGt)          d| j         dt+          |j                   d|j                            d                     |j                            d          }t1          j        |          }|                    d	          }	|	d
k    sd|vsd|vsd|vsd|vr2t)          d| j         d|j                            d                     t7          j        |                    d          d          }
t;          j        |
          }t?          |                    d          |                    d          |                    d          ||                                            }tC          |tE          |                    S Nhostr   GET   z"error refreshing credentials from z,  http_code=z
, result: zutf-8CodeSuccessAccessKeyIdAccessKeySecretSecurityToken
Expirationz"error retrieving credentials from z	 result: z%Y-%m-%dT%H:%M:%SZ)access_key_idaccess_key_secretsecurity_tokenr   provider_name)value
stale_time)#r   r'   phget_new_requesthostnameheadersportschemer)   r   methodpathpathnamer   queryitemsr	   	do_actionr0   status_coder   strbodydecodejsonloadsgetr   strptimecalendartimegmr   get_provider_namer   r   r4   rtea_requestkeyvaluesrM   responser]   diccontent_code
time_arrayr   credentialss                r   r1   z+URLCredentialsProvider._refresh_credentials4   s   TY(**&'jF#6 xC4>CV" v#AG,,2244 	/ 	/KC / /).!#&&/ $[$2GHH3&&% RTY  R  RSQYQeMfMf  R  Rrzr  sG  sG  HO  sP  sP  R  RS S S }##G,,jwwv9$$S(@(@DU]`D`D`ds{~d~d~  CO  WZ  CZ  CZ%hTYhhI]I]^eIfIfhhj j j ]377<#8#8:NOO
_Z00
!''-00!gg&78877?33!0022
 
 
 ;(7
(C(CE E E 	Er   c           
        K   t          | j                  }t          j                    }|j        |j        d<   |j        |_        |j        p| j        pd|_	        d|_
        |j        |_        t          |j                                                  D ]\  }}|D ]}||j        |<   t!          j        || j                   d {V }|j        dk    rGt)          d| j         dt+          |j                   d|j                            d                     |j                            d          }t1          j        |          }|                    d	          }	|	d
k    sd|vsd|vsd|vsd|vr2t)          d| j         d|j                            d                     t7          j        |                    d          d          }
t;          j        |
          }t?          |                    d          |                    d          |                    d          ||                                            }tC          |tE          |                    S r?   )#r   r'   rO   rP   rQ   rR   rS   rT   r)   r   rU   rV   rW   r   rX   rY   r	   async_do_actionr0   r[   r   r\   r]   r^   r_   r`   ra   r   rb   rc   rd   r   re   r   r   rf   s                r   r2   z1URLCredentialsProvider._refresh_credentials_async]   s     TY(**&'jF#6 xC4>CV" v#AG,,2244 	/ 	/KC / /).!#&&/ !0d>STTTTTTTT3&&% RTY  R  RSQYQeMfMf  R  Rrzr  sG  sG  HO  sP  sP  R  RS S S }##G,,jwwv9$$S(@(@DU]`D`D`ds{~d~d~  CO  WZ  CZ  CZ%hTYhhI]I]^eIfIfhhj j j ]377<#8#8:NOO
_Z00
!''-00!gg&78877?33!0022
 
 
 ;(7
(C(CE E E 	Er   c                     dS )Ncredential_uri r9   s    r   re   z(URLCredentialsProvider.get_provider_name   s    r   )__name__
__module____qualname__r,   r.   r\   r   r5   r   r:   r=   r   r1   r2   re   rt   r   r   r   r      s        "  !!'-1
 
 


  +
 
 
 
*4 4 4 4 4;[ ; ; ; ;'EmK&@ 'E 'E 'E 'ER'E-2L 'E 'E 'E 'ER 3            r   r   )rc   r_   r   urllib.parser   r   -alibabacloud_credentials.provider.refreshabler   r   r   alibabacloud_credentials.httpr   Tea.corer	   alibabacloud_credentials_apir
   alibabacloud_credentials.utilsr   r%   r   rO   #alibabacloud_credentials.exceptionsr   r   r   r   rt   r   r   <module>r      s#      + + + + + + + + k k k k k k k k k k 5 5 5 5 5 5       = = = = = = : : : : : : A A A A A A C C C C C C           r  r  r  r  r 1 r  r  r  r  r r   