https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/uaclient/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

��Jh�K�@sddlZddlZddlZddlmZmZddlmZmZm	Z	ddl
mZmZm
Z
mZmZmZmZmZddlmZmZmZmZmZmZmZmZmZddlmZmZddl m!Z!e�"e�#e$��Z%dd	d
�Z&dZ'dZ(d
Z)e�*�Z+Gdd�d�Z,de-fdd�Z.ddd�Z/de-fdd�Z0dS)�N)�	lru_cache�wraps)�Any�Dict�Optional)�apt�event_logger�
exceptions�http�messages�snap�system�util)	�APT_NEWS_URL�BASE_CONTRACT_URL�BASE_LIVEPATCH_URL�BASE_SECURITY_URL�BASE_VULNERABILITY_DATA_URL�CONFIG_DEFAULTS�CONFIG_FIELD_ENVVAR_ALLOWLIST�DEFAULT_CONFIG_FILE�DEFAULT_DATA_DIR)�state_files�user_config_file)�	safe_load�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�vulnerability_data_url_prefix�lxd_guest_attach)
�contract_url�data_dir�features�log_file�	log_level�security_urlr,�settings_overrides�	ua_config�
livepatch_urlc	@seZdZdZdZdZ			dIdeeee	fdee
jdeeddfd	d
�Ze
defdd��Ze
defd
d��Ze
defdd��Ze
deefdd��Zejdefdd��Ze
deefdd��Zejdefdd��Ze
deefdd��Zejdefdd��Ze
deefdd��Zejdefdd��Ze
defdd��Zejdefd d��Ze
edd!�deefd"d#���Zejdefd$d#��Ze
edd!�deefd%d&���Zejdefd'd&��Ze
defd(d)��Zejdefd*d)��Ze
defd+d,��Zejdefd-d,��Ze
defd.d/��Zejdefd0d/��Ze
defd1d2��Zejdefd3d2��Ze
defd4d5��Z e jdefd6d5��Z e
defd7d8��Z!e!jdefd9d8��Z!e
de
j"fd:d;��Z#e#jde
j"fd<d;��Z#e
d=d>��Z$e
d?d@��Z%e
defdAdB��Z&e
dCdD��Z'dEdF�Z(dGdH�Z)dS)J�UAConfig)r$r%)r&r')r"r#N�cfg�user_config�series�returnc
Cs�|rd|_||_d|_n
t�|_t|j�\|_|_|r||_n,ztj��|_Wn#tyJ}zt	j
d|d�t	�
d�t��|_WYd}~nd}~wwd|jvrctjji|j�
��|jd�dd�|_||_dS)�NzError loading user config)�exc_infozUsing default config valuesr5T)� optional_type_errors_become_null)�cfg_pathr8�invalid_keys�get_config_path�parse_configr9r�read�	Exception�LOG�warning�UserConfigData�	from_dict�to_dictr:)�selfr8r9r:�e�rL�1/usr/lib/python3/dist-packages/uaclient/config.py�__init__Vs,
��
�
zUAConfig.__init__cC�|j�dt�S)Nr.)r8�getr�rJrLrLrMr.y�zUAConfig.contract_urlcCrO)Nr3)r8rPrrQrLrLrMr3}rRzUAConfig.security_urlcCrO)Nr6)r8rPrrQrLrLrMr6�rRzUAConfig.livepatch_urlcC�|jjS�N)r9r rQrLrLrMr ��zUAConfig.http_proxy�valuecC�||j_tj�|j�dSrT)r9r r�write�rJrVrLrLrMr ��cCrSrT)r9r!rQrLrLrMr!�rUzUAConfig.https_proxycCrWrT)r9r!rrXrYrLrLrMr!�rZcCrSrT)r9r%rQrLrLrMr%�rUzUAConfig.ua_apt_https_proxycCrWrT)r9r%rrXrYrLrLrMr%�rZcCrSrT)r9r$rQrLrLrMr$�rUzUAConfig.ua_apt_http_proxycCrWrT)r9r$rrXrYrLrLrMr$�rZcC�|jj}|dur
tS|SrT)r9r,r�rJ�valrLrLrMr,��z&UAConfig.vulnerability_data_url_prefixcCrWrT)r9r,rrXrYrLrLrMr,�rZ)�maxsizecC�:|jj}|r|S|jj}|rt�tjjddd��|SdS)Nr"r&��old�new)r9r&r"�event�infor�WARNING_DEPRECATED_FIELD�format�rJ�
global_val�old_apt_valrLrLrMr&����zUAConfig.global_apt_http_proxycC�.||j_d|j_tjj��tj�|j�dSrT)r9r&r"r7�fget�cache_clearrrXrYrLrLrMr&��cCr`)Nr#r'ra)r9r'r#rdrerrfrgrhrLrLrMr'�rkzUAConfig.global_apt_https_proxycCrlrT)r9r'r#r7rmrnrrXrYrLrLrMr'�rocC�|jj}|dur
dS|S)Ni`T)r9r(r\rLrLrMr(�r^zUAConfig.update_messaging_timercCrWrT)r9r(rrXrYrLrLrMr(�rZcCrp)Ni@8)r9r)r\rLrLrMr)�r^zUAConfig.metering_timercCrWrT)r9r)rrXrYrLrLrMr)�rZcCrp)NF)r9�poll_for_pro_licenser\rLrLrMrq�szUAConfig.poll_for_pro_licensecCrWrT)r9rqrrXrYrLrLrMrqrZcCrp)NiX)r9�polling_error_retry_delayr\rLrLrMrrsz"UAConfig.polling_error_retry_delaycCrWrT)r9rrrrXrYrLrLrMrrrZcCrp)NT)r9r*r\rLrLrMr*r^zUAConfig.apt_newscCrWrT)r9r*rrXrYrLrLrMr*!rZcCr[rT)r9r+rr\rLrLrMr+&r^zUAConfig.apt_news_urlcCrWrT)r9r+rrXrYrLrLrMr+-rZcCs|jj}|durtjjS|SrT)r9r-r�LXDGuestAttachEnum�OFFr\rLrLrMr-2szUAConfig.lxd_guest_attachcCs*|durtjj}||j_tj�|j�dSrT)rrsrtr9r-rXrYrLrLrMr-9scCrO)Nr/)r8rPrrQrLrLrMr/@rRzUAConfig.data_dircCs8|j�dd�}ztt|���WStytjYSw)Nr2�DEBUG)r8rP�getattr�logging�upper�AttributeErrorru)rJr2rLrLrMr2Ds
�zUAConfig.log_levelcCs|j�dtd�S)Nr1)r8rPrrQrLrLrMr1LszUAConfig.log_filecCs.|j�d�}|rt|t�r|St�d|�iS)z>Return a dictionary of any features provided in uaclient.conf.r0zDUnexpected uaclient.conf features value. Expected dict, but found %s)r8rP�
isinstance�dictrErF)rJr0rLrLrMr0Ps
�zUAConfig.featuresc
CsVdD]"}t||�}|durt�d|�qt|t�r|dkr$tj||d��q|js+|jr5|j	s1|j
r5t���t�
d|jtj�t�
d|jtj�t�
d|j	tj�t�
d|j
tj�t�
d|jtj�t�
d|jtj�|jsq|jr}t�|j|jtjj�n|j	s�|j
r�t�|j	|j
tjj�g}t��r�t�|j|j�|js�t�tj�s�|js�t�tj�r�|�d�ddl m!}dd	l"m#}||�j$}t%d
d�|D��}|r�|�&|j|j�|js�|�|j�s�|js�|�|j�r�|�d�t'|�dk�rd
�(|�}t)t*j+j,|d��ddl-m.}	|j/t0j1j2k�r|	|�j3�st)t*j4�dSt5j6�7t5j8|j/d��dS)N)r(r)z1No config set for %s, default value will be used.r��keyrVr
�httpsr)�	livepatch)�_enabled_servicescss�|]
}|jdkr|VqdS)rN)r)�.0�entrLrLrM�	<genexpr>�s��z*UAConfig.process_config.<locals>.<genexpr>rz, )�services)�_is_attached)�guest_attach)9rvrE�debugrz�intr	�InvalidPosIntConfigValuer&r'r$r%�InvalidProxyCombinationConfigr
�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_snapd_installed�configure_snap_proxy�get_config_option_value�HTTP_PROXY_OPTION�HTTPS_PROXY_OPTION�append�uaclientr�-uaclient.api.u.pro.status.enabled_services.v1r��enabled_services�any�configure_livepatch_proxy�len�join�printr�!PROXY_DETECTED_BUT_NOT_CONFIGUREDrg�(uaclient.api.u.pro.status.is_attached.v1r�r-rrsrt�is_attached�-WARNING_LXD_GUEST_ATTACH_SET_BUT_NOT_ATTACHEDr�lxd_pro_config_filerX�LXDProConfig)
rJ�proprV�services_with_proxiesrr�r��livepatch_enabledr�r�rLrLrM�process_config_s�
�������
��
�
����
��
�

��������

����zUAConfig.process_configcCs`|jdurt|j�D]}t�d|�q
d|jvr.t�d�t�d�t�d�t�d�dSdS)Nz&Ignoring invalid uaclient.conf key: %sr5z)legacy "ua_config" found in uaclient.confzPlease do the following:z�  1. run `sudo pro config set field=value` for each field/value pair present under "ua_config" in /etc/ubuntu-advantage/uaclient.confzQ  2. Delete "ua_config" and all sub-fields in /etc/ubuntu-advantage/uaclient.conf)r@�sortedrErFr8)rJ�invalid_keyrLrLrM�warn_about_invalid_keys�s
�


���z UAConfig.warn_about_invalid_keys)NNN)*�__name__�
__module__�__qualname__�ua_scoped_proxy_options�global_scoped_proxy_options�&deprecated_global_scoped_proxy_optionsrr�strrrrGrN�propertyr.r3r6r �setterr!r%r$r,rr&r'r�r(r)�boolrqrrr*r+rsr-r/r2r1r0r�r�rLrLrLrMr7Ks�����
�#	


vr7r;cCstj�d�}|r
|StS)z4Get config path to be used when loading config dict.�UA_CONFIG_FILE)�os�environrPr)�config_filerLrLrMrA�srAc	Cspt�t�}|s
t�}t�d|�tj�|�r |�t	t
�|���i}tj�
�D]Q\}}|��}|�d�rx|dd�}|�d�rp|dd�}|�d�r^tj�|�rXt	t
�|��}ntj|d��d	|vri||i|d	<q'||d	|<q'|tvrx|||<q'|�|�d
|vr�tj�|d
�|d
<dD]}t�||�s�tj|||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_�	�yaml)�filepathr0r/)r.r3r|)�copyrrArEr�r��path�exists�updaterr
�	load_filer��items�lower�
startswith�endswithr	�InvalidFeatureYamlConfigValuer�
expanduserr
�is_service_url�InvalidURLConfigValue�set�keys�
difference�VALID_UA_CONFIG_KEYS�pop)	�config_pathr8�env_keysr}rV�
field_name�feature_field_namer@r�rLrLrMrB�sH




��
�rB�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)Nr4�
cloud_type)rBrP�UNSET_SETTINGS_OVERRIDE_KEY)r8�_�value_override)�fr�rLrM�new_fAs
�z>apply_config_settings_override.<locals>.wrapper.<locals>.new_f)r)r�r��r�)r�rM�wrapper@s
z/apply_config_settings_override.<locals>.wrapperrL)r�r�rLr�rM�apply_config_settings_override3s
r�rT)1r�rwr��	functoolsrr�typingrrrr�rrr	r
rrr
r�uaclient.defaultsrrrrrrrrr�uaclient.filesrr�
uaclient.yamlr�	getLogger�replace_top_level_logger_namer�rE�MERGE_ID_KEY_MAPr��UA_CONFIGURABLE_KEYSr��get_event_loggerrdr7r�rArBr�rLrLrLrM�<module>s0(,
�#
	?

https://t.me/RX1948 - 2025