CasperSecurity

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

o

��JhQ �
@s|ddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
mZmZmZmZmZmZddlmZddlmZddlmZmZddlmZdd	lmZe��Z d
Z!Gdd�dej"�Z#d
d�Z$de%fdd�Z&d1dd�Z'dd�Z(dd�Z)d1dd�Z*dd�Z+dd�Z,dd�Z-d ed!dfd"d#�Z.d ed$ed%e/d&ee/d!df
d'd(�Z0d)d*�Z1d2d,ee/fd-d.�Z2d/d0�Z3dS)3�N��wraps)�Optional)
�actions�api�daemon�entitlements�event_logger�
exceptions�lock�messages�status�util)�CVE_OR_USN_REGEX)�_is_attached)�
AptProxyScope�setup_apt_proxy)�UAConfig)�
machine_tokenzc	@sJeZdZdefdd�Zdededeedeefdd	�Zd
efdd�Z	d
S)�CLIEnableDisableProgress�
assume_yescCs||_||_dS�N)�is_interactiver)�selfr�r�7/usr/lib/python3/dist-packages/uaclient/cli/cli_util.py�__init__"s
z!CLIEnableDisableProgress.__init__�total_steps�
done_steps�previous_step_message�current_step_messagecCs|dur
t|�dSdSr)�print)rrrrr rrr�progress&s�z!CLIEnableDisableProgress.progress�eventcCs:|dkr
t|�dS|dkrt�||j�st���dSdS)N�info�message_operation)r!r�handle_message_operationsrr
�PromptDeniedError)rr#�payloadrrr�	_on_event1s�z"CLIEnableDisableProgress._on_eventN)
�__name__�
__module__�__qualname__�boolr�intr�strr"r)rrrrr!s���
�rcOsdSrr��args�kwargsrrr�_null_print9sr3�json_outputcCs|rtStSr)r3r!)r4rrr�&create_interactive_only_print_function=sr5c��fdd�}|S)z1Decorator asserting exclusive access to lock filec�t����fdd��}|S)NcsFtj�dd���|d|i|��}Wd�|S1swY|S)N�)�lock_holder�
sleep_time�cfg)r�	RetryLock)r;r1r2�retval)�fr9rr�new_fHs
��z0assert_lock_file.<locals>.wrapper.<locals>.new_fr�r>r?�r9�r>r�wrapperGsz!assert_lock_file.<locals>.wrapperr)r9rCrrAr�assert_lock_fileDs	rDc�t���fdd��}|S)zDecorator asserting root usercst��st����|i|��Sr)r�we_are_currently_rootr
�NonRootUserErrorr0rBrrr?Vszassert_root.<locals>.new_frr@rrBr�assert_rootSsrHcrE)z>Decorator to verify if correct params are used for json formatcsH|s
�|g|�Ri|��S|jdkr|jst����|g|�Ri|��S)N�json)�formatrr
�CLIJSONFormatRequireAssumeYes)�cmd_argsr1r2rBrrr?cs
z&verify_json_format_args.<locals>.new_frr@rrBr�verify_json_format_args`s	rMcr6)z�Decorator asserting attached config.
    :param msg_function: Optional function to generate a custom message
    if raising an UnattachedError
    cr7)NcsRt|�js�rt|dd�}t|dd�}�|||d�nt����|fd|i|��S)N�command��service)rN�
service_namesr;r;)r�is_attached�getattrr
�UnattachedError)r1r;r2rNrQ)r>�raise_custom_error_functionrrr?ws
�z/assert_attached.<locals>.wrapper.<locals>.new_frr@�rUrBrrCvsz assert_attached.<locals>.wrapperr)rUrCrrVr�assert_attachedpsrWcrE)z&Decorator asserting unattached config.cs<t|�jrt��}tj|j�dd�d���|fd|i|��S)N�namerO)�account_namer;)rrRr�get_machine_token_filer
�AlreadyAttachedError�account�get)r1r;r2�machine_token_filerBrrr?�s
�z"assert_not_attached.<locals>.new_frr@rrBr�assert_not_attached�sr_cr6)Ncst����fdd��}|S)Ncs:t|dd�}t�t|�stj|�d���|fd|i|��S)N�security_issuerO)�issue�cmdr;)rS�re�matchrr
�InvalidSecurityIssueIdFormat)r1r;r2r`)rbr>rrr?�s�z@assert_vulnerability_issue_valid.<locals>.wrapper.<locals>.new_frr@�rbrBrrC�s
z1assert_vulnerability_issue_valid.<locals>.wrapperr)rbrCrrfr� assert_vulnerability_issue_valid�srgcCsftj||d�\}}|r|rtjd�|�|d�|�dd��|r(tjd�|�|d��tj|d�|�dd��)z�Raises a custom error for enable/disable commands when unattached.

    Takes into consideration if the services exist or not, and notify the user
    accordingly.)�namesr;z, rO)�
valid_service�	operation�invalid_service�service_msg)rirj)rjrkrl)r�get_valid_entitlement_namesr
�UnattachedMixedServicesError�join�UnattachedValidServicesError�UnattachedInvalidServicesError)rNrQr;�entitlements_found�entitlements_not_foundrrr�&_raise_enable_disable_unattached_error�s(��
��rtr;�returncCs|t�|�}|j}|rt�tjj|d��nt�tj�t	�
�t	�|�t�
|�\}}t
�|�}t�t�|��t��dS)N)�
contract_name)rrZrvr#r$r�ATTACH_SUCCESS_TMPLrJ�ATTACH_SUCCESS_NO_CONTRACT_NAMEr�stop�cleanuprr
�format_tabularr�handle_unicode_characters�process_events)r;r^rv�status_dict�_ret�outputrrr�post_cli_attach�s
�

r��scope�set_key�	set_valuecCsR|tjkr|j}|j}n|tjkr|j}|j}d|vr|}n|}t|||d�dS)zS
    Handles setting part the apt proxies - global and uaclient scoped proxies
    �https)�
http_proxy�https_proxy�proxy_scopeN)r�GLOBAL�global_apt_http_proxy�global_apt_https_proxy�UACLIENT�ua_apt_http_proxy�ua_apt_https_proxyr)r;r�r�r�r�r�rrr�configure_apt_proxy�s
	

�r�cCs`t�gd��}|��s.tj�d�|t|�t��tj�	�t
�d�tj�d�|��rdSdS)N)�|�/�-�\z
{}{}{}g�������?�)�	itertools�cycle�is_set�sys�stdout�writerJ�next�CLEAR_LINE_ANSI_CODE�flush�time�sleep)�stop_spinner�msg�spinnerrrr�run_spinner�s�

�r�rOr�cr6)Ncr7)Ncs�tj��s�|fd|i|��St��}tjt|�fd�}|���|fd|i|��}|��|�	�tj�
dt�tj��|S)Nr;)�targetr1�
)
r�r��isatty�	threading�Event�Threadr��start�setror�r�r�)r1r;r2r��spinner_threadr=)r>r�rrr?�s
�
z,with_spinner.<locals>.wrapper.<locals>.new_frr@�r�rBrrC�szwith_spinner.<locals>.wrapperr)r�rCrr�r�with_spinner�sr�cCst|dkrtjj|tjjS|dkrtjj|tjjS|dkr*tjj|tjjS|dkr8tjj|tjjS|S)N�low�medium�high�critical)r�TxtColor�INFOBLUE�ENDC�
WARNINGYELLOW�ORANGE�FAIL)�priorityrrr�colorize_prioritys�r�r)rO)4r�rcr�r�r��	functoolsr�typingr�uaclientrrrrr	r
rrr
r�'uaclient.api.u.pro.security.fix._commonr�(uaclient.api.u.pro.status.is_attached.v1r�uaclient.aptrr�uaclient.configr�uaclient.filesr�get_event_loggerr#r��AbstractProgressrr3r-r5rDrHrMrWr_rgrtr�r/r�r�r�r�rrrr�<module>sP0

����
�
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