%PDF- %PDF-
Mini Shell

Mini Shell

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

�

�P�fic��<�ddlZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZmZddl
mZmZmZmZmZmZmZmZmZddlmZddlmZmZmZddlmZej>�Z ejBejDe#��Z$dZ%Gd	�d
ejL�Z'y)�N)�exists)�Any�Dict�List�Optional�Tuple�Union)	�api�apt�contract�event_logger�
exceptions�http�messages�system�util)�base)�ApplicationStatus�CanDisableFailure�CanDisableFailureReason)�status_cache_filez<^linux-image-([\d]+[.-][\d]+[.-][\d]+-[\d]+-[A-Za-z0-9_-]+)$c	����eZdZdZdZdZdZdZdZdZ	e
deee
dffd��Ze
de
fd	��Ze
de
fd
��Ze
dee
fd��Ze
dee
fd��Ze
dee
fd
��Zdefd�Ze
ej2de
fd���Z	d'dedeeeeff�fd�
Zdefd�Zdej@defd�Z!defd�Z"dej@fd�Z#dej@fd�Z$dej@fd�Z%d�Z&d�Z'dee(ee)jTffd�Z+d�Z,	d'de-e
e.fde-e
e.fdedef�fd �
Z/		d(dej@d!eee
d"eddfd#�Z0dej@ddfd$�Z1	d)dej@d%efd&�Z2�xZ3S)*�RepoEntitlementz1/etc/apt/sources.list.d/ubuntu-{name}.{extension}z$/etc/apt/preferences.d/ubuntu-{name}z	{}/ubuntuNFT�returnc��y�N���selfs �</usr/lib/python3/dist-packages/uaclient/entitlements/repo.py�repo_pin_priorityz!RepoEntitlement.repo_pin_priority6s���c��d}tj�j}|tjvrd}|j
j
|j|��S)N�sources�list)�name�	extension)r�get_release_info�seriesr�SERIES_NOT_USING_DEB822�repo_file_tmpl�formatr&)rr'r)s   r �	repo_filezRepoEntitlement.repo_file:sN���	��(�(�*�1�1���S�0�0�0��I��"�"�)�)�t�y�y�I�)�N�Nr"c� �|jdzS)Nz {})�
repo_url_tmplrs r �repo_policy_check_tmplz&RepoEntitlement.repo_policy_check_tmplBs���!�!�E�)�)r"c��g}|jjdi�}|r9|jdi�}tj|jdg��}|}|S)zdebs to install on enablement�entitlement�
directives�additionalPackages)�entitlement_cfg�get�copy)r�packagesr2r3�additional_packagess     r r8zRepoEntitlement.packagesFs^�����*�*�.�.�}�b�A���$����r�:�J�"&�)�)����3�R�8�#��+�H��r"c�x�|jjdi�jdi�jd�S)Nr2r3�aptURL�r5r6rs r �apt_urlzRepoEntitlement.apt_urlW�4��
� � �$�$�]�B�7�
�S��r�
"�
�S��]�	
r"c�x�|jjdi�jdi�jd�S)Nr2r3�suitesr<rs r �
apt_suiteszRepoEntitlement.apt_suites_r>r"c��tjt|j���}tj|�|S)z%Check if system needs to be rebooted.)�installed_pkgs)r�
should_reboot�setr8�event�needs_reboot)r�reboot_requireds  r �_check_for_rebootz!RepoEntitlement._check_for_rebootgs4�� �.�.��t�}�}�-�
��	���?�+��r"c��yrrrs r �
repo_key_filezRepoEntitlement.repo_key_fileos��	
r"�ignore_dependent_servicesc���t�|�|��\}}|dur||fS|js[|jrOdt	t
jtjj|j|j���fS||fS)N)rLF��entitlement_name�title)�super�can_disable�origin�purgerr�NO_PURGE_WITHOUT_ORIGINr�REPO_PURGE_FAIL_NO_ORIGINr,rP)rrL�result�reason�	__class__s    �r rRzRepoEntitlement.can_disablets������,�&?�-�
�����U�?��6�>�!��{�{�t�z�z��!�+�C�C��6�6�=�=�)-���4�:�:�>����
��v�~�r"c�r�|jduxrt|j�dkD}|js|syy)Nr��)r8�len�access_only)r�will_installs  r �enable_stepszRepoEntitlement.enable_steps�s8���}�}�D�0�K�S����5G�!�5K�����<��r"�progressc��|jtjj|j���|j|�|jrn|jrbt|j�dkDrI|jdtjjdj|j����y|j|�y)z�Enable specific entitlement.

        @return: True on success, False otherwise.
        @raises: UbuntuProError on failure to install suggested packages
        ��servicer�info� �r8T)rar�CONFIGURING_APT_ACCESSr,rP�setup_apt_config�supports_access_onlyr^r]r8�emit�SKIPPING_INSTALLING_PACKAGES�join�install_packages)rras  r �_perform_enablezRepoEntitlement._perform_enable�s���	����+�+�2�2�4�:�:�2�F�	
�	
���h�'��$�$��)9�)9��4�=�=�!�A�%��
�
���9�9�@�@�!$���$�-�-�!8�A����
�!�!�(�+�r"c��|jsyy)Nr[r\)rTrs r �
disable_stepszRepoEntitlement.disable_steps�s���z�z��r"c��|jr�|jr�|jdtj�|jdd�tj|j�}|j||�syg}g}|D]S}tj||j��}|r|j|t|�f��C|j|��U|j|||�syt|d�r|j�|j|�|jrg|jr[|jtj j#|j$���|j'�|j)�y)Nre�F)�exclude_origin�remove_packages�rPT)rTrSrkr�PURGE_EXPERIMENTALr� get_installed_packages_by_origin�purge_kernel_check�get_remote_versions_for_package�append�max�prompt_for_purge�hasattrru�remove_apt_configra�PURGING_PACKAGESr,rP�execute_reinstall�execute_removal)rra�repo_origin_packages�packages_to_reinstall�packages_to_remove�package�alternativess       r �_perform_disablez RepoEntitlement._perform_disable�s`���:�:�$�+�+��M�M�&�(�"=�"=�>��M�M�&�"�%�#&�#G�#G����$� ��*�*�+?��J��$&�!�!#��/�
7��"�B�B��D�K�K� �� �*�0�0� �#�l�"3�4��'�-�-�g�6�
7��(�(�"�$9�8����4�*�+�� � �"����x�(��:�:�$�+�+�����)�)�0�0�t�z�z�0�B�
�
�"�"�#8�9�� � �!3�4�r"c�H�g}|D]I}tjt|j�}|s�*|j	|jd���K|�rJ|j
�stj��|jdtjj|j���|jddj|��tj �j"}|jdtj$j|���tj&�}|D�cgc]}||vr|��
}	}|	s!|jdtj(�y|jdt*j,dtj.ifg�y	cc}w)
a*
        Checks if the purge operation involves a kernel.

        When package called 'linux-image-*' is in the package list, warn the
        user that a kernel is being removed. Then, show the user what the
        current kernel is.

        If the current kernel is to be removed, and there are no other valid
        Ubuntu Kernels installed in the system, return False to abort the
        operation.

        If there is another Ubuntu kernel - besides the one installed - then
        prompt the user for confirmation before proceeding.
        �rercrf)�kernel_versionF�message_operation�msgT)�re�search�
RE_KERNEL_PKGr&r{�group�is_interactiver�#NonInteractiveKernelPurgeDisallowedrkr�PURGE_KERNEL_REMOVALr,rPrmr�get_kernel_info�
uname_release�PURGE_CURRENT_KERNEL�get_installed_ubuntu_kernels�PURGE_NO_ALTERNATIVE_KERNELr�prompt_for_confirmation�PURGE_KERNEL_CONFIRMATION)
r�package_listra�linux_image_versionsr��m�current_kernel�installed_kernels�version�alternative_kernelss
          r ryz"RepoEntitlement.purge_kernel_check�s}�� "��#�	8�G��	�	�-����6�A��$�+�+�A�G�G�A�J�7�	8� ��*�*�,� �D�D�F�F��M�M���-�-�4�4�T�Z�Z�4�H�
�
�M�M�&�#�(�(�+?�"@�A�#�3�3�5�C�C�N��M�M���-�-�4�4�#1�5��
�!'� C� C� E�� 1�#���"6�6��#��#�'��
�
�f�h�&J�&J�K���M�M�#��4�4��� B� B�C���
���)#s�9
Fc��d}|r_|jdtj�|jdtj|D�cgc]}|j
��c}��d}|rd|jdtj�|jdtj|D��cgc]\}}|j
��c}}��d}|r3|jdtjdtjifg�ycc}wcc}}w)NFreTr�r�)	rkr�WARN_PACKAGES_REMOVALr�create_package_list_strr&�WARN_PACKAGES_REINSTALLr��PROCEED_YES_NO)rr�r�ra�promptr��_s       r r}z RepoEntitlement.prompt_for_purge!s�������M�M�&�(�"@�"@�A��M�M���,�,�1C�D�g�W�\�\�D��
��F� ��M�M�&�(�"B�"B�C��M�M���,�,�6K�L�l�w��W�\�\�L��
��F���M�M�#��4�4��� 7� 7�8���
���3E��Ms�D�&Dc���tj�}|D�cgc]}|j|vr|j��}}|r5tj|tj
j
|���yycc}w)Nrg)r�get_installed_packages_namesr&�purge_packagesr�UNINSTALLING_PACKAGES_FAILEDr,)rr��installed_packagesr��	to_removes     r r�zRepoEntitlement.execute_removalHs��
!�=�=�?��.�
���|�|�1�1�
�L�L�
�	�
�
������5�5�<�<�&�=��
���
s�!A4c���tj�}|D��cgc]9\}}|j|vr&dj|j|j���;}}}|rtj
|�yycc}}w)Nz{}={})rr�r&r,�ver_str�reinstall_packages)rr�r�r�r��to_reinstalls      r r�z!RepoEntitlement.execute_reinstall[ss��!�=�=�?��'<�
�"��'��|�|�1�1�
�N�N�7�<�<����9�
��
�
��"�"�<�0���
s�>A4c��tjtjj	|j
��f}|j}|jdi�jdi�}|jd�}|s:tjtjj	|j
��fS|jd�}|s:tjtjj	|j
��fStjtj��}|D]p}tj|jj	||�|�}|s�6tj tj"j	|j
��f}n|j$rc|j&D]T}	tj(|	�r�tjtj*j	|j,|	��fcS|S)Nrvr2r3r;r@)�	error_msg)rdr�)r�DISABLEDr�SERVICE_NOT_CONFIGUREDr,rPr5r6�NO_APT_URL_FOR_SERVICE�NO_SUITES_FOR_SERVICEr�get_apt_cache_policy�APT_POLICY_FAILEDr�r�r0�ENABLED�SERVICE_IS_ACTIVE�check_packages_are_installedr8�is_installed� SERVICE_DISABLED_MISSING_PACKAGEr&)
r�current_statusr5r3�repo_url�repo_suites�policy�suite�
service_matchr�s
          r �application_statusz"RepoEntitlement.application_statushs���
�&�&��+�+�2�2����2�D�
��
�.�.��$�(�(���;�?�?��"�
�
��>�>�(�+���!�*�*��/�/�6�6�T�Z�Z�6�H��
�!�n�n�X�.���!�*�*��.�.�5�5�D�J�J�5�G��
�
�)�)�H�4N�4N�O�� �		�E��I�I��+�+�2�2�8�U�C�V��M��%�-�-��.�.�5�5�D�J�J�5�G�"���		��,�,��=�=�
���'�'��0�)�2�2� �A�A�H�H�$(�I�I�w�I����
��r"c���|j}td�tj|�j	�jd�D��ry|syt
|tj|�v�S)z�Check if apt url delta should be applied.

        :param apt_url: string containing the apt url to be used.

        :return: False if apt url is already found on the source file.
                 True otherwise.
        c3�>K�|]}|jd����y�w)�#N)�
startswith)�.0�lines  r �	<genexpr>z<RepoEntitlement._check_apt_url_is_applied.<locals>.<genexpr>�s!����
��
�O�O�C� �
�s��
FT)r-�allr�	load_file�strip�split�bool)rr=�apt_files   r �_check_apt_url_is_appliedz)RepoEntitlement._check_apt_url_is_applied�sm���>�>���
��(�(��2�8�8�:�@�@��F�
�
�����G�v�/�/��9�9�:�:r"�orig_access�deltas�allow_enablec�h��t�
|�|||�ry|jdi�}|jdi�}|jd�}|jd�}tj�}|r|r|j�}	n|j
�\}	}
|	tjk(ry|j|�s�tjd|j|�tjtjj!|j���|jdi�}|jdi�jd�}|r t#j$|j&|�|j)t+j,��|j/t+j,��|r}tjd	|�tjtj0j!d
j3|����|j5t+j,�|��y)
a1Process any contract access deltas for this entitlement.

        :param orig_access: Dictionary containing the original
            resourceEntitlement access details.
        :param deltas: Dictionary which contains only the changed access keys
        and values.
        :param allow_enable: Boolean set True if allowed to perform the enable
            operation. When False, a message will be logged to inform the user
            about the recommended enabled service.

        :return: True when delta operations are processed; False when noop.
        Tr2r3r;r4Fz.New aptURL, updating %s apt sources list to %srcz%New additionalPackages, installing %r�, rg)r�)rQ�process_contract_deltasr6r�read�"_check_application_status_on_cacher�rr�r��LOGrer&rFr�REPO_UPDATING_APT_SOURCESr,r�remove_auth_apt_repor-rr
�ProgressWrapperri� REPO_REFRESH_INSTALLING_PACKAGESrmrn)rr�r�r��delta_entitlement�delta_directives�
delta_apt_url�delta_packages�status_cacher�r��orig_entitlement�old_urlrYs             �r r�z'RepoEntitlement.process_contract_deltas�s����$�7�*�;���M��"�J�J�}�b�9��,�0�0��r�B��(�,�,�X�6�
�)�-�-�.B�C��(�-�-�/����!%�!H�!H�!J��$(�$;�$;�$=�!����!2�!;�!;�;���-�-�m�<��H�H�@��	�	��
�

�J�J��2�2�9�9�$�)�)�9�L�
� +���}�b�A��&�*�*�<��<�@�@��J�G���(�(�����A��"�"�3�#6�#6�#8�9��!�!�#�"5�"5�"7�8���H�H�<�n�M��J�J��9�9�@�@�!�Y�Y�~�6�A��
�

�!�!��#�#�%�N�
"�
�r"r��cleanup_on_failurec���|s|j}|sy|jd|jjd��	|j	|�|jtjj|j���|jr	ddi}gd�}nd}g}	t!j"|||��y#t
j$r'|r#|jtj���wxYw#t
j$rU|rQt$j'd	j|j(��|jtj���wxYw)
z�Install contract recommended packages for the entitlement.

        :param package_list: Optional package list to use instead of
            self.packages.
        :param cleanup_on_failure: Cleanup apt files if apt install fails.
        Nr��pre_installrv�DEBIAN_FRONTEND�noninteractive)z--allow-downgradesz$-o Dpkg::Options::="--force-confdef"z$-o Dpkg::Options::="--force-confold")r8�apt_options�override_env_varsz.Apt install failed, removing apt config for {})r8rk�	messagingr6�_update_sources_listr�UbuntuProErrorrr
r�rar�INSTALLING_SERVICE_PACKAGESr,rP�apt_noninteractiver�run_apt_install_commandr�rer&)rrar�r�r�r�s      r rnz RepoEntitlement.install_packages�sC����=�=�L����
�
�)�4�>�>�+=�+=�m�+L�M�	��%�%�h�/�	����0�0�7�7�d�j�j�7�I�	
��"�"�!2�4D� E���K�!%���K�	��'�'�%�'�"3�
��+�(�(�	�!��&�&�s�':�':�'<�=��	��4�(�(�	�!����D�K�K��	�	���
�&�&�s�':�':�'<�=��	�s�B;�"C8�;:C5�8A(E c��
�d}d}d}|jjs|jjr�tjd|jjtj
�}tjd|jjtj�}tjj}n�|jjs|jjr�tjd|jjtj
�}tjd|jjtj�}tjj}tj|||��|j}|j}|dj!di�}|dj!di�}|j!d�}	|	s�|j"j$d	}
|j!d
�sNt'j(|j�}|j+|
|j,�}|r|j!d�}	|	s"|
}	t.j1d|j2�|j!d�}
|
s t5j6|j,�
��|j!d�}|s t5j8|j,�
��|j!d�}|s t5j:|j,�
��|j<r�|j>s+t5j@|j,|j2���|jBjE|j,��}tjF|||j>|j<�g}tItjJ�s|jMd�tItjN�s|jMd�|rV|jQdtRjTjEdjW|����	tjX|��tjb||jdjE|�|	||jf�|jitRjjjE|j2���	tjl|�y#t4jZ$r%|j]t_j`���wxYw#t4jZ$r'|j]t_j`�d���wxYw)z�Setup apt config based on the resourceToken and directives.
        Also sets up apt proxy if necessary.

        :raise UbuntuProError: on failure to setup any aspect of this apt
           configuration
        Nr�https)�
http_proxy�https_proxy�proxy_scoper2r3�obligations�
resourceToken�machineToken�enableByDefaultzWNo resourceToken present in contract for service %s. Using machine token as credentials�aptKey�rOr;r@rN�r&zapt-transport-httpszca-certificatesrer�rgF)�run_apt_update)7�cfg�global_apt_http_proxy�global_apt_https_proxyr�validate_proxy�PROXY_VALIDATION_APT_HTTP_URL�PROXY_VALIDATION_APT_HTTPS_URLr�
AptProxyScope�GLOBAL�ua_apt_http_proxy�ua_apt_https_proxy�UACLIENT�setup_apt_proxyr-r5r6�machine_token_file�
machine_tokenr�UAContractClient�get_resource_machine_accessr&r��warningrPr�RepoNoAptKey�MissingAptURLDirective�RepoNoSuitesr!rS�RepoPinFailNoOrigin�repo_pref_file_tmplr,�add_ppa_pinningr�APT_METHOD_HTTPS_FILEr{�CA_CERTIFICATES_FILErkr�INSTALLING_PACKAGESrmr�r�rr
r��add_auth_apt_repor/rKra�APT_UPDATING_LIST�update_sources_list)rrar�r��scope�
repo_filename�resource_cfgr3r��tokenr�client�machine_accessrr�r��repo_pref_file�prerequisite_pkgss                  r riz RepoEntitlement.setup_apt_config1sX���
������8�8�)�)�T�X�X�-L�-L��,�,�����.�.��2�2��J�
�-�-�����/�/��3�3��K�
�%�%�,�,�E�
�X�X�
'�
'�4�8�8�+F�+F��,�,�����*�*��2�2��J�
�-�-�����+�+��3�3��K�
�%�%�.�.�E����!�{��	
����
��+�+��!�-�0�4�4�\�2�F�
�"�=�1�5�5�m�R�H��� � ��1��� �3�3�A�A���M��?�?�#4�5�"�2�2�4�8�8�<��!'�!C�!C�!�4�9�9�"��"�*�.�.��?�E��%�����:��J�J��
����)����)�)�4�9�9�E�E��>�>�(�+����3�3�T�Y�Y�O�O� �n�n�X�.����)�)�4�9�9�E�E��!�!��;�;� �4�4�%)�Y�Y��*�*���"�5�5�<�<�$�)�)�<�L�N����������&�&�	
����c�/�/�0��$�$�%:�;��c�.�.�/��$�$�%6�7���M�M���,�,�3�3�!�Y�Y�'8�9�4��
�
��+�+�5F�G�	�������%�%�h�/������	
�	���(�4�4�;�;����;�L�M�	��#�#�M�2��!�,�,�
��&�&�s�':�':�'<�=��
��"�(�(�	��"�"�3�#6�#6�#8��"�O��	�s�S)�T$�)8T!�$:Urc�`�tj�j}|j}|jj�|jjdi�}|jdi�}|jd�}|s tj|j���|jj|�}|jtjj|j���t!j"|||j$�t!j&||�|j(r;|j*j|j��}tj,|�|r4|jtj.�t!j0�yy)z�Remove any repository apt configuration files.

        :param run_apt_update: If after removing the apt update
            command after removing the apt files.
        r2r3r;rrvrN)rr(r)r-r�entitlementsr&r6rrr/r,rar�REMOVING_APT_CONFIGURATIONrPrr�rK�remove_apt_list_filesr!r�ensure_file_absent�APT_UPDATING_LISTS�run_apt_update_command)	rrarr)r#r2�access_directivesr�r(s	         r rz!RepoEntitlement.remove_apt_config�sN���(�(�*�1�1�����
��-�-�:�:�<�T�Y�Y�G�K�K��2�
��(�O�O�L�"�=��$�(�(��2����3�3�T�Y�Y�O�O��%�%�,�,�X�6������/�/�6�6�T�Z�Z�6�H�	
�	� � ���$�:L�:L�M��!�!�(�F�3��!�!�!�5�5�<�<�$�)�)�<�L�N��%�%�n�5�����h�9�9�:��&�&�(�r")F)NT)T)4�__name__�
__module__�__qualname__r+rr/rSr�r��supports_purge�propertyr	�int�strr!r-r0rr8rr=rAr�rI�abc�abstractmethodrKrrrRr`r
r�rorqr�ryr}r�r�rr�NamedMessager�r�rrr�rnrir�
__classcell__)rYs@r rr#s����H�N�@���M��F���$)� ��N���5��c�4��#8�����O�3�O��O��*��*��*���$�s�)���� �
��#��
��
��
�H�S�M�
��
��4������
�s�
���
�16��)-��	�t�X�/�0�0�	1��,�c����(;�(;����.�s��*��)<�)<�*�X?��9L�9L�?�B%��%�%�	%�N�&1�/�	� �(�8�+@�+@�"A�A�	B�/�b;�<#�	A��#�s�(�^�A��S�#�X��A��	A�

�A�L-1�#'�	9��%�%�9��t�C�y�)�9�!�	9�

�9�vy��)<�)<�y��y�| $�")��%�%�")��")r"r)(r9r7�loggingr��os.pathr�typingrrrrrr	�uaclientr
rrr
rrrrr�uaclient.entitlementsr�(uaclient.entitlements.entitlement_statusrrr�uaclient.files.state_filesr�get_event_loggerrF�	getLogger�replace_top_level_logger_namer2r�r��
UAEntitlementrrr"r �<module>rHs���
���	��:�:�
�
�
�'���
9�%��%�%�'���g���:��:�:�8�D�E��P�
�k
)�d�(�(�k
)r"

Zerion Mini Shell 1.0