o
    �¨ÊhÛ  ã                   @   sz   d dl mZ d dl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 edg d	¢ƒZG d
d„ de
ƒZdS )é    )Ú
namedtuple)ÚRequestÚSession)ÚTwilioRestException)Úurlparse)Ú
HttpClient)ÚResponse)ÚClientValidationJwtÚValidationPayload©ÚmethodÚpathÚquery_stringÚall_headersÚsigned_headersÚbodyc                   @   sD   e Zd ZddgZddd„Z		ddd	„Zd
d„ Zdd„ Zdd„ ZdS )ÚValidationClientÚauthorizationÚhostTc                 C   s2   || _ || _|| _|| _|rtƒ | _dS d| _dS )a+  
        Build a ValidationClient which signs requests with private_key and allows Twilio to
        validate request has not been tampered with.

        :param str account_sid: A Twilio Account Sid starting with 'AC'
        :param str api_key_sid: A Twilio API Key Sid starting with 'SK'
        :param str credential_sid: A Credential Sid starting with 'CR',
                                   corresponds to public key Twilio will use to verify the JWT.
        :param str private_key: The private key used to sign the Client Validation JWT.
        N)Úaccount_sidÚcredential_sidÚapi_key_sidÚprivate_keyr   Úsession)Úselfr   r   r   r   Úpool_connections© r   úO/var/www/html/env/lib/python3.10/site-packages/twilio/http/validation_client.pyÚ__init__   s
   zValidationClient.__init__NFc	                 C   s¤   | j ptƒ }	t| ¡ |||||d�}
|	 |
¡}d|jvr)d|jvr)|  |¡|jd< |  |¡}t| j	| j
| j| j|ƒ}| ¡ |jd< |	j|||d�}tt|jƒ|jƒS )aØ  
        Make a signed HTTP Request

        :param str method: The HTTP method to use
        :param str url: The URL to request
        :param dict params: Query parameters to append to the URL
        :param dict data: Parameters to go in the body of the HTTP request
        :param dict headers: HTTP Headers to send with the request
        :param tuple auth: Basic Auth arguments
        :param float timeout: Socket/Read timeout for the request
        :param boolean allow_redirects: Whether or not to allow redirects
        See the requests documentation for explanation of all these parameters

        :return: An http response
        :rtype: A :class:`Response <twilio.rest.http.response.Response>` object
        )ÚparamsÚdataÚheadersÚauthÚHostr   zTwilio-Client-Validation)Úallow_redirectsÚtimeout)r   r   r   ÚupperÚprepare_requestr!   Ú	_get_hostÚ_build_validation_payloadr	   r   r   r   r   Úto_jwtÚsendr   ÚintÚstatus_codeÚtext)r   r   Úurlr   r    r!   r"   r%   r$   r   ÚrequestÚprepared_requestÚvalidation_payloadÚjwtÚresponser   r   r   r0   $   s    

ÿýzValidationClient.requestc                 C   s:   t |jƒ}|j}|jpd}t|j|||jtj|j	pdd�S )zÏ
        Extract relevant information from request to build a ClientValidationJWT
        :param PreparedRequest request: request we will extract information from.
        :return: ValidationPayload
        Ú r   )
r   r/   r   Úqueryr
   r   r!   r   Ú!_ValidationClient__SIGNED_HEADERSr   )r   r0   Úparsedr   r   r   r   r   r)   J   s   

úz*ValidationClient._build_validation_payloadc                 C   s   t |jƒ}|jS )z Pull the Host out of the request)r   r/   Únetloc)r   r0   r8   r   r   r   r(   ]   s   
zValidationClient._get_hostc                 C   s2   |  dd¡}|jdk s|jdkrt|jddƒ‚dS )z£
        Validate that a request to the new SSL certificate is successful
        :return: null on success, raise TwilioRestException if the request fails
        ÚGETzhttps://api.twilio.com:8443éÈ   i,  z"Failed to validate SSL certificateN)r0   r-   r   )r   Úclientr4   r   r   r   Úvalidate_ssl_certificateb   s   ÿz)ValidationClient.validate_ssl_certificate)T)NNNNNF)	Ú__name__Ú
__module__Ú__qualname__r7   r   r0   r)   r(   r=   r   r   r   r   r      s    

ÿ&r   N)Úcollectionsr   Úrequestsr   r   Útwilio.base.exceptionsr   Útwilio.compatr   Útwilio.httpr   Útwilio.http.responser   Útwilio.jwt.validationr	   r
   r   r   r   r   r   Ú<module>   s    