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: //opt/saltstack/salt/lib/python3.10/site-packages/libcloud/common/__pycache__/aws.cpython-310.pyc
o

;j�@�@s�ddlZddlZddlZddlZddlmZmZmZddlmZddl	m	Z	ddl
mZmZm
Z
mZmZmZddlmZmZddlmZmZmZmZddlmZmZzddlZWn
eyeddlZYnwgd	�Zd
Z dZ!d�"�Z#Gd
d�de�Z$Gdd�de$�Z%Gdd�de�Z&Gdd�d�Z'Gdd�de'�Z(Gdd�de'�Z)Gdd�d�Z*Gdd�de&�Z+Gdd�de�Z,d&d d!�Z-d"d#�Z.Gd$d%�d%e�Z/dS)'�N)�Dict�Type�Optional)�sha256)�datetime)�ET�b�httplib�urlquote�
basestring�
_real_unicode)�findall_ignore_namespace�findtext_ignore_namespace)�
BaseDriver�XmlResponse�JsonResponse�ConnectionUserAndKey)�InvalidCredsError�MalformedResponseError)�AWSBaseResponse�AWSGenericResponse�AWSTokenConnection�SignedAWSConnection�AWSRequestSignerAlgorithmV2�AWSRequestSignerAlgorithmV4�	AWSDriver�2zUNSIGNED-PAYLOADa�
"params" dictionary contains an attribute "%s" which value (%s, %s) is not a
string.

Parameters are sent via query parameters and not via request body and as such,
all the values need to be of a simple type (string, int, bool).

For arrays and other complex types, you should use notation similar to this
one:

params['TagSpecification.1.Tag.Value'] = 'foo'
params['TagSpecification.2.Tag.Value'] = 'bar'

See https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Query-Requests.html
for details.
c@seZdZdZdd�ZdS)rNcCs(t|d|jd�}t|d|jd�}||fS)z�
        Parse code and message from the provided error element.

        :return: ``tuple`` with two elements: (code, message)
        :rtype: ``tuple``
        ZCode��element�xpath�	namespace�Message)rr )�selfr�code�message�r%�G/opt/saltstack/salt/lib/python3.10/site-packages/libcloud/common/aws.py�_parse_error_detailsEs
�z$AWSBaseResponse._parse_error_details)�__name__�
__module__�__qualname__r r'r%r%r%r&rBsrc@s$eZdZdZiZdd�Zdd�ZdS)rNcCs|jtjtjtjfvS�N)�statusr	�OK�CREATED�ACCEPTED)r"r%r%r&�success`szAWSGenericResponse.successcCs.|jj}t|j�}|tjkr"|jstt|j�d|j	��t|j��zt
�|j�}Wnty;t
d|j|jjd��w|jrIt||j|jd�}n|g}g}|D]A}|j|d�\}}|j�|d�}	|	duro|�d�||��qPi}
t|	d�r�|	jD]}||vr�|||
|<qy|	d
||jjd�|
���d	�|�S)Nz: zFailed to parse XML)�body�driverr)r�{}: {}�kwargs)�valuer2�
r%)�
connection�context�intr,r	�	FORBIDDENr1r�str�errorrZXML�	Exceptionrr2rr
r r'�
exceptions�get�append�format�hasattrr4�join)r"r8r,r1ZerrsZmsgs�errr#r$ZexceptionCls�params�keyr%r%r&�parse_errorcsB


��
�

�
zAWSGenericResponse.parse_error)r(r)r*rr>r0rGr%r%r%r&rTs
rcsHeZdZ									d	�fdd�	Z�fdd�Z�fdd�Z�ZS)
rTNcs*|	|_t�j||||||||
||d�
dS)N)�secure�host�port�url�timeout�retry_delay�backoff�	proxy_url��token�super�__init__)r"�user_idrFrHrIrJrKrLrOrQrMrN��	__class__r%r&rS�s
�zAWSTokenConnection.__init__c�|jr|j|d<t��|�S�Nzx-amz-security-token)rQrR�add_default_params�r"rErUr%r&rY�s
z%AWSTokenConnection.add_default_paramscrWrX)rQrR�add_default_headers�r"�headersrUr%r&r[�s
z&AWSTokenConnection.add_default_headers)	TNNNNNNNN)r(r)r*rSrYr[�
__classcell__r%r%rUr&r�s�rc@s,eZdZdZdd�Zddd�Zdd	d
�ZdS)
�AWSRequestSignerz@
    Class which handles signing the outgoing AWS requests.
    cCs||_||_||_||_dS)aI
        :param access_key: Access key.
        :type access_key: ``str``

        :param access_secret: Access secret.
        :type access_secret: ``str``

        :param version: API version.
        :type version: ``str``

        :param connection: Connection instance.
        :type connection: :class:`Connection`
        N��
access_key�
access_secret�versionr7)r"rarbrcr7r%r%r&rS�s
zAWSRequestSigner.__init__�GET�/cCs|Sr+r%�r"rE�method�pathr%r%r&�get_request_params�sz#AWSRequestSigner.get_request_paramsNcCs||fSr+r%�r"rEr]rgrh�datar%r%r&�get_request_headers�sz$AWSRequestSigner.get_request_headers�rdre�rdreN)r(r)r*�__doc__rSrirlr%r%r%r&r_�s

r_c@s eZdZddd�Zd	dd�ZdS)
rrdrecCsRd|d<d|d<|j|d<|j|d<t�dt���|d<|j||j|d	�|d
<|S)NrZSignatureVersionZ
HmacSHA256ZSignatureMethodZAWSAccessKeyId�Versionz%Y-%m-%dT%H:%M:%SZZ	Timestamp)rE�
secret_keyrhZ	Signature)rarc�time�strftime�gmtime�_get_aws_auth_paramrbrfr%r%r&ri�s


�z.AWSRequestSignerAlgorithmV2.get_request_paramsc
Cs�|j}t|���}|��g}|D]}t||�}|�t|dd�dt|dd��qd�|�}	|j}
|j	r;|j
dksC|j	sL|j
dkrL|
dt|j
�7}
d	�d
|
||	f�}t�t
jt|�t|�td����}|�d�S)
aU
        Creates the signature required for AWS, per
        http://bit.ly/aR7GaQ [docs.amazonwebservices.com]:

        StringToSign = HTTPVerb + "
" +
                       ValueOfHostHeaderInLowercase + "
" +
                       HTTPRequestURI + "
" +
                       CanonicalizedQueryString <from the preceding step>
        ���safe�=z-_~�&i��P�:r6rd)Z	digestmodzutf-8)r7�list�keys�sortr;r@r
rCrIrHrJ�base64�	b64encode�hmac�newrr�digest�decode)
r"rErqrhr7r~�pairsrFr5�qs�hostname�string_to_signZb64_hmacr%r%r&ru�s&
$
�
�
z/AWSRequestSignerAlgorithmV2._get_aws_auth_paramNrm)re)r(r)r*rirur%r%r%r&r�s
rc@steZdZddd�Zddd�Zddd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zddd�Zdd�Z
dd�ZdS)rrdrecCs|dkr	|j|d<|S)Nrdrp)rcrfr%r%r&ri
s
z.AWSRequestSignerAlgorithmV4.get_request_paramsNcCsHt��}|�d�|d<|�||�|d<|j||||||d�|d<||fS)N�%Y%m%dT%H%M%SZz
X-AMZ-DatezX-AMZ-Content-SHA256�rEr]�dtrgrhrkZ
Authorization)r�utcnowrs�_get_payload_hash�_get_authorization_v4_header)r"rEr]rgrhrk�nowr%r%r&rls
�z/AWSRequestSignerAlgorithmV4.get_request_headersc
CsB|j|d�}|j|d�}|j||||||d�}	d|j|||	d�S)N)r�)r]r�zNAWS4-HMAC-SHA256 Credential=%(u)s/%(c)s, SignedHeaders=%(sh)s, Signature=%(s)s)�u�c�sh�s)�_get_credential_scope�_get_signed_headers�_get_signaturera)
r"rEr]r�rgrhrkZcredentials_scopeZsigned_headersZ	signaturer%r%r&r�s����z8AWSRequestSignerAlgorithmV4._get_authorization_v4_headerc	Cs.|�|�}|j||||||d�}t||dd�S)Nr�T�rF�msg�hex)�_get_key_to_sign_with�_get_string_to_sign�_sign)	r"rEr]r�rgrhrkrFr�r%r%r&r�.s

�z*AWSRequestSignerAlgorithmV4._get_signaturecCs2ttttd|j|�d��|jjj�|jj�d�S)NZAWS4�%Y%m%d�aws4_request)r�rbrsr7r2�region_name�service_name�r"r�r%r%r&r�5s���z1AWSRequestSignerAlgorithmV4._get_key_to_sign_withcCs6|j|||||d�}d�d|�d�|�|�t|�g�S)N�rEr]rgrhrkr6zAWS4-HMAC-SHA256r�)�_get_canonical_requestrCrsr��_hash)r"rEr]r�rgrhrkZcanonical_requestr%r%r&r�As
���z/AWSRequestSignerAlgorithmV4._get_string_to_signcCs"d�|�d�|jjj|jjdg�S)Nrer�r�)rCrsr7r2r�r�r�r%r%r&r�Os��z1AWSRequestSignerAlgorithmV4._get_credential_scopecCs"d�dd�t|��tjd�D��S)N�;cSsg|]}|���qSr%��lower)�.0�kr%r%r&�
<listcomp>ZszCAWSRequestSignerAlgorithmV4._get_signed_headers.<locals>.<listcomp>�rF)rC�sortedr~r;r�r\r%r%r&r�Ys"z/AWSRequestSignerAlgorithmV4._get_signed_headerscCs(d�dd�t|��dd�d�D��dS)Nr6cSs*g|]\}}d�|��t|���g��qS)r|)rCr�r;�strip�r�r��vr%r%r&r�_s��zFAWSRequestSignerAlgorithmV4._get_canonical_headers.<locals>.<listcomp>cSs|d��S)Nrr�)r�r%r%r&�<lambda>aszDAWSRequestSignerAlgorithmV4._get_canonical_headers.<locals>.<lambda>r��rCr��itemsr\r%r%r&�_get_canonical_headers\s����z2AWSRequestSignerAlgorithmV4._get_canonical_headerscCsD|turtS|dvr|rt|d�st|d�rtSt|�StStd�S)N)�POST�PUT�next�__next__rv)�UnsignedPayloadSentinel�UNSIGNED_PAYLOADrBr�)r"rgrkr%r%r&r�gsz-AWSRequestSignerAlgorithmV4._get_payload_hashcCsd�dd�t|���D��S)Nrzc	Ss0g|]\}}d�t|dd�tt|�dd���qS)z{}={}rvrw�~)rAr
r;r�r%r%r&r�xs��zCAWSRequestSignerAlgorithmV4._get_request_params.<locals>.<listcomp>r�rZr%r%r&�_get_request_paramsus

��z/AWSRequestSignerAlgorithmV4._get_request_paramscCs0d�|||�|�|�|�|�|�|�||�g�S)Nr6)rCr�r�r�r�rjr%r%r&r�~s
��z2AWSRequestSignerAlgorithmV4._get_canonical_requestrmrnr+)r(r)r*rirlr�r�r�r�r�r�r�r�r�r�r%r%r%r&rs





	rc@seZdZdS)r�N)r(r)r*r%r%r%r&r��sr�c
sFeZdZdZdddddddddef
�fdd�	Zdd�Zdd�Z�ZS)	rNTc

stt�j||||||||	|
||d�t|�|_|jdkrt}
n|jdkr&t}
ntd|��|
|j|j|j	|d�|_
dS)N)rTrFrHrIrJrKrLrQrMrNrOr�4z!Unsupported signature_version: %sr`)rRrSr;�signature_versionrr�
ValueErrorrTrFrc�signer)r"rTrFrHrIrJrKrLrOrQrMrNr�Z
signer_clsrUr%r&rS�s2�


�zSignedAWSConnection.__init__cCsX|jj||j|jd�}|��D]\}}t|tttt	f�s)t
||t|�f}t|��q|S)N)rErgrh)
r�rirg�actionr��
isinstancerrr9�bool�PARAMS_NOT_STRING_ERROR_MSG�typer�)r"rErFr5r�r%r%r&rY�s�z&SignedAWSConnection.add_default_paramscCs(|jj|||j|j|jd�\}}||fS)Nr�)r�rlrgr�rk)r"rEr]r%r%r&�pre_connect_hook�s
�z$SignedAWSConnection.pre_connect_hook)	r(r)r*rc�DEFAULT_SIGNATURE_VERSIONrSrYr�r^r%r%rUr&r�s�,
rc@seZdZdZdd�ZdS)�AWSJsonResponsezU
    Amazon ECS response class.
    ECS API uses JSON unlike the s3, elb drivers
    cCs0t�|j�}|d}|�d|d�}d�||�S)NZ__typer!r$r3)�json�loadsr1r?rA)r"�responser#r$r%r%r&rG�szAWSJsonResponse.parse_errorN)r(r)r*rorGr%r%r%r&r��sr�FcCs<|rt�t|�t|�tj���St�t|�t|�tj���Sr+)r�r�r�hashlibr�	hexdigestr�r�r%r%r&r��sr�cCst�t|����Sr+)r�rrr�)r�r%r%r&r��sr�cs8eZdZ							d�fdd�	Z�fdd�Z�ZS)rNTc	

s.||_t�j|f|||||||d�|	��dS)N)�secretrHrIrJ�api_version�regionrQrP)
r"rFr�rHrIrJr�r�rQr4rUr%r&rS�s��	
�zAWSDriver.__init__cst���}|j|d<|S)NrQ)rR�_ex_connection_class_kwargsrQ)r"r4rUr%r&r�s

z%AWSDriver._ex_connection_class_kwargs)NTNNNNN)r(r)r*rSr�r^r%r%rUr&r�s�r)F)0r�rrr�r��typingrrrrrZlibcloud.utils.py3rrr	r
rrZlibcloud.utils.xmlr
rZlibcloud.common.baserrrrZlibcloud.common.typesrrZ
simplejsonr��ImportError�__all__r�r�r�r�rrrr_rrr�rr�r�r�rr%r%r%r&�<module>sD �
�>* 0G