%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/uaclient/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/uaclient/__pycache__/config.cpython-312.pyc

�

�Hcf�G��\�ddlZddlZddlZddlmZmZddlmZmZm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZddlmZmZmZmZmZmZmZmZddlmZddlm Z ejBejDe#��Z$dd	d
�Z%dZ&dZ'd
Z(ejR�Z*Gd�d�Z+de,fd�Z-dd�Z.de,fd�Z/y)�N)�	lru_cache�wraps)�Any�Dict�Optional)	�apt�event_logger�
exceptions�files�http�messages�snap�system�util)�APT_NEWS_URL�BASE_CONTRACT_URL�BASE_LIVEPATCH_URL�BASE_SECURITY_URL�CONFIG_DEFAULTS�CONFIG_FIELD_ENVVAR_ALLOWLIST�DEFAULT_CONFIG_FILE�DEFAULT_DATA_DIR)�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)	�contract_url�data_dir�features�log_file�	log_level�security_url�settings_overrides�	ua_config�
livepatch_urlc	�p�eZdZdZdZdZ			d/deeee	fdee
jdeeddfd	�Ze
d
��Ze
defd��Ze
defd��Ze
defd
��Ze
deefd��Zej&defd��Ze
deefd��Zej&defd��Ze
deefd��Zej&defd��Ze
deefd��Zej&defd��Ze
ed��deefd���Zej&defd��Ze
ed��deefd���Zej&defd��Ze
defd��Zej&defd��Ze
defd��Zej&defd��Ze
defd ��Zej&defd!��Ze
defd"��Zej&defd#��Ze
defd$��Z e j&defd%��Z e
defd&��Z!e!j&defd'��Z!e
d(��Z"e
d)��Z#e
defd*��Z$e
d+��Z%e
d,��Z&d-�Z'd.�Z(y)0�UAConfig)r$r%)r&r')r"r#N�cfg�user_config�series�returnc�~�|rd|_||_d|_n1t�|_t	|j�\|_|_|r||_n$	tj
j�|_d|jvrOtjji|j
j��|jd�d��|_||_d|_y#t$rO}tjd|��tjd�t
j�|_Yd}~��d}~wwxYw)�NzError loading user config)�exc_infozUsing default config valuesr3T)� optional_type_errors_become_null)�cfg_pathr7�invalid_keys�get_config_path�parse_configr8r�read�	Exception�LOG�warning�UserConfigData�	from_dict�to_dictr9�_machine_token_file)�selfr7r8r9�es     �1/usr/lib/python3/dist-packages/uaclient/config.py�__init__zUAConfig.__init__Ss��� �D�M��D�H� $�D��+�-�D�M�*6�t�}�}�*E�'�D�H�d�'��*�D��
E�#3�#?�#?�#D�#D�#F�� ��$�(�(�"�/�>�>�H�H�G�4�#�#�+�+�-�G����+�1F�G�15� I� �D��
����	
� ���
E����7�!��D����9�:�#3�#B�#B�#D�� � ��
E�s�#C$�$	D<�-AD7�7D<c��|js>tj|j|jjd��|_|jS)N�machine_token_overlay)rJr�MachineTokenFiler-r.�get�rKs rM�machine_token_filezUAConfig.machine_token_fileysF���'�'�',�'=�'=��
�
��
�
�!�!�"9�:�(�D�$��'�'�'�c�B�|jjdt�S)Nr,)r7rRrrSs rMr,zUAConfig.contract_url�����x�x�|�|�N�,=�>�>rUc�B�|jjdt�S)Nr1)r7rRrrSs rMr1zUAConfig.security_url�rWrUc�B�|jjdt�S)Nr4)r7rRrrSs rMr4zUAConfig.livepatch_url�s���x�x�|�|�O�-?�@�@rUc�.�|jjS�N)r8r rSs rMr zUAConfig.http_proxy�s�����*�*�*rU�valuec�x�||j_tjj|j�yr[)r8r r�write�rKr\s  rMr zUAConfig.http_proxy�s*��&+����#��$�$�*�*�4�+;�+;�<rUc�.�|jjSr[)r8r!rSs rMr!zUAConfig.https_proxy�s�����+�+�+rUc�x�||j_tjj|j�yr[)r8r!rr^r_s  rMr!zUAConfig.https_proxy�s*��',����$��$�$�*�*�4�+;�+;�<rUc�.�|jjSr[)r8r%rSs rMr%zUAConfig.ua_apt_https_proxy�s�����2�2�2rUc�x�||j_tjj|j�yr[)r8r%rr^r_s  rMr%zUAConfig.ua_apt_https_proxy�s*��.3����+��$�$�*�*�4�+;�+;�<rUc�.�|jjSr[)r8r$rSs rMr$zUAConfig.ua_apt_http_proxy�s�����1�1�1rUc�x�||j_tjj|j�yr[)r8r$rr^r_s  rMr$zUAConfig.ua_apt_http_proxy�s*��-2����*��$�$�*�*�4�+;�+;�<rU)�maxsizec���|jj}|r|S|jj}|r6tj	t
jjdd���|Sy)Nr"r&��old�new)r8r&r"�event�infor
�WARNING_DEPRECATED_FIELD�format�rK�
global_val�old_apt_vals   rMr&zUAConfig.global_apt_http_proxy�sh���%�%�;�;�
�����&�&�5�5����J�J��1�1�8�8�(�.E�9��
�
��rUc���||j_d|j_tjjj�tjj|j�yr[)r8r&r"r6�fget�cache_clearrr^r_s  rMr&zUAConfig.global_apt_http_proxy�sP��16����.�*.����'��&�&�+�+�7�7�9��$�$�*�*�4�+;�+;�<rUc���|jj}|r|S|jj}|r6tj	t
jjdd���|Sy)Nr#r'rh)r8r'r#rkrlr
rmrnros   rMr'zUAConfig.global_apt_https_proxy�sh���%�%�<�<�
�����&�&�6�6����J�J��1�1�8�8�)�/G�9��
�
��rUc���||j_d|j_tjjj�tjj|j�yr[)r8r'r#r6rsrtrr^r_s  rMr'zUAConfig.global_apt_https_proxy�sP��27����/�+/����(��'�'�,�,�8�8�:��$�$�*�*�4�+;�+;�<rUc�8�|jj}|�y|S)Ni`T)r8r(�rK�vals  rMr(zUAConfig.update_messaging_timer�s �����5�5���;���
rUc�x�||j_tjj|j�yr[)r8r(rr^r_s  rMr(zUAConfig.update_messaging_timer�s*��27����/��$�$�*�*�4�+;�+;�<rUc�8�|jj}|�y|S)Ni@8)r8r)rxs  rMr)zUAConfig.metering_timer�s �����-�-���;���
rUc�x�||j_tjj|j�yr[)r8r)rr^r_s  rMr)zUAConfig.metering_timer�s*��*/����'��$�$�*�*�4�+;�+;�<rUc�8�|jj}|�y|S)NF)r8�poll_for_pro_licenserxs  rMr~zUAConfig.poll_for_pro_license�s"��
���3�3���;���
rUc�x�||j_tjj|j�yr[)r8r~rr^r_s  rMr~zUAConfig.poll_for_pro_licenses*��05����-��$�$�*�*�4�+;�+;�<rUc�8�|jj}|�y|S)NiX)r8�polling_error_retry_delayrxs  rMr�z"UAConfig.polling_error_retry_delay	s"�����8�8���;���
rUc�x�||j_tjj|j�yr[)r8r�rr^r_s  rMr�z"UAConfig.polling_error_retry_delays*��5:����2��$�$�*�*�4�+;�+;�<rUc�8�|jj}|�y|S)NT)r8r*rxs  rMr*zUAConfig.apt_newss �����'�'���;���
rUc�x�||j_tjj|j�yr[)r8r*rr^r_s  rMr*zUAConfig.apt_newss*��$)����!��$�$�*�*�4�+;�+;�<rUc�B�|jj}|�tS|Sr[)r8r+rrxs  rMr+zUAConfig.apt_news_url#s#�����+�+���;����
rUc�x�||j_tjj|j�yr[)r8r+rr^r_s  rMr+zUAConfig.apt_news_url*s*��(-����%��$�$�*�*�4�+;�+;�<rUc�B�|jjdt�S)Nr-)r7rRrrSs rMr-zUAConfig.data_dir/s���x�x�|�|�J�(8�9�9rUc��|jjdd�}	tt|j	��S#t
$rtjcYSwxYw)Nr0�DEBUG)r7rR�getattr�logging�upper�AttributeErrorr�)rKr0s  rMr0zUAConfig.log_level3sH���H�H�L�L��g�6�	�	!��7�I�O�O�$5�6�6���	!��=�=� �	!�s�<�A�Ac�H�|jjdtd�S)Nr/)r7rRrrSs rMr/zUAConfig.log_file;s���x�x�|�|�J��
�(C�D�DrUc��|jjd�}|r(t|t�r|Stjd|�iS)z>Return a dictionary of any features provided in uaclient.conf.r.zDUnexpected uaclient.conf features value. Expected dict, but found %s)r7rR�
isinstance�dictrErF)rKr.s  rMr.zUAConfig.features?sC���8�8�<�<�
�+����(�D�)������3���
�	rUc�.�|jjS)zAReturn the machine-token if cached in the machine token response.)rT�
machine_tokenrSs rMr�zUAConfig.machine_tokenNs���&�&�4�4�4rUc�P�dD]S}t||�}|�tjd|��(t|t�r|dks�>tj||���|js|jr,|js|jrtj��tjd|jtj�tjd|jtj�tjd|jtj�tjd|jtj�tjd|j tj"�tjd|j$tj&�|js|jrDt)j*|j|jt(j,j.�n[|js|jrCt)j*|j|jt(j,j0�g}t3j4�r�t3j6|j |j$�|j s#t3j8t2j:�s/|j$s4t3j8t2j<�r|j?d�ddl m!}dd	l"m#}dd
l$m%}||�}|jM�\}}	||jNk(r�|jQ|j |j$�|j s|j9|j:�s'|j$s,|j9|j<�r|j?d�tS|�dkDr;djU|�}
tWtXjZj]|
�
��yy)N)r(r)z1No config set for %s, default value will be used.r��keyr\r�httpsr)�	livepatch)�ApplicationStatus)�LivepatchEntitlementr�z, )�services)/r�rE�debugr��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.entitlements.entitlement_statusr��uaclient.entitlements.livepatchr��application_status�ENABLED�configure_livepatch_proxy�len�join�printr
�!PROXY_DETECTED_BUT_NOT_CONFIGUREDrn)rK�propr\�services_with_proxiesr�r�r��
livepatch_ent�livepatch_status�_r�s           rM�process_configzUAConfig.process_configSsN��
�	�D��D�$�'�E��}��	�	�G��� ��s�+�u�q�y� �9�9��E���	�
�&�&�$�*E�*E��"�"�d�&=�&=��:�:�<�<������&�&��.�.�	
�
	
�����'�'��/�/�	
�
	
����D�*�*�D�,N�,N�	
�	
�����#�#��/�/�	
�
	
����D�O�O�T�%H�%H�	
�	
����T�%�%�t�'K�'K�	
��%�%��)D�)D�����*�*��+�+��!�!�(�(�
�
�
#�
#�t�'>�'>�����&�&��'�'��!�!�*�*�
�!#���"�"�$��%�%�d�o�o�t�7G�7G�H��O�O��0�0��1G�1G�H��$�$��0�0��1H�1H�I�%�,�,�V�4�&�N�H�,�T�2�
�+�>�>�@���!��0�8�8�8��/�/�����!1�!1�
��O�O��5�5��/�/���$�$��5�5��0�0��&�,�,�[�9��$�%��)��y�y�!6�7�H���:�:�A�A�%�B��
�*rUc�B�|j�0t|j�D]}tjd|��d|jvrUtjd�tjd�tjd�tjd�yy)Nz&Ignoring invalid uaclient.conf key: %sr3z)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@�sortedrErFr7)rK�invalid_keys  rM�warn_about_invalid_keysz UAConfig.warn_about_invalid_keys�s������(�%�d�&7�&7�8�
�����<�k��
��$�(�(�"�
�K�K�C�D��K�K�2�3��K�K�7�
�

�K�K�7�
�#rU)NNN))�__name__�
__module__�__qualname__�ua_scoped_proxy_options�global_scoped_proxy_options�&deprecated_global_scoped_proxy_optionsrr�strrrrGrN�propertyrTr,r1r4r �setterr!r%r$rr&r'r�r(r)�boolr~r�r*r+r-r0r/r.r�r�r��rUrMr6r6HsN��I��#��.�*�)-�AE� $�	$
�
�d�3��8�n�
%�$
��.�=�=�>�$
���
�	$
�

�$
�L�(��(��?�c�?��?��?�c�?��?��A�s�A��A��+�H�S�M�+��+����=��=��=��,�X�c�]�,��,����=��=��=��3�H�S�M�3��3����=��=��=��2�8�C�=�2��2����=�s�=��=���t��
�x��}�
���
��!�!�=�3�=�"�=���t��
���
�
���
��"�"�=�C�=�#�=��������"�"�=�C�=�#�=����������=�C�=��=���d����� � �=�$�=�!�=���3�����%�%�=�s�=�&�=���$�����_�_�=�d�=��=���c�������=�#�=��=��:��:��!��!��E�#�E��E������5��5�e�NrUr6r:c�T�tjjd�}|r|StS)z4Get config path to be used when loading config dict.�UA_CONFIG_FILE)�os�environrRr)�config_files rMrArA�s$���*�*�.�.�!1�2�K�����rUc�`�tjt�}|s
t�}tj	d|�t
jj|�r-|jttj|���i}t
jj�D]�\}}|j�}|jd�s�(|dd}|jd�r|dd}|j!d�rTt
jj|�rttj|��}nt#j$|���d	|vr||i|d	<��||d	|<��|t&vs��|||<��|j|�d
|vr%t
jj)|d
�|d
<dD]4}t+j,||�r�t#j.|||���t1|j3��j5t6�}|D]}|j9|��||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)�filepathr.r-)r,r1r�)�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_pathr7�env_keysr�r\�
field_name�feature_field_namer@r�s	         rMrBrB�s����)�)�O�
$�C��%�'���I�I�5�{�C�	�w�w�~�~�k�"��
�
�9�V�-�-�k�:�;�<��H��j�j�&�&�(�-�
��U��i�i�k���>�>�%� ��Q�R��J��$�$�[�1�%/���^�"��>�>�&�)��w�w�~�~�e�,� )�&�*:�*:�5�*A� B��(�F�F�%*����S�(�'9�5�&A�C�
�O�:?�C�
�O�$6�7��5�5�',���$�5-�6�J�J�x���S���'�'�,�,�S��_�=��J��/�L���"�"�3�s�8�,��2�2�s�#�c�(�K�K�L��s�x�x�z�?�-�-�.B�C�L�#������������rU�override_keyc����fd�}|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.
    c�2���t����fd��}|S)Nc���t�\}}|jdi�j�t�}|tk7r�dk(r|dfS|S��S)Nr2�
cloud_type)rBrR�UNSET_SETTINGS_OVERRIDE_KEY)r7r��value_override�fr�s   ��rM�new_fz>apply_config_settings_override.<locals>.wrapper.<locals>.new_f&s[���!�^�F�C�� �W�W�%9�2�>�B�B��9��N��!<�<��<�/�*�D�1�1�%�%��3�JrU)r)r�r�r�s` �rM�wrapperz/apply_config_settings_override.<locals>.wrapper%s ���	�q��	�
�	��rUr�)r�r�s` rM�apply_config_settings_overrider�s����"�NrUr[)0r�r�r��	functoolsrr�typingrrrr�rr	r
rrr
rrr�uaclient.defaultsrrrrrrrr�uaclient.filesr�
uaclient.yamlr�	getLogger�replace_top_level_logger_namer�rE�MERGE_ID_KEY_MAPr��UA_CONFIGURABLE_KEYSr��get_event_loggerrkr6r�rArBr�r�rUrM�<module>rs�����	�&�&�&�
�
�
�	�	�	�,�#��g���:��:�:�8�D�E��!�"���'��
�� 
��	&��%�%�'��E�E�P���<�~��rU

Zerion Mini Shell 1.0