HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/uaclient/cli/__pycache__/cli_util.cpython-38.pyc
U

��JhQ �@srddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
mZmZmZmZmZmZddlmZddlmZddlmZmZddlmZdd	lmZe��Z d
Z!Gdd�dej"�Z#d
d�Z$e%d�dd�Z&d.dd�Z'dd�Z(dd�Z)d/dd�Z*dd�Z+dd�Z,dd�Z-edd �d!d"�Z.eee/ee/dd#�d$d%�Z0d&d'�Z1d0ee/d)�d*d+�Z2d,d-�Z3dS)1�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@sDeZdZed�dd�Zeeeeeed�dd�Zed�dd	�Z	d
S)�CLIEnableDisableProgress)�
assume_yescCs||_||_dS�N)Zis_interactiver)�selfr�r�7/usr/lib/python3/dist-packages/uaclient/cli/cli_util.py�__init__"sz!CLIEnableDisableProgress.__init__)�total_steps�
done_steps�previous_step_message�current_step_messagecCs|dk	rt|�dSr)�print)rrrrrrrr�progress&sz!CLIEnableDisableProgress.progress)�eventcCs4|dkrt|�n|dkr0t�||j�s0t���dS)N�infoZmessage_operation)r rZhandle_message_operationsrr
ZPromptDeniedError)rr"Zpayloadrrr�	_on_event1s

z"CLIEnableDisableProgress._on_eventN)
�__name__�
__module__�__qualname__�boolr�intr�strr!r$rrrrr!s�rcOsdSrr��args�kwargsrrr�_null_print9sr.�Zjson_outputcCs|rtStSdSr)r.r r/rrr�&create_interactive_only_print_function=sr0cs�fdd�}|S)z1Decorator asserting exclusive access to lock filecst����fdd��}|S)Nc	s0tj�dd���|d|i|��}W5QRX|S)N�)�lock_holderZ
sleep_time�cfg)rZ	RetryLock)r3r,r-�retval)�fr2rr�new_fHsz0assert_lock_file.<locals>.wrapper.<locals>.new_fr�r5r6�r2�r5r�wrapperGsz!assert_lock_file.<locals>.wrapperr)r2r:rr8r�assert_lock_fileDs	r;cst���fdd��}|S)zDecorator asserting root usercs t��st���n
�||�SdSr)rZwe_are_currently_rootr
ZNonRootUserErrorr+r9rrr6Vs
zassert_root.<locals>.new_frr7rr9r�assert_rootSsr<cst���fdd��}|S)z>Decorator to verify if correct params are used for json formatcsB|s�|f|�|�S|jdkr.|js.t���n�|f|�|�SdS)NZjson)�formatrr
ZCLIJSONFormatRequireAssumeYes)Zcmd_argsr,r-r9rrr6cs

z&verify_json_format_args.<locals>.new_frr7rr9r�verify_json_format_args`s	r>cs�fdd�}|S)z�Decorator asserting attached config.
    :param msg_function: Optional function to generate a custom message
    if raising an UnattachedError
    cst����fdd��}|S)NcsRt|�js>�r6t|dd�}t|dd�}�|||d�nt����|fd|i|��S)N�command��service)r?�
service_namesr3r3)r�is_attached�getattrr
ZUnattachedError)r,r3r-r?rB)r5�raise_custom_error_functionrrr6ws
�z/assert_attached.<locals>.wrapper.<locals>.new_frr7�rEr9rr:vsz assert_attached.<locals>.wrapperr)rEr:rrFr�assert_attachedpsrGcst���fdd��}|S)z&Decorator asserting unattached config.cs<t|�jr(t��}tj|j�dd�d���|fd|i|��S)N�namer@)Zaccount_namer3)rrCr�get_machine_token_filer
ZAlreadyAttachedErrorZaccount�get)r,r3r-�machine_token_filer9rrr6�s
�z"assert_not_attached.<locals>.new_frr7rr9r�assert_not_attached�srLcs�fdd�}|S)Ncst����fdd��}|S)Ncs:t|dd�}t�t|�s&tj|�d���|fd|i|��S)N�security_issuer@)Zissue�cmdr3)rD�re�matchrr
ZInvalidSecurityIssueIdFormat)r,r3r-rM)rNr5rrr6�s�z@assert_vulnerability_issue_valid.<locals>.wrapper.<locals>.new_frr7�rNr9rr:�s
z1assert_vulnerability_issue_valid.<locals>.wrapperr)rNr:rrQr� assert_vulnerability_issue_valid�srRcCsntj||d�\}}|r:|r:tjd�|�|d�|�dd��n0|rTtjd�|�|d��ntj|d�|�dd��dS)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.)�namesr3z, r@)�
valid_service�	operation�invalid_service�service_msg)rTrU)rUrVrWN)rZget_valid_entitlement_namesr
ZUnattachedMixedServicesError�joinZUnattachedValidServicesErrorZUnattachedInvalidServicesError)r?rBr3Zentitlements_foundZentitlements_not_foundrrr�&_raise_enable_disable_unattached_error�s*����rY)r3�returncCs|t�|�}|j}|r*t�tjj|d��nt�tj�t	�
�t	�|�t�
|�\}}t
�|�}t�t�|��t��dS)N)�
contract_name)rrIr[r"r#rZATTACH_SUCCESS_TMPLr=ZATTACH_SUCCESS_NO_CONTRACT_NAMEr�stopZcleanuprr
Zformat_tabularrZhandle_unicode_charactersZprocess_events)r3rKr[Zstatus_dictZ_ret�outputrrr�post_cli_attach�s
�

r^)r3�scope�set_key�	set_valuerZcCsR|tjkr|j}|j}n|tjkr.|j}|j}d|kr<|}n|}t|||d�dS)zS
    Handles setting part the apt proxies - global and uaclient scoped proxies
    Zhttps)�
http_proxy�https_proxyZproxy_scopeN)rZGLOBALZglobal_apt_http_proxyZglobal_apt_https_proxyZUACLIENTZua_apt_http_proxyZua_apt_https_proxyr)r3r_r`rarbrcrrr�configure_apt_proxy�s	

�rdcCsZt�ddddg�}|��sVtj�d�|t|�t��tj�	�t
�d�tj�d�qdS)N�|�/�-�\z
{}{}{}g�������?�)�	itertools�cycleZis_set�sys�stdout�writer=�next�CLEAR_LINE_ANSI_CODE�flush�time�sleep)�stop_spinner�msgZspinnerrrr�run_spinner�s�

rvr@�rucs�fdd�}|S)Ncst����fdd��}|S)Ncs�tj��s�|fd|i|��St��}tjt|�fd�}|���|fd|i|��}|��|�	�tj�
dt�tj��|S)Nr3)�targetr,�
)
rlrm�isatty�	threadingZEventZThreadrv�start�setrXrnrprq)r,r3r-rtZspinner_threadr4)r5rurrr6�s
�
z,with_spinner.<locals>.wrapper.<locals>.new_frr7rwr9rr:�szwith_spinner.<locals>.wrapperr)rur:rrwr�with_spinner�sr~cCsx|dkrtjj|tjjS|dkr8tjj|tjjS|dkrTtjj|tjjS|dkrptjj|tjjS|SdS)NZlowZmediumZhighZcritical)rZTxtColorZINFOBLUEZENDCZ
WARNINGYELLOWZORANGEZFAIL)Zpriorityrrr�colorize_prioritys�r)N)N)r@)4rjrOrlr{rr�	functoolsr�typingrZuaclientrrrrr	r
rrr
rZ'uaclient.api.u.pro.security.fix._commonrZ(uaclient.api.u.pro.status.is_attached.v1rZuaclient.aptrrZuaclient.configrZuaclient.filesrZget_event_loggerr"rpZAbstractProgressrr.r(r0r;r<r>rGrLrRrYr^r*rdrvr~rrrrr�<module>sD0


�