
    =h                         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e
      Zy)    )
namedtuple)RequestSession)TwilioRestException)urlparse)
HttpClient)Response)ClientValidationJwtValidationPayloadmethodpathquery_stringall_headerssigned_headersbodyc                   D    e Zd ZddgZ	 d	dZ	 	 	 	 	 	 d
dZd Zd Zd Zy)ValidationClientauthorizationhostc                 n    || _         || _        || _        || _        |rt	               | _        yd| _        y)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_connectionss         m/var/www/html/phonemate/phone_mate_backend/venv/lib/python3.12/site-packages/twilio/http/validation_client.py__init__zValidationClient.__init__   s5    $ ',&&$4wy$    Nc	                 J   | j                   xs
 t               }	t        |j                         |||||      }
|	j	                  |
      }d|j
                  vr,d|j
                  vr| j                  |      |j
                  d<   | j                  |      }t        | j                  | j                  | j                  | j                  |      }|j                         |j
                  d<   |	j                  |||      }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responses                  r   r4   zValidationClient.request-   s   6 ,,+')LLNCT7QU
 #227; *222.666/3~~>N/O$$V,!;;<LM!
 @Czz|  !;<<<+   
 H0018==AAr!   c           	          t        |j                        }|j                  }|j                  xs d}t	        |j
                  |||j                  t        j                  |j                  xs 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   r3   r   queryr   r   r%   r   !_ValidationClient__SIGNED_HEADERSr   )r   r4   parsedr   r   s        r   r-   z*ValidationClient._build_validation_payloadf   s_     '++&{{||)r >>%+<<#
 	
r!   c                 V    t        |j                        }t        |j                        S )z Pull the Host out of the request)r   r3   strnetloc)r   r4   r=   s      r   r,   zValidationClient._get_hosty   s    '++&6==!!r!   c                     |j                  dd      }|j                  dk  s|j                  dk\  rt        |j                  dd      y)z
        Validate that a request to the new SSL certificate is successful
        :return: null on success, raise TwilioRestException if the request fails
        GETzhttps://tls-test.twilio.com:443   i,  z"Failed to validate SSL certificateN)r4   r1   r   )r   clientr8   s      r   validate_ssl_certificatez)ValidationClient.validate_ssl_certificate~   sR    
 >>%)JK#%)=)=)D%$$14  *Er!   )T)NNNNNF)	__name__
__module____qualname__r<   r    r4   r-   r,   rE    r!   r   r   r      sA    '0 ?8 7Br
&"
r!   r   N)collectionsr   requestsr   r   twilio.base.exceptionsr   urllib.parser   twilio.httpr   twilio.http.responser	   twilio.jwt.validationr
   r   r   rI   r!   r   <module>rQ      s;    " % 6 ! " ) 5 O xz xr!   