Your IP : 216.73.216.52


Current Path : /usr/lib/python3/dist-packages/uaclient/entitlements/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/uaclient/entitlements/__pycache__/__init__.cpython-38.pyc

U

8�-d<�
@s�ddlZddlZddlmZmZmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZmZdd
lmZddlmZddlmZmZdd
lmZddlmZeeeeej ej!eeeeg
Z"e	e#d�dd�Z$d,e	e%e%ee#d�dd�Z&e	ee#ee#d�dd�Z'ej(Gdd�dej)��Z*e	ee#d�dd�Z+e	ee#d�dd�Z,e	ee
e*ee#e%fee#d �d!d"�Z-e	e*ee#d#�d$d%�Z.ee#e	d&�d'd(�Z/e	e%ej0d)�d*d+�Z1dS)-�N)�Dict�List�Type)�messages)�UAConfig)�fips)�
UAEntitlement)�CommonCriteriaEntitlement)�CISEntitlement)�ESMAppsEntitlement�ESMInfraEntitlement)�LivepatchEntitlement)�RealtimeKernelEntitlement)�ROSEntitlement�ROSUpdatesEntitlement)�EntitlementNotFoundError)�is_config_value_true)�cfg�namecCs.tD]}|||d�jkr|Sqt|��dS)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.
    �rN)�ENTITLEMENT_CLASSES�valid_namesr)rr�entitlement�r�@/usr/lib/python3/dist-packages/uaclient/entitlements/__init__.py�entitlement_factory s
rF)r�
allow_beta�	all_names�returncslt�jd�}||O}t}|s*dd�|D�}|rVg}|D]}|�|�d�j�q6t|�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)Zis_beta��.0rrrr�
<listcomp>As�z"valid_services.<locals>.<listcomp>rcsg|]}|�d�j�qS)r)Zpresentation_namerrrrr!Os�)rrr�extendr�sorted)rrrZallow_beta_cfgZentitlements�namesrrrr�valid_services2s"
�
��r%)r�entsrcs(t|���fdd��t|�fdd�d�S)zR
    A function to sort entitlments for enabling that preserves invalid names
    cs.z��|�WStk
r(t��YSXdS�N)�index�
ValueError�len�Zent)�valid_ents_orderedrr� sort_order_with_nonexistent_last^szIorder_entitlements_for_enabling.<locals>.sort_order_with_nonexistent_lastcs�|�Sr'rr+)r-rr�<lambda>d�z1order_entitlements_for_enabling.<locals>.<lambda>)�key)�entitlements_enable_orderr#)rr&r)r-r,r�order_entitlements_for_enablingVsr2c@seZdZe�Ze�ZdS)�	SortOrderN)�__name__�
__module__�__qualname__�object�REQUIRED_SERVICES�DEPENDENT_SERVICESrrrrr3gsr3)rrcCst|tjd�S)zR
    Return the entitlements disable order based on dependent services logic.
    �r�
sort_order)�_sort_entitlementsr3r9rrrr�entitlements_disable_ordermsr=cCst|tjd�S)zP
    Return the entitlements enable order based on required services logic.
    r:)r<r3r8rrrrr1tsr1�r�ent_clsr;�visited�ordercCsv|j|krdS|tjkr$||�j}n
||�j}|D] }|j|kr2t|||||d�q2|�t|j��d|t|j�<dS)Nr>T)rr3r8Zrequired_servicesZdependent_services�_sort_entitlements_visit�append�str)rr?r;r@rAZcls_listZcls_dependencyrrrrB{s 



�rB)rr;rcCs(g}i}tD]}t|||||d�q|S)Nr>)rrB)rr;rAr@r?rrrr<�s�r<)r$rcCsFg}|D] }|t|ddd�kr|�|�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)rrr)r%rCr#�set)r$rZentitlements_foundZent_name�entitlements_not_foundrrr�get_valid_entitlement_names�s�rG)rrrcCsNt||d�}d�|�}d�tjd|ddddd��}tjjd	d�|�|d
�S)z{
    Constructs the MESSAGE_INVALID_SERVICE_OP_FAILURE message
    based on the attempted services and valid services.
    )rrz, �
zTry �.�PF)�widthZbreak_long_wordsZbreak_on_hyphens�enable)Z	operationZinvalid_service�service_msg)r%�join�textwrapZwraprZINVALID_SERVICE_OP_FAILURE�format)rFrrZvalid_services_namesrrMrrr�,create_enable_entitlements_not_found_message�s

���rQ)FF)2�enumrO�typingrrrZuaclientrZuaclient.configrZuaclient.entitlementsrZuaclient.entitlements.baserZuaclient.entitlements.ccr	Zuaclient.entitlements.cisr
Zuaclient.entitlements.esmrrZuaclient.entitlements.livepatchr
Zuaclient.entitlements.realtimerZuaclient.entitlements.rosrrZuaclient.exceptionsrZ
uaclient.utilrZFIPSEntitlementZFIPSUpdatesEntitlementrrDr�boolr%r2�unique�Enumr3r=r1rBr<rGZNamedMessagerQrrrr�<module>sl���%�
��