U
    2d2                     @   s   d dl Z d dlmZmZmZ d dlmZmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ d dlmZ G d	d
 d
ejZG dd deZG dd deZdS )    N)TupleTypeUnion)gpgsystem)APT_KEYS_DIRESM_REPO_FILE_CONTENTKEYRINGS_DIR)ESM_APT_ROOTDIR)repo)UAEntitlement)CanDisableFailurec                       sd   e Zd ZdZeeee df dddZde	e	d fdd	Z
d
dddZd
dddZ  ZS )ESMBaseEntitlementzhttps://ubuntu.com/security/esm.returnc                 C   s   ddl m}m} ||fS )Nr   )ROSEntitlementROSUpdatesEntitlement)Zuaclient.entitlements.rosr   r   )selfr   r    r   ;/usr/lib/python3/dist-packages/uaclient/entitlements/esm.pydependent_services   s    z%ESMBaseEntitlement.dependent_servicesF)silentr   c                    s4   ddl m} t j|d}|r0|| j |   |S Nr   )update_motd_messages)r   )uaclient.timer.update_messagingr   super_perform_enablecfgdisable_local_esm_repo)r   r   r   Zenable_performed	__class__r   r   r      s    
z"ESMBaseEntitlement._perform_enableNc                 C   s   t  j}| jdst| jtdd  }tj	t
| jj| jd }| j}tj|r^d S t |tj||d tjt|}tj	t
t | }tjtj|dd t|| d S )Nzesm-name)r"   seriesT)exist_ok)r   Zget_release_infor#   r"   
startswithAssertionErrorlenospathnormpathr
   repo_list_file_tmplformatrepo_key_fileexistsZ
write_filer   joinr	   r   makedirsdirnamer   Zexport_gpg_key)r   r#   Zesm_namerepo_filenamekeyring_fileZsource_keyring_fileZdestination_keyring_filer   r   r   setup_local_esm_repo!   s&    

z'ESMBaseEntitlement.setup_local_esm_repoc                 C   sJ   t jtt | j }t jt| jj| jd }t	
| t	
| d S )Nr!   )r(   r)   r*   r
   r   r-   r+   r,   r"   r   Zensure_file_absent)r   r3   r2   r   r   r   r   <   s    
z)ESMBaseEntitlement.disable_local_esm_repo)F)__name__
__module____qualname__Zhelp_doc_urlpropertyr   r   r   r   boolr   r4   r   __classcell__r   r   r   r   r      s   	r   c                       sH   e Zd ZdZdZdZdZdZdee	e
def f d fd	d
Z  ZS )ESMAppsEntitlementZUbuntuESMAppszesm-appszUbuntu Pro: ESM Appsz.Expanded Security Maintenance for Applicationszubuntu-pro-esm-apps.gpgFNr   c                    sD   ddl m} t j|d\}}|r<|| j t r<|   ||fS r   )r   r   r   disabler   r   Zis_current_series_ltsr4   r   r   r   Zdisable_performedZfailr   r   r   r<   N   s    
zESMAppsEntitlement.disable)F)r5   r6   r7   originr"   titledescriptionr-   r   r9   r   r   r<   r:   r   r   r   r   r;   G   s    r;   c                       sH   e Zd ZdZdZdZdZdZdee	e
def f d fd	d
Z  ZS )ESMInfraEntitlementz	esm-infraZ	UbuntuESMzUbuntu Pro: ESM Infraz0Expanded Security Maintenance for Infrastructurezubuntu-pro-esm-infra.gpgFNr   c                    sD   ddl m} t j|d\}}|r<|| j t r<|   ||fS r   )r   r   r   r<   r   r   Zis_current_series_active_esmr4   r=   r   r   r   r<   b   s    
zESMInfraEntitlement.disable)F)r5   r6   r7   r"   r>   r?   r@   r-   r   r9   r   r   r<   r:   r   r   r   r   rA   [   s    rA   )r(   typingr   r   r   Zuaclientr   r   Zuaclient.aptr   r   r	   Zuaclient.defaultsr
   Zuaclient.entitlementsr   Zuaclient.entitlements.baser   Z(uaclient.entitlements.entitlement_statusr   ZRepoEntitlementr   r;   rA   r   r   r   r   <module>   s   ;