AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/uaclient/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/uaclient/__pycache__/config.cpython-310.pyc
o

F��c�a�@sLddlZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZmZm
Z
mZmZddlZddlmZmZmZmZmZmZmZmZddlmZmZmZmZmZm Z ddl!m"Z"e�#e$�Z%dZ&d	d
d�Z'dZ(d
Z)dZ*edd�Z+e�,�Z-ede.d�Z/dede/fde/fdd�Z0Gdd�d�Z1de.fdd�Z2d!dd�Z3de.fdd �Z4dS)"�N)�
namedtuple)�	lru_cache�wraps)�Any�Callable�Dict�Optional�Tuple�TypeVar)�apt�event_logger�
exceptions�files�messages�snap�system�util)�APT_NEWS_URL�BASE_CONTRACT_URL�BASE_SECURITY_URL�CONFIG_DEFAULTS�CONFIG_FIELD_ENVVAR_ALLOWLIST�DEFAULT_CONFIG_FILE)�
NoticeFile�private�name�type)�availableResources�resourceEntitlements�_unset)�
http_proxy�https_proxy�apt_http_proxy�apt_https_proxy�ua_apt_http_proxy�ua_apt_https_proxy�global_apt_http_proxy�global_apt_https_proxy�update_messaging_timer�metering_timer�apt_news�apt_news_url)
�contract_url�data_dir�features�log_file�	log_level�security_url�settings_overrides�timer_log_file�daemon_log_file�	ua_config�DataPath)�filenamer�	permanent�S)�bound�func.�returncCs
t�|�S�N)r)r;�r>�1/usr/lib/python3/dist-packages/uaclient/config.py�	str_cacheRs
r@c	@s�eZdZeddd�eddd�eddd�eddd�eddd�eddd�d	�Zd
ZdZdZ	
	
	dmdee	e
efdee
dedd
fdd�Z
edd��Zedd��Zede
fdd��Zede
fdd��Zedee
fdd��Zejde
fdd��Zedee
fd d!��Zejde
fd"d!��Zedee
fd#d$��Zejde
fd%d$��Zedee
fd&d'��Zejde
fd(d'��Zeedee
fd)d*���Zejde
fd+d*��Zeedee
fd,d-���Zejde
fd.d-��Zedeefd/d0��Zejdefd1d0��Zednd3d4��Zejdefd5d4��Zedefd6d7��Zejdefd8d7��Zedefd9d:��Zejdefd;d:��Zedefd<d=��Z e jdefd>d=��Z ede
fd?d@��Z!e!jde
fdAd@��Z!de"ee
ffdBdC�Z#edDdE��Z$edFdG��Z%ede
fdHdI��Z&ede
fdJdK��Z'edLdM��Z(edNdO��Z)edPdQ��Z*edRdS��Z+dodTee
de
fdUdV�Z,dTe
defdWdX�Z-dYe
dd
fdZd[�Z.dTe
dd
fd\d]�Z/dpd^efd_d`�Z0dpdTe
daedeefdbdc�Z1dTe
ddedd
fdedf�Z2dgdh�Z3dodidj�Z4dkdl�Z5d
S)q�UAConfig�instance-idTFzmachine-access-cis.json�lockzstatus.jsonznotices.jsonzmarker-reboot-cmds-required)rBzmachine-access-cisrCzstatus-cache�noticeszmarker-reboot-cmds)r$r%)r&r')r"r#N�cfg�series�	root_moder<cCsN|rd|_||_d|_n
t�|_t|j�\|_|_||_||_d|_d|_dS)�N)	�cfg_pathrE�invalid_keys�get_config_path�parse_configrFrG�_machine_token_file�_notice_file)�selfrErFrGr>r>r?�__init__ms�
zUAConfig.__init__cCs(|jst�|j|j|j�d��|_|jS)N�machine_token_overlay)rMr�MachineTokenFiler-rGr.�get�rOr>r>r?�machine_token_file�s
�zUAConfig.machine_token_filecCs|jst|j|j�|_|jSr=)rNrr-rGrTr>r>r?�notice_file�szUAConfig.notice_filecC�|j�dt�S)Nr,)rErSrrTr>r>r?r,��zUAConfig.contract_urlcCrW)Nr1)rErSrrTr>r>r?r1�rXzUAConfig.security_urlcC�|j�di��d�S�Nr5r �rErSrTr>r>r?r ��zUAConfig.http_proxy�valuecC�.d|jvr
i|jd<||jdd<|��dSrZ�rE�	write_cfg�rOr]r>r>r?r ��

cCrY�Nr5r!r[rTr>r>r?r!�r\zUAConfig.https_proxycCr^rcr_rar>r>r?r!�rbcCrY�Nr5r%r[rTr>r>r?r%�r\zUAConfig.ua_apt_https_proxycCr^rdr_rar>r>r?r%�rbcCrY�Nr5r$r[rTr>r>r?r$�r\zUAConfig.ua_apt_http_proxycCr^rer_rar>r>r?r$�rbcC�H|j�di��d�}|r|S|j�di��d�}|r"t�tj�|SdS�Nr5r&r")rErS�event�infor�WARNING_DEPRECATED_APT_HTTP�rO�
global_val�old_apt_valr>r>r?r&�szUAConfig.global_apt_http_proxycC�Hd|jvr
i|jd<||jdd<d|jdd<tjj��|��dSrg)rErAr&�fget�cache_clearr`rar>r>r?r&��

cCrf�Nr5r'r#)rErSrhrir�WARNING_DEPRECATED_APT_HTTPSrkr>r>r?r'�s�zUAConfig.global_apt_https_proxycCrnrr)rErAr'rorpr`rar>r>r?r'�rqcCrY�Nr5r(r[rTr>r>r?r(�r\zUAConfig.update_messaging_timercCr^rtr_rar>r>r?r(�rb�
Optional[int]cCrY�Nr5r)r[rTr>r>r?r)r\zUAConfig.metering_timercCr^rvr_rar>r>r?r)rbcC�|j�di��dd�S)Nr5�poll_for_pro_licenseFr[rTr>r>r?rxszUAConfig.poll_for_pro_licensecCr^)Nr5rxr_rar>r>r?rxrbcCrw)Nr5�polling_error_retry_delayiXr[rTr>r>r?rys�z"UAConfig.polling_error_retry_delaycCr^)Nr5ryr_rar>r>r?ry!rbcCrw)Nr5r*Tr[rTr>r>r?r*(�zUAConfig.apt_newscCr^)Nr5r*r_rar>r>r?r*,rbcCs|j�di��dt�S�Nr5r+)rErSrrTr>r>r?r+3rzzUAConfig.apt_news_urlcCr^r{r_rar>r>r?r+7rbcCs�|�d�}d}tj�|�s|St�|�}|�d�\}}zt�d|g�t|�|fWSt	j
yVt��dkrFt�
d||�t|�|fYSt�d||�t�|�|YSw)a]Return lock info if config lock file is present the lock is active.

        If process claiming the lock is no longer present, remove the lock file
        and log a warning.

        :param lock_path: Full path to the lock file.

        :return: A tuple (pid, string describing lock holder)
            If no active lock, pid will be -1.
        rC)���rH�:�psrz.Found stale lock file previously held by %s:%sz1Removing stale lock file previously held by %s:%s)�	data_path�os�path�existsr�	load_file�split�subp�intr
�ProcessExecutionError�getuid�logging�debug�warning�ensure_file_absent)rO�	lock_path�no_lock�lock_content�lock_pid�lock_holderr>r>r?�check_lock_info>s2

��
�zUAConfig.check_lock_infocCs
|jdS)Nr-)rErTr>r>r?r-bs
zUAConfig.data_dircCs@|j�dd�}ztt|���WStytttd�YSw)Nr0�DEBUG)rErS�getattrr��upper�AttributeErrorr)rOr0r>r>r?r0fs�zUAConfig.log_levelcC�|j�dtd�S)Nr/�rErSrrTr>r>r?r/nszUAConfig.log_filecCr�)Nr3r�rTr>r>r?r3r��zUAConfig.timer_log_filecCr�)Nr4r�rTr>r>r?r4xr�zUAConfig.daemon_log_filecCs
t|j�S)z<Report whether this machine configuration is attached to UA.)�bool�
machine_tokenrTr>r>r?�is_attached~s
zUAConfig.is_attachedcCs.|j�d�}|rt|t�r|St�d|�iS)z>Return a dictionary of any features provided in uaclient.conf.r.zDUnexpected uaclient.conf features value. Expected dict, but found %s)rErS�
isinstance�dictr�r�)rOr.r>r>r?r.�s
�zUAConfig.featurescCs|jjS)zAReturn the machine-token if cached in the machine token response.)rUr�rTr>r>r?r��szUAConfig.machine_token�keycCsh|jd}|stj�|t�S||jvr,|j|}|jr$tj�|t|j�Stj�||j�Stj�|t|�S)zAReturn the file path in the data directory represented by the keyr-)rEr�r��join�PRIVATE_SUBDIR�
data_pathsrr7)rOr�r-rr>r>r?r�s


�zUAConfig.data_pathcCs|�|�}tj�|�Sr=)rr�r�r��rOr��
cache_pathr>r>r?�cache_key_exists�s
zUAConfig.cache_key_existsr�cCst�|�dS)z�Delete the given cache_path if it exists.

        (This is a separate method to allow easier disabling of deletion during
        tests.)
        N)rr�)rOr�r>r>r?�_perform_delete�szUAConfig._perform_deletecCsL|std��|�d�rd|_n|dkr|j�dd�|�|�}|�|�dS)zRemove specific cache file.z1Invalid or empty key provided to delete_cache_key�machine-accessNrCrHzOperation in progress.*)�RuntimeError�
startswithrMrV�removerr�r�r>r>r?�delete_cache_key�s�

zUAConfig.delete_cache_key�delete_permanentcCs.|j��D]}|s|j|js|�|�qdS)z�
        Remove configuration cached response files class attributes.

        :param delete_permanent: even delete the "permanent" files
        N)r��keysr8r�)rOr��path_keyr>r>r?�delete_cache�s

��zUAConfig.delete_cache�silentcCst|�|�}zt�|�}Wnty$tj�|�s!|s!t�d|�YdSwz	t	j
|tjd�WSt
y9|YSw)NzFile does not exist: %s��cls)rrr��	Exceptionr�r�r�r�r��json�loadsr�DatetimeAwareJSONDecoder�
ValueError)rOr�r�r��contentr>r>r?�
read_cache�s
��zUAConfig.read_cacher�cCs�|�|�}tj�|�}tj�|�s&tj|dd�tj�|�tkr&t�|d�|�	d�r/d|_
n|dkrFd|vrF|j�dd�
|�d�d	��t|t�sStj|tjd
�}d}||jvrb|j|jsbd}tj|||d
�dS)NT)�exist_oki�r�rCr}rHzOperation in progress: {}�r�i�i�)�mode)rr�r��dirnamer��makedirs�basenamer��chmodr�rMrV�add�formatr�r��strr��dumpsr�DatetimeAwareJSONEncoderr�rr�
write_file)rOr�r��filepathr-r�r>r>r?�write_cache�s*

�

zUAConfig.write_cachecCsdD]$}t||�}|durt�d�qt|t�r|dkr&d�|�}t�|��q|js-|j	r9|j
s3|jr9t�tj
��t�d|jtj�t�d|j	tj�t�d|j
tj�t�d|jtj�t�d|jtj�t�d|jtj�|jsu|j	r�t�|j|j	tjj�n|j
s�|jr�t�|j
|jtjj�g}t��r�t�|j|j�|js�t�tj�s�|js�t�tj �r�|�!d�ddl"m#}dd	l$m%}|�&�}|�'�\}}	||j(kr�|�)|j|j�|js�|�|j�s�|js�|�|j �r�|�!d
�t*|�dk�rd�+|�}
t,tj-j|
d��dSdS)
N)r(r)z1No config set for {}, default value will be used.rzQValue for the {} interval must be a positive integer. Default value will be used.�http�httpsr)�	livepatch)�ApplicationStatusr�z, )�services).r�r�r�r�r�r�r
�UserFacingErrorr&r'r$r%r�ERROR_PROXY_CONFIGURATIONr�validate_proxy�PROXY_VALIDATION_APT_HTTP_URL�PROXY_VALIDATION_APT_HTTPS_URLr �PROXY_VALIDATION_SNAP_HTTP_URLr!�PROXY_VALIDATION_SNAP_HTTPS_URLr�setup_apt_proxy�
AptProxyScope�GLOBAL�UACLIENTr�is_installed�configure_snap_proxy�get_config_option_value�HTTP_PROXY_OPTION�HTTPS_PROXY_OPTION�append�uaclient.entitlementsr��(uaclient.entitlements.entitlement_statusr��LivepatchEntitlement�application_status�ENABLED�configure_livepatch_proxy�lenr��print�!PROXY_DETECTED_BUT_NOT_CONFIGURED)rO�propr]�	error_msg�services_with_proxiesr�r��
livepatch_ent�livepatch_status�_r�r>r>r?�process_config�s�
��
������
��
�
����
��
�

�������

���zUAConfig.process_configcs~|st}tj}t��j�}d|vrtd|d<dD]	}t�|�||<q�fdd�tD�|d<|t	j
|dd�7}t�||�dS)	z?Write config values back to config_path or DEFAULT_CONFIG_FILE.r0)r,r1r-r/r3r4csi|]	}|t�|d��qSr=)r�)�.0r�rTr>r?�
<dictcomp>ks�z&UAConfig.write_cfg.<locals>.<dictcomp>r5F)�default_flow_styleN)
rr�UACLIENT_CONF_HEADER�copy�deepcopyrErr��UA_CONFIGURABLE_KEYS�yaml�dumprr�)rO�config_pathr��cfg_dict�attrr>rTr?r`Vs

�zUAConfig.write_cfgcCs.|jdurt|j�D]
}t�d|�q
dSdS)Nz&Ignoring invalid uaclient.conf key: %s)rJ�sortedr�r�)rO�invalid_keyr>r>r?�warn_about_invalid_keysrs
��z UAConfig.warn_about_invalid_keys)NNF)r<rur=)F)6�__name__�
__module__�__qualname__r6r��ua_scoped_proxy_options�global_scoped_proxy_options�&deprecated_global_scoped_proxy_optionsrrr�rr�rP�propertyrUrVr,r1r �setterr!r%r$r@r&r'r�r(r)rxryr*r+r	r�r-r0r/r3r4r�r.r�rr�r�r�r�r�r�r�r`r�r>r>r>r?rAVs�




������
�
	

$









jrAcCsBtj�d�}|r
|Stj�t��tj�t��}tj�|�r|StS)z4Get config path to be used when loading config dict.�UA_CONFIG_FILE)	r��environrSr�r��getcwdr�rr�)�config_file�	local_cfgr>r>r?rKzs�rKc	Cstt�t�}|s
t�}t�d|�tj�|�r!|�t	�
t�|���i}tj
��D]T\}}|��}|�d�r||dd�}|�d�rt|dd�}|�d�rbtj�|�rZt	�
t�|��}nt�d�|���d	|vrm||i|d	<q(||d	|<q(|tvr||||<q(|�|�tj�|d
�|d
<dD]}t�||�s�t�d�|||���q�t|����t�}|D]}|�|�q�||fS)
a�Parse known Pro config file

    Attempt to find configuration in cwd and fallback to DEFAULT_CONFIG_FILE.
    Any missing configuration keys will be set to CONFIG_DEFAULTS.

    Values are overridden by any environment variable with prefix 'UA_'.

    @param config_path: Fullpath to pro configfile. If unspecified, use
        DEFAULT_CONFIG_FILE.

    @return: Dict of configuration values.
    z%Using client configuration file at %s�ua_�N�	features_�	r�zCould not find yaml file: {}r.r-)r,r1zInvalid url in config. {}: {})r�rrK�LOGr�r�r�r��updater��	safe_loadrr�r�items�lowerr��endswithr
r�r�r�
expanduserr�is_service_url�setr��
difference�VALID_UA_CONFIG_KEYS�pop)	r�rE�env_keysr�r]�
field_name�feature_field_namerJr�r>r>r?rL�sJ




��
��rL�override_keycs�fdd�}|S)a�Decorator used to override function return by config settings.

    To identify if we should override the function return, we check
    if the config object has the expected override key, we use it
    has, we will use the key value as the function return. Otherwise
    we will call the function normally.

    @param override_key: key to be looked for in the settings_override
     entry in the config dict. If that key is present, we will return
     its value as the function return.
    cst����fdd��}|S)Ncs@t�\}}|�di���t�}|tkr�dkr|dfS|S��S)Nr2�
cloud_type)rLrS�UNSET_SETTINGS_OVERRIDE_KEY)rEr��value_override)�frr>r?�new_f�s
�z>apply_config_settings_override.<locals>.wrapper.<locals>.new_f)r)r"r#�r)r"r?�wrapper�s
z/apply_config_settings_override.<locals>.wrapperr>)rr%r>r$r?�apply_config_settings_override�s
r&r=)5r�r�r�r��collectionsr�	functoolsrr�typingrrrrr	r
r��uaclientrrr
rrrrr�uaclient.defaultsrrrrrr�uaclient.filesr�	getLoggerr�rr��MERGE_ID_KEY_MAPr r�rr6�get_event_loggerrhr�r9r@rArKrLr&r>r>r>r?�<module>s> ( 

�
(
@

Anon7 - 2022
AnonSec Team