o
    ÙKÕi  ã                   @   sü   d dl Z d dlmZmZ d dlmZmZ d dlmZ d dl	m
Z
mZmZ d dlmZmZ d dlmZ d dlmZ ejejd	�d
efdd„ƒZdd„ Zdd„ Zd
efdd„Zd
efdd„Zedejejeejdee
dejdd�e
dejdd�gd�gd�Z dS )é    N)Ú
exceptionsÚmessages)ÚCVEsOptionsÚ_cves)Úcli_util)ÚProArgumentÚProArgumentGroupÚ
ProCommand)ÚTableÚcreate_link)ÚHelpCategory)ÚUAConfig)ÚmsgÚcfgc                K   s>   t | j| jd�}z	t||d�}W |S  tjy   d }Y |S w )N)ÚfixableÚ	unfixable)Úoptionsr   )r   r   r   r   r   ÚVulnerabilityDataNotFound)Úargsr   ÚkwargsÚcve_optionsÚresult© r   ú3/usr/lib/python3/dist-packages/uaclient/cli/cves.pyÚ_get_cve_vulnerabilities   s   þýýr   c                 C   sV   g }| j  ¡ D ]!\}}|jD ]}| j |j¡}|r'| ||j|jp"d|jf¡ qq|S )Nú-)ÚpackagesÚitemsÚcvesÚgetÚnameÚappendÚpriorityÚ
fix_origin)Úcve_vulnerabilitiesÚrowsÚpackage_nameÚpackage_infoÚcveÚcve_infor   r   r   Ú_get_cve_table_rows   s   
üÿ€ür*   c                 C   sX   g }t | dd„ d�D ]}| |d t |d ¡|d t|d d |d ¡d	�f¡ q
|S )
Nc                 S   s   | d d  | d ¡fS )Nr   )ÚcriticalÚhighÚmediumÚlowÚ
negligibleé   )Úindex)Úrowr   r   r   Ú<lambda>3   s   þz"_format_cve_rows.<locals>.<lambda>)Úkeyr   r0   é   é   zhttps://ubuntu.com/security/{})ÚtextÚurl)Úsortedr!   r   Úcolorize_priorityr   Úformat)Úcve_rowsÚformatted_rowsr2   r   r   r   Ú_format_cve_rows/   s    
þþüÿr>   c                 C   s²   t | |d�}|st ¡ ‚|jr>tt|ƒƒ}|r#ttg d¢|d�ƒ d S | jr-tt	j
ƒ d S | jr7tt	jƒ d S tt	jƒ d S | jrHtt	j
ƒ d S | jrRtt	jƒ d S tt	jƒ d S )N)r   )ÚPackageÚPriorityÚOriginÚVulnerability)Úheadersr%   )r   r   r   r   r>   r*   Úprintr
   r   r   ÚCLI_UNFIXABLE_CVES_NOT_AFFECTEDr   ÚCLI_FIXABLE_CVES_NOT_AFFECTEDÚCLI_CVES_NOT_AFFECTED)r   r   r$   r%   r   r   r   Ú
_list_cvesG   s,   þÿrH   c                K   sL   | j r| jrtjddd�‚z	t| |d� W d S  ty%   tj ¡  Y d S w )Nr   r   )Úoption1Úoption2)r   r   )	r   r   r   ÚInvalidOptionCombinationrH   ÚBrokenPipeErrorÚsysÚstderrÚclose)r   r   r   r   r   r   Úaction_cvesg   s   ÿÿrP   r   Tz--unfixableÚ
store_true)ÚhelpÚactionz	--fixable)Ú	arguments)rR   ÚdescriptionrS   Úhelp_categoryÚpreserve_descriptionÚargument_groups)!rM   Úuaclientr   r   Ú#uaclient.api.u.pro.security.cves.v1r   r   Úuaclient.clir   Úuaclient.cli.commandsr   r   r	   Úuaclient.cli.formatterr
   r   Úuaclient.cli.parserr   Úuaclient.configr   Úwith_spinnerÚCLI_CVES_SPINNER_MSGr   r*   r>   rH   rP   ÚCLI_CVESÚCLI_CVES_DESCÚSECURITYÚCLI_CVES_UNFIXABLEÚCLI_CVES_FIXABLEÚcves_commandr   r   r   r   Ú<module>   sH     ýýúÿÿ
ù