CasperSecurity

Current Path : /lib/python3/dist-packages/uaclient/http/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/uaclient/http/__pycache__/serviceclient.cpython-310.pyc

o

��Jh��@stddlZddlZddlZddlZddlmZmZmZddlm	Z	ddl
mZmZm
Z
mZmZGdd�dejd�ZdS)�N)�Any�Dict�Optional)�	urlencode)�config�http�system�util�versionc@s�eZdZdZdZeejdefdd���Z	dde
ejddfdd�Z
d	d
�Z						dded
e
edejfdd�Zdefdd�Zdede
ejfdd�ZdS)�UAServiceClient�N�returncCsdS)z@String in subclasses, the UAConfig attribute containing base urlN���selfrr�=/usr/lib/python3/dist-packages/uaclient/http/serviceclient.py�cfg_url_base_attrsz!UAServiceClient.cfg_url_base_attr�cfgcCs|s	t��|_dS||_dS�N)r�UAConfigr)rrrrr�__init__s
zUAServiceClient.__init__cCsd�t���ddd�S)NzUA-Client/{}�application/json)z
user-agent�accept�content-type)�formatr
�get_versionrrrr�headerss�zUAServiceClient.headersT�log_response_body�timeoutcCs�|�d�}|s|��}|�d�dkr|rtj|tjd��d�}t�	t
|j|j�|�}|�
|�}	|	r3|	S|rHdd�t|���D�}
|dt|
�7}|durN|n|j}tj||||||d	�S)
N�/rr)�clszutf-8cSsi|]\}}|dur||�qSrr)�.0�k�vrrr�
<dictcomp>>sz/UAServiceClient.request_url.<locals>.<dictcomp>�?)�url�datar�methodrr)�lstripr�get�json�dumpsr	�DatetimeAwareJSONEncoder�encode�	posixpath�join�getattrrr�_get_fake_responses�sorted�itemsr�url_timeoutr�readurl)r�pathr'rr(�query_paramsrrr&�
fake_response�filtered_params�timeout_to_userrr�request_url%s2

�

��zUAServiceClient.request_urlr&cCsf|jdur|j�|g�S|jj�d�}|si|_ntj�|�s#i|_n	t�t	�
|��|_|j�|g�S)a.Return a list of fake response dicts for a given URL.

        serviceclient_url_responses in uaclient.conf should be a path
        to a json file which contains a dictionary keyed by full URL path.
        Each value will be a list of dicts representing each faked response
        for the given URL.

            The response dict item will have a code: <HTTP_STATUS_CODE> and
               response: "some string of content".
            The JSON string below fakes the available_resources URL on the
            contract server:
            '{"https://contracts.canonical.com/v1/resources":                [{"code": 200, "response": {"key": "val1", "key2": "val2"}}]}'

        :return: List of dicts for each faked response matching the url, or
           and empty list when no matching url found.
        N�serviceclient_url_responses)�_response_overlayr*r�features�osr7�existsr+�loadsr�	load_file)rr&�response_overlay_pathrrr�_get_response_overlayMs
��z%UAServiceClient._get_response_overlaycCs�|�|�}|s	dSt|�dkr|d}n|�d�}i}g}|d}t|t�r)|}nt|t�r0|}tj|d|�di�t	j
|ddd�||d	�S)
z7Return response if faked for this URL in uaclient.conf.N�r�response�coderT)�	sort_keys)rHr�body�	json_dict�	json_list)rE�len�pop�
isinstance�dict�listr�HTTPResponser*r+r,)rr&�	responsesrGrKrL�resprrrr2os(





�z#UAServiceClient._get_fake_responsesr)NNNNTN)�__name__�
__module__�__qualname__r5r>�property�abc�abstractmethod�strrrrrrr�bool�intrrRr<rEr2rrrrrs.
���	
�("r)�	metaclass)rYr+r@r/�typingrrr�urllib.parser�uaclientrrrr	r
�ABCMetarrrrr�<module>s
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY