o
    Jh                     @   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     
