HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/uaclient/entitlements/__pycache__/__init__.cpython-310.pyc
o

nHJe	�
@sddlZddlZddlmZmZmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZdd
lmZmZddlmZddlmZdd
lmZddlmZmZddl m!Z!ddl"m#Z#e
eeeeej$ej%ej&eeeeeg
Z'd3de	de(de(fdd�Z)	d4de	de*de*dee(fdd�Z+de	dee(dee(fdd�Z,ej-Gd d!�d!ej.��Z/de	dee(fd"d#�Z0de	dee(fd$d%�Z1de	d&eed'e/d(ee(e*fd)ee(f
d*d+�Z2de	d'e/dee(fd,d-�Z3d.ee(de	fd/d0�Z4de	de*dej5fd1d2�Z6dS)5�N)�Dict�List�Type)�
exceptions)�UAConfig)�fips)�AnboxEntitlement)�
UAEntitlement)�CommonCriteriaEntitlement)�CISEntitlement)�ESMAppsEntitlement�ESMInfraEntitlement)�LandscapeEntitlement)�LivepatchEntitlement)�RealtimeKernelEntitlement)�ROSEntitlement�ROSUpdatesEntitlement)�EntitlementNotFoundError)�is_config_value_true��cfg�name�variantcCsVtD]#}||d�}||jvr%|s|S||jvr |j|St|d��qt|d��)aReturns a UAEntitlement class based on the provided name.

    The return type is Optional[Type[UAEntitlement]].
    It cannot be explicit because of the Python version on Xenial (3.5.2).
    :param cfg: UAConfig instance
    :param name: The name of the entitlement to return
    :param not_found_okay: If True and no entitlement with the given name is
        found, then returns None.
    :raise EntitlementNotFoundError: If not_found_okay is False and no
        entitlement with the given name is found, then raises this error.
    �r)�entitlement_name)�ENTITLEMENT_CLASSES�valid_names�variantsr)rrr�entitlement�ent�r �@/usr/lib/python3/dist-packages/uaclient/entitlements/__init__.py�entitlement_factory%s



�
r"F�
allow_beta�	all_names�returncslt�jd�}||O}t}|sdd�|D�}|r+g}|D]}|�|�d�j�qt|�St�fdd�|D��S)aReturn a list of valid (non-beta) services.

    :param cfg: UAConfig instance
    :param allow_beta: if we should allow beta services to be marked as valid
    :param all_names: if we should return all the names for a service instead
        of just the presentation_name
    zfeatures.allow_betacSsg|]}|js|�qSr )�is_beta��.0rr r r!�
<listcomp>Ls��z"valid_services.<locals>.<listcomp>rcsg|]}|�d�j�qS)r)�presentation_namer'rr r!r)Zs
��)rrr�extendr�sorted)rr#r$�allow_beta_cfg�entitlements�namesrr rr!�valid_services=s"
�
��r0�entscs(t|���fdd��t|�fdd�d�S)zR
    A function to sort entitlments for enabling that preserves invalid names
    cs(z��|�WStyt��YSw�N)�index�
ValueError�len�r)�valid_ents_orderedr r!� sort_order_with_nonexistent_lastis
�zIorder_entitlements_for_enabling.<locals>.sort_order_with_nonexistent_lastcs�|�Sr2r r6)r8r r!�<lambda>osz1order_entitlements_for_enabling.<locals>.<lambda>)�key)�entitlements_enable_orderr,)rr1r )r8r7r!�order_entitlements_for_enablingasr<c@seZdZe�Ze�ZdS)�	SortOrderN)�__name__�
__module__�__qualname__�object�REQUIRED_SERVICES�DEPENDENT_SERVICESr r r r!r=rs
r=cC�t|tjd�S)zR
    Return the entitlements disable order based on dependent services logic.
    �r�
sort_order)�_sort_entitlementsr=rCrr r r!�entitlements_disable_orderx�rHcCrD)zP
    Return the entitlements enable order based on required services logic.
    rE)rGr=rBrr r r!r;rIr;�ent_clsrF�visited�ordercCsv|j|vrdS|tjkr||�j}n||�j}|D]}|j|vr)t|||||d�q|�t|j��d|t|j�<dS)N�rrJrFrKrLT)rr=rB�required_services�dependent_services�_sort_entitlements_visit�append�str)rrJrFrKrL�cls_list�cls_dependencyr r r!rP�s"



��rPcCs(g}i}tD]}t|||||d�q|S)NrM)rrP)rrFrLrKrJr r r!rG�s�rGr/cCsFg}|D]}|t|ddd�vr|�|�qtt|�t|��}||fS)z�Return a list of valid entitlement names.

    :param names: List of entitlements to validate
    :return: a tuple of List containing the valid and invalid entitlements
    T)rr#r$)r0rQr,�set)r/r�entitlements_found�ent_name�entitlements_not_foundr r r!�get_valid_entitlement_names�s�
�rYcCsLt||d�}d�|�}d�tjd|ddddd��}tjd	d�|�|d
�S)z{
    Constructs the MESSAGE_INVALID_SERVICE_OP_FAILURE message
    based on the attempted services and valid services.
    )rr#z, �
zTry �.�PF)�width�break_long_words�break_on_hyphens�enable)�	operation�invalid_service�service_msg)r0�join�textwrap�wrapr�InvalidServiceOpError)rXrr#�valid_services_namesrrcr r r!�*create_enable_entitlements_not_found_error�s

���ri)r)FF)7�enumre�typingrrr�uaclientr�uaclient.configr�uaclient.entitlementsr�uaclient.entitlements.anboxr�uaclient.entitlements.baser	�uaclient.entitlements.ccr
�uaclient.entitlements.cisr�uaclient.entitlements.esmrr
�uaclient.entitlements.landscaper�uaclient.entitlements.livepatchr�uaclient.entitlements.realtimer�uaclient.entitlements.rosrr�uaclient.exceptionsr�
uaclient.utilr�FIPSEntitlement�FIPSUpdatesEntitlement�FIPSPreviewEntitlementrrRr"�boolr0r<�unique�Enumr=rHr;rPrGrY�UbuntuProErrorrir r r r!�<module>s������
�$��
����
�
����