CasperSecurity

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

o

��Jh�	@s�ddlZddlZddlmZmZmZddlmZmZm	Z	m
Z
mZmZm
Z
mZdZgd�ZdZdZdZd	Ze	��Ze�e�e��Zed
defdefd
efdefdefg�Zdefdd�Zdefdd�Z			d0deedeedeee ddfdd�Z!	d1dedeee ddfdd�Z"dedeefdd�Z#deefd d!�Z$d"d#�Z%d$ej&fd%d&�Z'		'd2d(edeed)efd*d+�Z(d(efd,d-�Z)d(edefd.d/�Z*dS)3�N)�List�
NamedTuple�Optional)�api�apt�event_logger�
exceptions�http�messages�system�utilz
/usr/bin/snap)g�?g�?g@z
proxy.httpzproxy.httpsz/run/snapd.socketz/v2/snaps/{}�SnapPackage�name�version�revision�channel�	publisher�returncCsdt��vS)z(Returns whether or not snap is installed�snapd)r�get_installed_packages_names�rr�//usr/lib/python3/dist-packages/uaclient/snap.py�is_snapd_installed'srcCstdd�t�D��S)z3Returns whether or not snapd is installed as a snapcss�|]}|jdkVqdS)rN�r)�.0�snaprrr�	<genexpr>.s�z/is_snapd_installed_as_a_snap.<locals>.<genexpr>)�any�get_installed_snapsrrrr�is_snapd_installed_as_a_snap,sr�
http_proxy�https_proxy�retry_sleepscCsxt�s
t�d�dS|s|rt�tjjdd��|r(tj	dddd�|�g|d�|r:tj	dddd	�|�g|d�dSdS)
a
    Configure snap to use http and https proxies.

    :param http_proxy: http proxy to be used by snap. If None, it will
                       not be configured
    :param https_proxy: https proxy to be used by snap. If None, it will
                        not be configured
    :param retry_sleeps: Optional list of sleep lengths to apply between
        retries. Specifying a list of [0.5, 1] tells subp to retry twice
        on failure; sleeping half a second before the first retry and 1 second
        before the second retry.
    z6Skipping configure snap proxy. snapd is not installed.Nr)�service�setrz
proxy.http={}�r"zproxy.https={})
r�LOG�debug�event�infor
�SETTING_SERVICE_PROXY�formatr�subp)r r!r"rrr�configure_snap_proxy1s 
�
��r-�
protocol_typecCs4t�s
t�d�dStjdddd�|�g|d�dS)a�
    Unset snap configuration settings for http and https proxies.

    :param protocol_type: String either http or https
    :param retry_sleeps: Optional list of sleep lengths to apply between
        retries. Specifying a list of [0.5, 1] tells subp to retry twice
        on failure; sleeping half a second before the first retry and 1 second
        before the second retry.
    z8Skipping unconfigure snap proxy. snapd is not installed.Nr�unsetrzproxy.{}r%)rr&r'rr,r+)r.r"rrr�unconfigure_snap_proxyVs

�r0�keycCs8zt�ddd|g�\}}|��WStjyYdSw)z�
    Gets the config value from snap.
    :param protocol: can be any valid snap config option
    :return: the value of the snap config option, or None if not set
    r�getrN)rr,�stripr�ProcessExecutionError)r1�out�_rrr�get_config_option_valueks
�r7cCsRt�gd��\}}|��}|dd�}g}|D]}|��d}|�t|��q|S)N)r�listz--color�neverz	--unicoder9�r)rr,�
splitlines�split�append�
get_snap_info)r5r6�apps�snaps�linerrrrrxs�rc
Cs�t�tjjdd��z	t�t���Wntj	y.}zt
�dt|��WYd}~nd}~wwz
t
jgd�tjd�WdStjyHt���w)Nzstandard Ubunturz<Trying to install snapd. Ignoring apt-get update failure: %s)zapt-get�installz--assume-yesrr%)r(r)r
�APT_UPDATING_LISTr+r�update_sources_list�get_system_sources_filer�UbuntuProErrorr&r'�strrr,�APT_RETRIESr4�CannotInstallSnapdError)�errr�
install_snapd�s$�����rK�progressc
Csvztjtdddgdd�WdStjy:}zt�dt|����r.t	�
d�|�dtj
�n�WYd}~dSd}~ww)	N�waitrzseed.loadedT��capturezunknown command .*waitz9Detected version of snapd that does not have wait commandr))rr,�SNAP_CMDrr4�re�searchrG�lowerr&�warning�emitr
�SNAPD_DOES_NOT_HAVE_WAIT_CMD)rLrJrrr�run_snapd_wait_cmd�s����rWFr�classic_confinement_supportcCs@td|g}|r|dg7}|r|d�|�g7}tj|dtd�dS)NrBz	--classicz--channel={}T)rOr")rPr+rr,�SNAP_INSTALL_RETRIES)rrrX�cmdrrr�install_snap�s


�r[cCstjtd|gdd�dS)N�refreshTrN)rr,rP�rrrr�refresh_snap�sr^c	Cs�t�|�}z5t�td|�}|jdkr9|jdkr)|j�di��d�dkr)tj	|d��|j�di��d�}tj
|d	��WntyEt���w|j�di�}t
|�d
d�|�dd�|�d
d�|�dd�|�di��dd�d�S)N�GET��i��result�kindzsnap-not-foundr]�message)�errorr�rrrr�username)rrrrr)�SNAPD_SNAPS_APIr+r	�unix_socket_request�SNAPD_SOCKET_PATH�code�	json_dictr2r�SnapNotInstalledError�UnexpectedSnapdAPIError�ConnectionRefusedError�SnapdAPIConnectionRefusedr
)r�url�resp�	error_msg�	snap_inforrrr>�s.


���



�r>)NNN)N)NF)+�loggingrQ�typingrrr�uaclientrrrrr	r
rrrPrY�HTTP_PROXY_OPTION�HTTPS_PROXY_OPTIONrirg�get_event_loggerr(�	getLogger�replace_top_level_logger_name�__name__r&rGr
�boolrr�floatr-r0r7rrK�ProgressWrapperrWr[r^r>rrrr�<module>st(�����
�
�&��
�
�
���
�
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