%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__/base.cpython-312.pyc

�

�Hcf����ddlZddlZddlZddlZddlmZddlmZmZmZm	Z	m
Z
mZmZm
Z
ddlmZmZmZmZmZmZmZmZmZmZmZddlmZddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&ddl'm(Z(m)Z)dd	l*m+Z+ejX�Z-ej\ej^e0��Z1Gd
�d�Z2Gd�d
ejf��Z4y)�N)�datetime)�Any�Dict�List�Optional�Set�Tuple�Type�Union)�api�apt�config�contract�event_logger�
exceptions�http�messages�snap�system�util)�_is_attached)�ApplicabilityStatus�ApplicationStatus�CanDisableFailure�CanDisableFailureReason�CanEnableFailure�CanEnableFailureReason�ContractStatus�UserFacingStatus)�status_cache_file)�MessagingOperationsDict�StaticAffordance)�is_config_value_truec�6�eZdZdeddej
fd�Zy)�EntitlementWithMessage�entitlement�
UAEntitlement�	named_msgc� �||_||_y�N)r&r()�selfr&r(s   �</usr/lib/python3/dist-packages/uaclient/entitlements/base.py�__init__zEntitlementWithMessage.__init__)s��
'���"���N)�__name__�
__module__�__qualname__r
r�NamedMessager-�r.r,r%r%(s$��#��/�*�#��(�(�#r.r%c���eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZedefd��Zedeefd��Zeej0defd	���Zeej0defd
���Zedefd��Zdeeefdeee e!jDffd
�Z#edefd��Z$edee%dffd��Z&edee'dffd��Z(edee'dffd��Z)edee*ddffd��Z+deee*dffd�Z,de-efd�Z.deee*dffd�Z/edeee*dffd��Z0edeee*dffd��Z1ede dfd��Z2ede3fd��Z4							dSde e5jldedededed ed!e eeddfd"�Z7ed#��Z8d$�Z9ed%��Z:ej0de;fd&��Z<ej0de;fd'��Z=de;fd(�Z>de;fd)�Z?deee e@ffd*�ZAd+eBj�deeeDde@fffd,�ZEd+eBj�defd-�ZFdefd.�ZGd+eBj�defd/�ZHdefd0�ZIej0d+eBj�defd1��ZJdee'fd2�ZKdefd3�ZLd+eBj�deee e!jDffd4�ZMd5�ZNd6�ZOd+eBj�deee e!jDffd7�ZP	dTd8edeee eQffd9�ZRd+eBj�deee eQffd:�ZSej0d+eBj�defd;��ZTdefd<�ZUdee*dfd=�ZVd+eBj�deee e!jDffd>�ZWdefd?�ZX	dTd@edAeddfdB�ZYdeeZe e!jDffdC�Z[de\fdD�Z]dee^e e!jDffdE�Z_ej0dee`e e!jDffdF��Zadeee e!jDffdG�Zbde efdH�ZcdefdI�Zdde`fdJ�ZedKeeefdLe edefdM�Zf	dTdNeeefdOeeefdPedefdQ�Zgd+eBj�fdR�Zhy)Ur'NF�r3T�returnc��y)z?The lowercase name of this entitlement, in case it is a variantr5r3�r+s r,�variant_namezUAEntitlement.variant_nameYs��r.c��|jg}|j|jk7r|j|j�|S)z1The list of names this entitlement may be called.)�name�presentation_name�append)r+�valid_namess  r,r>zUAEntitlement.valid_names^s;���y�y�k���!�!�T�Y�Y�.����t�5�5�6��r.c��y)z,The human readable title of this entitlementNr3r8s r,�titlezUAEntitlement.titlef���	
r.c��y)z&A sentence describing this entitlementNr3r8s r,�descriptionzUAEntitlement.descriptionlrAr.c��|jr|jS|jjjrF|j
j
di�j
di�j
d|j�S|jS)z/The user-facing name shown for this entitlementr&�affordances�presentedAs)�
is_variantr9�cfg�machine_token_file�
is_present�entitlement_cfg�getr;r8s r,r<zUAEntitlement.presentation_namersm���?�?��$�$�$�
�X�X�
(�
(�
3�
3��$�$�(�(���;���]�B�'���]�D�I�I�.�
��9�9�r.�platform_checkc��y)z�Verify specific platform checks for a service.

        This should only be used if the service requires custom platform checks
        to check if it is available or not in the machine.
        �TNr3)r+rMs  r,�verify_platform_checksz$UAEntitlement.verify_platform_checks�s��r.c�*�|j}|jrt|jj�D��cgc]!\}}dj||j���#}}}djdtjzdzg|z�}||z
}|Scc}}w)z$Help information for the entitlementz
  * {}: {}�
z

)�	help_text�variants�items�formatrC�joinr�CLI_HELP_VARIANTS_HEADER)r+rSr9�variant_cls�
variant_items�variant_texts      r,�	help_infozUAEntitlement.help_info�s����N�N�	��=�=�26���1D�1D�1F��-�L�+��#�#�L�+�2I�2I�J��M��
 �9�9��(�;�;�;�d�B�C�� ��L�
��%�I����s�&B.c��y)Nr3r3r8s r,�static_affordancesz UAEntitlement.static_affordances�s��r.c��|jS)a
        Return a list of packages that aren't compatible with the entitlement.
        When we are enabling the entitlement we can directly ask the user
        if those entitlements can be disabled before proceding.
        Overridden in livepatch and fips
        )�_incompatible_servicesr8s r,�incompatible_servicesz#UAEntitlement.incompatible_services�s���*�*�*r.c��|jS)a
        Return a list of packages that must be active before enabling this
        service. When we are enabling the entitlement we can directly ask
        the user if those entitlements can be enabled before proceding.
        Overridden in ros and ros-updates.
        )�_required_servicesr8s r,�required_serviceszUAEntitlement.required_services�s���&�&�&r.c��|jS)a
        Return a list of packages that depend on this service.
        We will use that list during disable operations, where
        a disable operation will also disable all of the services
        required by the original service
        Overriden in esm-apps and esm-infra
        )�_dependent_servicesr8s r,�dependent_servicesz UAEntitlement.dependent_services�s���'�'�'r.c��iSr*r3r8s r,�
_get_variantszUAEntitlement._get_variants�s���	r.c��t�}|j�}|jdi�jdg�}|D]7}|jdi�jd�}|s�'|j|��9|S)zV
        Fetch all available variants defined in the Contract Server response
        r&�	overrides�selector�variant)�set�_base_entitlement_cfgrL�add)r+�valid_variantsrKrk�overriderms      r,�_get_contract_variantsz$UAEntitlement._get_contract_variants�s{������4�4�6��#�'�'�
�r�:�>�>�{�B�O�	�!�	,�H��l�l�:�r�2�6�6�y�A�G���"�"�7�+�	,�
�r.c��|j�}|j�}d|vrd|di}ni}t|�D]}||vs�||||<�t|�dkDr|SiS)N�generic�)rirs�sorted�len)r+�service_variants�contract_variantsrqrms     r,�_get_valid_variantsz!UAEntitlement._get_valid_variants�s����-�-�/�� �7�7�9���(�(�'�)9�)�)D�E�N��N��/�0�	D�G��*�*�*:�7�*C��w�'�	D�"%�^�!4�q�!8�~�@�b�@r.c�>�|jriS|j�S)zf
        Return a list of services that are considered a variant
        of the main service.
        )rGr{r8s r,rTzUAEntitlement.variants�s���?�?��I��'�'�)�)r.c��|jsiS|j�j�D��cic]\}}||jk7r||��c}}Scc}}w)zw
        On a variant, return the other variants of the main service.
        On a non-variant, returns empty.
        )rGr{rUr9)r+r;�clss   r,�other_variantszUAEntitlement.other_variants�sZ������I�"�5�5�7�=�=�?�
���c��t�(�(�(�
�#�I�
�	
��
s�Ac�4�|jj�D]{}|jdk(r�||j|j|j
|j|j��}|j�\}}|tjk(s�y|cSy)z�
        On an enabled service class, return the variant that is enabled.
        Return None if no variants exist or none are enabled (e.g. access-only)
        ru)rH�
assume_yes�
allow_beta�called_name�access_onlyN)rT�valuesr9rHr�r��_called_namer��application_statusr�ENABLED)r+rYrm�status�_s     r,�enabled_variantzUAEntitlement.enabled_variant�s��� �=�=�/�/�1�	�K��'�'�9�4��!��H�H��?�?��?�?� �-�-� �,�,��G� �2�2�4�I�F�A��*�2�2�2���	�r.c��iSr*r3r8s r,�	messagingzUAEntitlement.messagings���	r.rHr�r�r�r��purge�
extra_argsc���|stj�}||_||_||_||_||_|�||_ng|_||_d|_	d|_
y)z]Setup UAEntitlement instance

        @param config: Parsed configuration dictionary
        NF)r�UAConfigrHr�r�r�r�r�r��_valid_service�_is_sources_list_updated)r+rHr�r�r�r�r�r�s        r,r-zUAEntitlement.__init__sc����/�/�#�C����$���$���&�����
��!�(�D�O� �D�O�'���"���(-��%r.c��|j�B|jxs.|jxs t|jjd�|_|jS)z2Check if the service is marked as valid (non-beta)zfeatures.allow_beta)r��is_betar�r#rHr8s r,�
valid_servicezUAEntitlement.valid_service4sV�����&��L�L� �M��?�?�M�'������6K�L�
���"�"�"r.c��tj|jjjj|ji��Sr*)�copy�deepcopyrHrI�entitlementsrLr;r8s r,roz#UAEntitlement._base_entitlement_cfg@s7���}�}��H�H�'�'�4�4�8�8����B�G�
�	
r.c��|j�}|jr|s|Stj||j��|S)N)�orig_accessrm)rorGr�apply_contract_overridesr9�r+rKs  r,rKzUAEntitlement.entitlement_cfgEs@���4�4�6�����o�"�"��)�)�'��1B�1B�	
��r.c��y)z�
        The number of steps that are reported as progress while enabling
        this specific entitlement that are not shared with other entitlements.
        Nr3r8s r,�enable_stepszUAEntitlement.enable_stepsR���	
r.c��y)z�
        The number of steps that are reported as progress while disabling
        this specific entitlement that are not shared with other entitlements.
        Nr3r8s r,�
disable_stepszUAEntitlement.disable_stepsZr�r.c�j�|j�}|jjdi�jdi�jd�}|�t|�dkDr|dz
}|jjdi�jdi�jd�}|�t|�dkDr|dz
}|j	�D].}||j|j�j�z
}�0|j�D].}||j|j�j�z
}�0|S)Nr&�
directives�
requiredSnapsrrv�requiredPackages)	r�rKrLrx�blocking_incompatible_servicesr&rHr��blocking_required_services)r+�total_steps�required_snaps�required_packages�incompatible_service�required_services      r,�calculate_total_enable_stepsz*UAEntitlement.calculate_total_enable_stepsbs8���'�'�)��� � �$�$�]�B�7�
�S��r�
"�
�S��
!�	�
�%�#�n�*=��*A��1��K�� � �$�$�]�B�7�
�S��r�
"�
�S�#�
$�	�
�(�S�1B�-C�a�-G��1��K�$(�$G�$G�$I�	� ��/�;�;������m�o�
�K�	�!%� ?� ?� A�	���+�7�7������l�n�
�K�	��r.c��|j�}|j�D]%}|||j�j�z
}�'|Sr*)r��blocking_dependent_servicesrH)r+r��dependent_services   r,�calculate_total_disable_stepsz+UAEntitlement.calculate_total_disable_steps|sN���(�(�*��!%�!A�!A�!C�	G���,�T�X�X�6�D�D�F�F�K�	G��r.c��|j�r?tjd|j�t	j
|j�|j�tjk(sEdttjtjj|j ����fS|j#�\}}|t$j&k7rEdttj(tj(j|j ����fS|j*sdttj,�fS|j/�\}}|t0j2k(rdttj2|��fS|j4r+|j7�rdttj8�fS|j:r+|j=�sdttj>�fS|j@sP|jBrDdttjDtjFj|j ���fSy)z�
        Report whether or not enabling is possible for the entitlement.

        :return:
            (True, None) if can enable
            (False, CanEnableFailure) if can't enable
        z(Updating contract on service '%s' expiryF�r@��messagerO)$�is_access_expired�LOG�debugr;r�refreshrH�contract_statusr�ENTITLEDrr�NOT_ENTITLEDr�
UNENTITLEDrVr@r�r�DISABLED�ALREADY_ENABLEDr��IS_BETA�applicability_statusr�INAPPLICABLEra�detect_incompatible_services�INCOMPATIBLE_SERVICErd�check_required_services_active�INACTIVE_REQUIRED_SERVICES�supports_access_onlyr��ACCESS_ONLY_NOT_SUPPORTED� ENABLE_ACCESS_ONLY_NOT_SUPPORTED)r+r�r�r��detailss     r,�
can_enablezUAEntitlement.can_enable�s
���!�!�#��I�I�@�$�)�)�L����T�X�X�&��#�#�%��)@�)@�@�� �*�7�7�$�/�/�6�6�T�Z�Z�6�H���
�!%� 7� 7� 9���A��!2�!;�!;�;�� �*�:�:�$�4�4�;�;�$�*�*�;�M���
��!�!��+�,B�,J�,J�K�L�L�(,�(A�(A�(C�%��g��#6�#C�#C�C�� �*�7�7����
��%�%��0�0�2��$�.�C�C�����!�!��6�6�8��$�.�I�I�����(�(�T�-=�-=�� �*�D�D��=�=�D�D�"�j�j�E����
�r.�progressc�h�|jd|jjd��|j�\}}|s�|�y|jt
jk(r!|j|�\}}|sM||_d|fS|jt
jk(r!|j|�\}}|s||_d|fSd|fS|jd|jjd��|js$|j|�sy|j|�sy|j|�}|syy)aNEnable specific entitlement.

        @return: tuple of (success, optional reason)
            (True, None) on success.
            (False, reason) otherwise. reason is only non-None if it is a
                populated CanEnableFailure reason. This may expand to
                include other types of reasons in the future.
        �message_operation�pre_can_enable�FNF�
pre_enablerO)�emitr�rLr��reasonrr��handle_incompatible_servicesr�r��_enable_required_servicesr��handle_required_snaps�handle_required_packages�_perform_enable)r+r�r��fail�incompat_ret�error�req_ret�rets        r,�enablezUAEntitlement.enable�s4��	�
�
�����!3�!3�4D�!E�	
� �?�?�,��
�D���|�"���� 6� K� K�K�&*�&G�&G��'�#��e�$�#(�D�L� �$�;�&����)�D�D�E�"&�!?�!?��!I�����#(�D�L� �$�;�&��d�{�"��
�
�)�4�>�>�+=�+=�l�+K�L�����-�-�h�7�"��0�0��:�"��"�"�8�,����r.c��|jjdi�jdi�jd�}|�ytj�sD|j	dt
jjd���tj�tj�sF|j	dt
jjd	���	tjd�tj |�	tj"d�t)j*d|j,j.t(j0�}t)j*d|j,j2t(j4�}tj6||tj8��|r|j;t
j<�t?|d���D]}|d}	tj@|��y#tj$rR}tjd
|��|j	dt
jjd�
��Yd}~��sd}~wwxYw#tj$rU}tjd|��t$j't
jjd�
��Yd}~���d}~wwxYw#tjB$ro|jdd�}|jd�}	|j	dt
jDj|���tj||	|��Y��uwxYw)z. "install snaps necessary to enable a service.r&r�r�NT�info�snapd��packagesz
snapd snapz!Failed to install snapd as a snap)�exc_infozsnap install snapd)�commandzFailed to refresh snapd snapzsnap refresh snapdr�https)�
http_proxy�https_proxy�retry_sleepsc�$�|jd�S)Nr;)rL)�xs r,�<lambda>z5UAEntitlement.handle_required_snaps.<locals>.<lambda>Js��Q�U�U�6�]�r.)�keyr;�classicConfinementSupportF�channel)r)r��classic_confinement_support)#rKrLr�is_snapd_installedr�r�INSTALLING_PACKAGESrV�
install_snapd�is_snapd_installed_as_a_snap�install_snapr�ProcessExecutionErrorr��warning�EXECUTING_COMMAND_FAILED�run_snapd_wait_cmd�refresh_snap�eventr�r�validate_proxyrHr��PROXY_VALIDATION_SNAP_HTTP_URLr��PROXY_VALIDATION_SNAP_HTTPS_URL�configure_snap_proxy�SNAP_INSTALL_RETRIESr��INSTALLING_REQUIRED_SNAPSrw�
get_snap_info�SnapNotInstalledError� INSTALLING_REQUIRED_SNAP_PACKAGE)
r+r�r��er�r��snap_pkg�	snap_namer�r�s
          r,r�z#UAEntitlement.handle_required_snapss���
� � �$�$�]�B�7�
�S��r�
"�
�S��
!�	��!���&�&�(��M�M���4�4�;�;�W�;�M�
�
��� ��0�0�2��M�M���,�,�3�3�\�3�J�
�	
��!�!�'�*�	
����)�	����g�&��(�(��D�H�H�'�'��)L�)L�
�
��)�)��T�X�X�)�)�4�+O�+O�
��	
�!�!�!�#��2�2�	
�����h�@�@�A��~�3J�K�	�H� ��(�I�
��"�"�9�-�		�.��w�3�3�
����?�!��L��
�
���5�5�<�<� 4�=�����
���/�/�	��K�K�6��K�C��J�J��1�1�8�8�0�9��
�
��	��8�3�3�
�.6�l�l�/��/�+�#�,�,�y�1���
�
���=�=�D�D�&�E����!�!��#�0K���
�sE�H�I,�,K�I)�AI$�$I)�,K�?A
K�K�A>M�Mc��|jjdi�jdi�jd�}|sy|D�cgc]}|d��	}}tj�}t	|D�cgc]}||v��c}�Scc}wcc}w)�/install packages necessary to enable a service.r&r�r�Tr;)rKrLr
�get_installed_packages_names�all)r+r��package�
package_names�installed_packages�requireds      r,�are_required_packages_installedz-UAEntitlement.are_required_packages_installedcs���
� � �$�$�]�B�7�
�S��r�
"�
�S�#�
$�	�!��8I�J�W����J�
�J� �=�=�?���<I�J��X�+�
+�J�
�	
��K��
Ks�B�.Bc��|jjdi�jdi�jd�}|sy|j|�|D�cgc]}|d��	}}tj	d|�|jtjjdj|����tj|�ycc}w)	rr&r�r�Tr;zInstalling packages %r� r�)rKrL�_update_sources_listr�r�r�rr�rVrWr
�run_apt_install_command)r+r�r�rrs     r,r�z&UAEntitlement.handle_required_packagesws���
� � �$�$�]�B�7�
�S��r�
"�
�S�#�
$�	�!���!�!�(�+�8I�J�W����J�
�J��	�	�*�M�:�����(�(�/�/����-�0�
0�
�	
�
	�#�#�M�2���Ks�Cc��|jjdi�jdi�jd�}|sy|D�cgc]}|jdd�r|d��}}t|�dk(rytj	d	|�d
j|�}tjtjj|���tj|tjj|���ycc}w)rr&r�r�T�removeOnDisableFr;rzUninstalling packages %rrr�)rKrLrxr�r�rWr�r�r�UNINSTALLING_PACKAGESrVr
�remove_packages�UNINSTALLING_PACKAGES_FAILED)r+r�rr�package_names_strs     r,�!handle_removing_required_packagesz/UAEntitlement.handle_removing_required_packages�s���
� � �$�$�]�B�7�
�S��r�
"�
�S�#�
$�	�!��-�
���{�{�,�e�4�
�F�O�
�
�
��}���"���	�	�,�m�<��H�H�]�3��
�
�
��*�*�1�1�;L�1�M�	
�	�����1�1�8�8�*�
9�
�	
���-
s�Dc��y)a
        Enable specific entitlement. This should be implemented by subclasses.
        This method does the actual enablement, and does not check can_enable
        or handle pre_enable or post_enable messaging.

        @return: True on success, False otherwise.
        Nr3�r+r�s  r,r�zUAEntitlement._perform_enable�s��	
r.c���g}|jD]b}|j|j�j�\}}|tj
tjfvs�R|j|��d|S)zI
        :return: List of incompatible services that are enabled
        )rar&rHr�rr��WARNINGr=�r+r��service�
ent_statusr�s     r,r�z,UAEntitlement.blocking_incompatible_services�ss�����1�1�	$�G�#�/�/����9�L�L�N�M�J���!�)�)�!�)�)����
�
�7�#�
	$��
r.c�:�t|j��dkDS)z�
        Check for incompatible services.

        :return:
            True if there are incompatible services enabled
            False if there are no incompatible services enabled
        r)rxr�r8s r,r�z*UAEntitlement.detect_incompatible_services�s���4�6�6�8�9�A�=�=r.c��tj|jjd��}|j�D]�}|j	|jd��}t
jj|j|j��}|rd|fcS|jdt
jj|j���|j|�\}}|r��||r|jfcSd	fcSy
)a)
        Prompt user when incompatible services are found during enable.

        When enabling a service, we may find that there is an incompatible
        service already enable. In that situation, we can ask the user
        if the incompatible service should be disabled before proceeding.
        There are also different ways to configure that behavior:

        We can disable removing incompatible service during enable by
        adding the following lines into uaclient.conf:

        features:
          block_disable_on_enable: true
        z features.block_disable_on_enable)r�
path_to_valueT)r�)�service_being_enabledr�Fr��r#NrO)
rr#rHr�r&r�#E_INCOMPATIBLE_SERVICE_STOPS_ENABLErVr@r��DISABLING_INCOMPATIBLE_SERVICE�disabler�)r+r��cfg_block_disable_on_enabler#�ent�e_msgr�r�s        r,r�z*UAEntitlement.handle_incompatible_services�s���$'+�&?�&?��8�8�<�<�<�'
�#��:�:�<�	=�G��%�%�d�h�h�4�%�@�C��@�@�G�G�&*�j�j�%(�Y�Y�H��E�
+��e�|�#��M�M���7�7�>�>��I�I�?��
����H�-�I�C����T�T�\�\�<�<�t�<�<�)	=�,r.c�:�t|j��dk(S)z�
        Check if all required services are active

        :return:
            True if all required services are active
            False is at least one of the required services is disabled
        r)rxr�r8s r,r�z,UAEntitlement.check_required_services_actives���4�2�2�4�5��:�:r.c���g}|jD]b}|j|j�j�\}}|tj
tjfvs�R|j|��d|S)zF
        :return: List of required services that are disabled
        )rdr&rHr�rr�r!r=r"s     r,r�z(UAEntitlement.blocking_required_servicesss�����-�-�	$�G�#�/�/����9�L�L�N�M�J���!�)�)�!�)�)�"���
�
�7�#�
	$��
r.c���|j�D]�}|j|jd��}|jdtj
j
|j���|j|�\}}|r�qd}|r;|jr/|jjrd|jjz}tjj
||j��}||fcSy)	a,
        Prompt user when required services are found during enable.

        When enabling a service, we may find that there are required services
        that must be enabled first. In that situation, we can ask the user
        if the required service should be enabled before proceeding.
        T)r�r�r)r5rR)r�r#rO)r�r&rHr�r�ENABLING_REQUIRED_SERVICErVr@r�r��msg�ERROR_ENABLING_REQUIRED_SERVICE)r+r�r�r.r�r��	error_msgr4s        r,r�z'UAEntitlement._enable_required_services s���!%� ?� ?� A�	 ��"�.�.�t�x�x�D�.�I�C��M�M���2�2�9�9�#�)�)�9�L�
��
�
�8�,�I�C����	��D�L�L�T�\�\�-=�-=� $�t�|�|�'7�'7� 7�I��>�>�E�E�#�S�Y�Y�F����C�x��	 �"r.�ignore_dependent_servicesc���|j�\}}|tjk(rEdttj
tj
j|j����fS|j�\}}|jr|tjk(rEdttjtjj|j����fS|jr-|s+|j!�rdttj"�fS|j$sP|j&rDdttj(tj*j|j���fSy)z�Report whether or not disabling is possible for the entitlement.

        :return:
            (True, None) if can disable
            (False, CanDisableFailure) if can't disable
        Fr�r�rO)r�rr�rr�ALREADY_DISABLEDrrVr@r�rKrr��NOT_APPLICABLE�CANNOT_DISABLE_NOT_APPLICABLErg�detect_dependent_services�ACTIVE_DEPENDENT_SERVICES�supports_purger��PURGE_NOT_SUPPORTED�DISABLE_PURGE_NOT_SUPPORTED)r+r7r�r�r�s     r,�can_disablezUAEntitlement.can_disable>s^��!%� 7� 7� 9���A��!2�!;�!;�;��!�+�<�<�$�5�5�<�<�4�:�:�<�N���
�#'�";�";�"=���a��$�$�#�':�'G�'G�G��!�+�:�:�$�B�B�I�I�"�j�j�J����
��"�"�+D��-�-�/��%�/�I�I�����"�"�t�z�z��!�+�?�?��8�8�?�?�"�j�j�@����
�r.c��|jd|jjd��|j�\}}|sE|�y|jt
jk(r!|j|�\}}|s||_d|fSd|fS|j|�sy|j�sy|jd|jjd��y)a�Disable specific entitlement

        @param silent: Boolean set True to silence print/log of messages

        @return: tuple of (success, optional reason)
            (True, None) on success.
            (False, reason) otherwise. reason is only non-None if it is a
                populated CanDisableFailure reason. This may expand to
                include other types of reasons in the future.
        r��pre_disabler�F�post_disablerO)r�r�rLrAr�rr=�_disable_dependent_servicesr��_perform_disabler)r+r�rAr�r�r4s      r,r,zUAEntitlement.disable}s���	�
�
�)�4�>�>�+=�+=�m�+L�M� �,�,�.���T���|�"����*�D�D�E� �;�;�H�E���S��#&�D�L� �$�;�&��d�{�"��$�$�X�.���5�5�7���
�
�)�4�>�>�+=�+=�n�+M�N�r.c��y)a\
        Disable specific entitlement. This should be implemented by subclasses.
        This method does the actual disable, and does not check can_disable
        or handle pre_disable or post_disable messaging.

        @param silent: Boolean set True to silence print/log of messages

        @return: True on success, False otherwise.
        Nr3rs  r,rFzUAEntitlement._perform_disable�s��	
r.c�:�t|j��dkDS)z�
        Check for depedent services.

        :return:
            True if there are dependent services enabled
            False if there are no dependent services enabled
        r)rxr�r8s r,r<z'UAEntitlement.detect_dependent_services�s���4�3�3�5�6��:�:r.c��g}|jD]J}||j�j�\}}|tjk(s�:|j|��L|S)zo
        Return list of depedent services that must be disabled
        before disabling this service.
        )rgrHr�rr�r=)r+�blocking�dependent_service_clsr$r�s     r,r�z)UAEntitlement.blocking_dependent_services�se��
��%)�%<�%<�	7�!�1����� � �"�
�J���.�6�6�6���� 5�6�	7��r.c���|j�D]�}||jd��}|jdtjj|j���|j|�\}}|r�hd}|r;|jr/|jjrd|jjz}tjj||j��}d|fcSy	)
ay
        Disable dependent services

        When performing a disable operation, we might have
        other services that depend on the original services.
        If that is true, we will alert the user about this
        and prompt for confirmation to disable these services
        as well.

        @param silent: Boolean set True to silence print/log of messages
        T)rHr�r�)r�r5rR)r�r�FrO)r�rHr�r�DISABLING_DEPENDENT_SERVICErVr@r,r�r4�"FAILED_DISABLING_DEPENDENT_SERVICE)r+r�rKr.r�r�r6r4s        r,rEz)UAEntitlement._disable_dependent_services�s���&*�%E�%E�%G�	"�!�'�D�H�H��F�C��M�M���4�4�;�;�%(�Y�Y�<��
����H�-�I�C����	��D�L�L�T�\�\�-=�-=� $�t�|�|�'7�'7� 7�I��A�A�H�H�#�c�i�i�I����c�z�!�'	"�*r.c��y)z=Check if system needs to be rebooted because of this service.Fr3r8s r,�_check_for_rebootzUAEntitlement._check_for_reboot�s��r.�	operation�silentc��|j�r7|s4tjtjj|���yyy)z�Check if user should be alerted that a reboot must be performed.

        @param operation: The operation being executed.
        @param silent: Boolean set True to silence print/log of messages
        )rQN)rPr�r�r�ENABLE_REBOOT_REQUIRED_TMPLrV)r+rQrRs   r,�_check_for_reboot_msgz#UAEntitlement._check_for_reboot_msg�sB���!�!�#�F��J�J��4�4�;�;�'�<��
�-3�#r.c�t�|j}|s tjtjfS|j
D]$\}}}|�|k7s�tj|fcS|djdi�}|jdd�}|jr�|��tj�|vrrtj|�}tjtjj|jtj�dj!|���fS|jdd�}|j"ry|�wtj$�j&|vrWtjtj(j|jtj$�j*��fStj,�}	|jd	d�}
|jd
d�}|j.re|
�c|	j0|
vrUtjtj2j|j|	j4dj!|
���fS|j6r�|r�|	j8��|	j:��tj<j|j|	j4|��}	|j?d
�\}
}tA|
�}tA|�}|	j8|krtj|fS|	j8|k(r!|	j:|krtj|fS|jdi�}|jI|�\}}|stj|fStjdfS#tB$r+tDjGd|�tj|fcYSwxYw)a�Check all contract affordances to vet current platform

        Affordances are a list of support constraints for the entitlement.
        Examples include a list of supported series, architectures for kernel
        revisions.

        :return:
            tuple of (ApplicabilityStatus, NamedMessage). APPLICABLE if
            platform passes all defined affordances, INAPPLICABLE if it doesn't
            meet all of the provided constraints.
        r&rE�
architecturesNz, )r@�arch�supported_arches�series)r@rZ�
kernelFlavors�minKernelVersion)r@�kernel�supported_kernels)r@r]�
min_kernel�.z$Could not parse minKernelVersion: %s�platformChecks)%rKr�
APPLICABLEr�"NO_ENTITLEMENT_AFFORDANCES_CHECKEDr^r�rL�affordance_check_archr�
get_dpkg_archr�deduplicate_arches�INAPPLICABLE_ARCHrVr@rW�affordance_check_series�get_release_inforZ�INAPPLICABLE_SERIES�pretty_version�get_kernel_info�affordance_check_kernel_flavor�flavor�INAPPLICABLE_KERNEL�
uname_release�#affordance_check_kernel_min_version�major�minor�INAPPLICABLE_KERNEL_VER�split�int�
ValueErrorr�r�rP)r+rK�
error_message�functor�expected_resultrE�affordance_arches�deduplicated_arches�affordance_series�kernel_info�affordance_kernels�affordance_min_kernel�invalid_msg�kernel_major�kernel_minor�min_kern_major�min_kern_minor�affordances_platform_checkr�r�s                    r,r�z"UAEntitlement.applicability_statuss����.�.���#�.�.��;�;��
�8<�7N�7N�	G�3�M�7�O��y�O�+�*�7�7��F�F�	G�&�m�4�8�8���K��'�O�O�O�T�B���&�&�!�-��$�$�&�.?�?�"&�"9�"9�:K�"L��#�0�0��*�*�1�1��*�*��-�-�/�%)�Y�Y�/B�%C�2���
�(�O�O�H�d�;���(�(�!�-��'�'�)�0�0�8I�I�$�0�0��,�,�3�3��*�*�!�2�2�4�C�C�4���
��,�,�.��(�_�_�_�d�C�� +���0B�D� I���/�/�"�.��!�!�);�;�'�4�4��0�0�7�7�"�j�j�*�8�8�*.�)�)�4F�*G�8����
�4�4�%��!�!�-��!�!�-�"�:�:�A�A��j�j�"�0�0�0�B��K�
	
G�-B�-H�-H��-M�*��l�!$�\�!2��!$�\�!2��� � �>�1�*�7�7��D�D��!�!�^�3��%�%��6�*�7�7��D�D�%0�_�_�5E�r�%J�"��1�1�2L�M���V��'�4�4�f�=�=�"�-�-�t�3�3��)�
G����:�)��,�8�8�+�F�F�
G�s�<*N�1N7�6N7c���t|j�jstjS|j
}|r$|dj
d�rtjStjS)z=Return whether the user is entitled to the entitlement or notr&�entitled)rrH�is_attachedrr�rKrLr�r�s  r,r�zUAEntitlement.contract_statusnsX���D�H�H�%�1�1�!�,�,�,��.�.����}�=�A�A�*�M�!�*�*�*��(�(�(r.c���|j�\}}|tjk7rtj|fS|j
}|s:tjtjj|j��fS|djdd�dur:tjtjj|j��fS|j�\}}|tjk(rtj|fS|tj k(rtj |fS|j#�\}}|rtj |fStj$|fS)z4Return (user-facing status, details) for entitlementr�r&r�F)r�rrbrr�rK�UNAVAILABLEr�SERVICE_NOT_ENTITLEDrVr@rLr�rr��INACTIVEr!�enabled_warning_status�ACTIVE)r+�
applicabilityr�rKr��explanationr��warn_msgs        r,�user_facing_statusz UAEntitlement.user_facing_statuswsK��"&�!:�!:�!<��
�w��/�:�:�:�#�0�0�'�9�9��.�.��� �,�,��-�-�4�4�4�:�:�4�F��
��]�
+�
/�
/�
�E�
B�e�
K� �,�,��-�-�4�4�4�:�:�4�F��
�
+/�*A�*A�*C�'��K��!2�!;�!;�;�#�,�,�k�9�9�
�#4�#<�#<�
<�#�+�+�[�8�8� �7�7�9�����#�+�+�X�5�5��&�&��3�3r.c��y)z�
        The current status of application of this entitlement

        :return:
            A tuple of (ApplicationStatus, human-friendly reason)
        Nr3r8s r,r�z UAEntitlement.application_status�s��	
r.c��y)z�
        If the entitlment is enabled, are there any warnings?
        The message is displayed as a Warning Notice in status output

        :return:
            A tuple of (warning bool, human-friendly reason)
        r�r3r8s r,r�z$UAEntitlement.enabled_warning_status�s��r.c��yr*r3r8s r,�status_description_overridez)UAEntitlement.status_description_override�s��r.c��|jjd�}|sytj|d�}|tj�k\ryy)z<Return entitlement access info as stale and needing refresh.�expiresFz%Y-%m-%dT%H:%M:%S.%fZT)rKrLr�strptime�utcnow)r+�
expire_str�expirys   r,r�zUAEntitlement.is_access_expired�sH���)�)�-�-�i�8�
����"�"�:�/F�G���X�_�_�&�&��r.c�P�tj�}|�tjS|j	dg�}|D]Z}|j	d�|j
k(s�"|j	d�}|dk(rtjcStjcStjS)z6Check on the state of application on the status cache.�servicesr;r��enabled)r �readrr�rLr;r�)r+�status_cache�services_status_listr#�service_statuss     r,�"_check_application_status_on_cachez0UAEntitlement._check_application_status_on_cache�s���(�-�-�/����$�-�-�-�+�/�/�
�B�?��+�	6�G��{�{�6�"�d�i�i�/�!(���X�!6��!�Y�.�,�4�4�4�,�5�5�5�	6�!�)�)�)r.�obligations�
resourceTokenc�>�t|jd�xr|�S)N�enableByDefault)�boolrL)r+r�r�s   r,�_should_enable_by_defaultz'UAEntitlement._should_enable_by_default�s���K�O�O�$5�6�H�=�I�Ir.r��deltas�allow_enablec��|sy|jdi�}|jdi�}tj�}t|tj
k(�}|s9|rt
j|�|d}|rd|vr|ddtj
fv}|�rA|r|r|j�}n|j�\}}	|tjk7�r|j�\}
}|
r�tjd|j�|j!t#j$��t&jt(j*j-|j���y|r|j.nd}tj1d	|j|�t&jt(j2j-|j���y|jd
�}
|
s|jd
�}
|jdi�}|j5||
�}|rd|_|j9�\}}	|�r|�r|r�t(j:j-|j��}t&j|t<j>�
�|jAt#j$��t&jt(jBj-|jD���yt(jFj-|j��}t&j|t<j>�
�yy)auProcess 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.
        :raise: UbuntuProError when auto-enable fails unexpectedly.
        Tr&r�r�Fz3Disabling %s after refresh transition to unentitledr)r5zDCannot disable %s after refresh transition to unentitled.
Reason: %sr�r��r;)�	file_typer�)$rLr r�r�r�DROPPED_KEYrr�r�r�rr�rAr�r�r;r,r�ProgressWrapperr�r�DISABLE_DURING_CONTRACT_REFRESHrV�
message_valuer��)UNABLE_TO_DISABLE_DURING_CONTRACT_REFRESHr�r�r��ENABLE_BY_DEFAULT_TMPL�sys�stderrr��ENABLED_TMPLr@�ENABLE_BY_DEFAULT_MANUAL_TMPL)r+r�r�r��delta_entitlement�delta_directivesr��transition_to_unentitledr�r�rAr��fail_msgr��delta_obligations�enable_by_defaultr�r4s                  r,�process_contract_deltasz%UAEntitlement.process_contract_deltas�s���&��"�J�J�}�b�9��,�0�0��r�B��(�-�-�/��#'�(9�T�=M�=M�(M�#N� �'� ��1�1�&�9�$*�=�$9�!��z�->�>�+<�Z�+H���$�$�M�,�(�$��L�%)�%L�%L�%N�"�(,�(?�(?�(A�%�"�A�!�%6�%?�%?�?�$(�$4�$4�$6�!��T���H�H�M��	�	���L�L��!4�!4�!6�7��J�J� �@�@�G�G�$(�I�I�H���&�6:�t�1�1�r�H��K�K�2��	�	� �	��J�J� �J�J�Q�Q�$(�I�I�R���
�#����8�
��"�J�J��7�M�-�1�1�-��D�� �:�:��}�
���"�D�O����)�
�
�A��+���5�5�<�<�$�)�)�<�L���
�
�3�#�*�*�
�5����C�/�/�1�2��
�
�8�0�0�7�7�d�j�j�7�I�J��	�<�<�C�C����D����
�
�3�#�*�*�
�5��r.c���|jry|jdtjj	d���tjtj��d|_y)Nr�zstandard Ubuntur�T)r�r�r�APT_UPDATING_LISTrVr
�update_sources_list�get_system_sources_filers  r,rz"UAEntitlement._update_sources_list<sU���(�(���
�
��H�.�.�5�5�;L�5�M�	
�	���� ;� ;� =�>�(,��%r.)NFFr5FFN)F)ir/r0r1r;�help_doc_urlr�r�r�r>rSr`rcrfrdrhrqrmrG�property�strr9rr>�abc�abstractmethodr@rCr<rrr	r�rrr2rPr\r"r^r%rardr
rgrirrsr{rTrr�r!r�rr�r-r�rorKrvr�r�r�r�rr�rr�rr�r�rr�rr�r�r�r�r�r�r�rrAr,rFr<r�rErPrUrr�rr�rr�rr�r�r�r�r�r�r�rr3r.r,r'r'2s����D��L��J��G�!���N��I� ������ ��"��*.�'�%)�"��J�
��c������T�#�Y��������
�s�
���
�����
�S�
���
���3�����"�3��8�n��	�t�X�h�3�3�4�4�	5����3����*��E�*:�C�*?�$@�����+�u�-C�S�-H�'I�+��+��'�5�)?��)D�#E�'��'��(�E�$��*?��*D�$E�(��(��t�C��o�)>�$>�?��
��C��
�
A�T�#�t�O�/D�*D�%E�
A��*�$�s�D��$9�9�:�*��*��
��S�$��*?�%?� @�
��
����/�!:����,��2����
*.� � ��!��*.�.�
�f�o�o�
&�.��.��	.�
�.��
.��.��T�#�Y�'�.�
�.�:�	#��	#�
�
�
��
�	���
�c�
��
�	���
�s�
��
��c��4�s��I�E�$��1A�(B�"B�C�I�Z;��%�%�;�
�t�U�4�!1�1�2�2�	3�;�zU�c�.A�.A�U�d�U�n
��
�(��1D�1D����4#�4�#�J	���
��(;�(;�
��
��
�
��5K�0L�
�>�d�>�,��%�%�,�
�t�X�h�3�3�4�4�	5�,�\;����%�%��
�t�X�h�3�3�4�4�	5��>16�=�)-�=�	�t�X�/�0�0�	1�=�~(��+�+�(�	�t�X�/�0�0�	1�(�T	���

��)<�)<�

��

��

�;�4�;�
�T�$��2G�-H�
�#��+�+�#�	�t�X�h�3�3�4�4�	5�#�J�4��
.3�
��
�&*�
�	
�
�g4�	�"�H�X�-B�-B�$C�C�	D�g4�R)��)�4�	���(�*?�*?�!@�@�	A�4�B	���	
�	� �(�8�+@�+@�"A�A�	B�	
��	
�
�	�t�X�h�3�3�4�4�	5�
��	�#���
	�4�	�*�4E�*�(J���S��>�J�:B�3�-�J�	
�J�#�	a��#�s�(�^�a��S�#�X��a��	a�

�a�F-�S�-@�-@�-r.r')�	metaclass)5r�r��loggingr�r�typingrrrrrr	r
r�uaclientrr
rrrrrrrrr�(uaclient.api.u.pro.status.is_attached.v1r�(uaclient.entitlements.entitlement_statusrrrrrrrr�uaclient.files.state_filesr �uaclient.typesr!r"�
uaclient.utilr#�get_event_loggerr��	getLogger�replace_top_level_logger_namer/r�r%�ABCMetar'r3r.r,�<module>r�s���
���
��E�E�E�����B�	�	�	�9�D�.�%��%�%�'���g���:��:�:�8�D�E��#�#�Q-�c�k�k�Q-r.

Zerion Mini Shell 1.0