
    Jh                        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
efd       Zd Zd Zd
efdZd
efdZ edej6                  ej8                  eej:                  d e e
dej<                  d       e
dej>                  d      g      g      Z y)    N)
exceptionsmessages)CVEsOptions_cves)cli_util)ProArgumentProArgumentGroup
ProCommand)Tablecreate_link)HelpCategory)UAConfig)msgcfgc                    t        | j                  | j                        }	 t        ||      }|S # t        j
                  $ r d }Y |S w xY w)N)fixable	unfixable)optionsr   )r   r   r   r   r   VulnerabilityDataNotFound)argsr   kwargscve_optionsresults        3/usr/lib/python3/dist-packages/uaclient/cli/cves.py_get_cve_vulnerabilitiesr      sS    ..K
{4 M // Ms   2 A
Ac                 .   g }| j                   j                         D ]u  \  }}|j                  D ]a  }| j                  j                  |j                        }|s+|j                  ||j                  |j                  xs d|j                  f       c w |S )N-)packagesitemscvesgetnameappendpriority
fix_origin)cve_vulnerabilitiesrowspackage_namepackage_infocvecve_infos         r   _get_cve_table_rowsr,      s    D&9&B&B&H&H&J "l$$ 	C*//33CHH=H$ ))-#			 K    c                     g }t        | d       D ]S  }|j                  |d   t        j                  |d         |d   t	        |d   dj                  |d               f       U |S )	Nc                 4    | d   dj                  | d         fS )Nr   )criticalhighmediumlow
negligible   )index)rows    r   <lambda>z"_format_cve_rows.<locals>.<lambda>3   s"    F?EEc!fM
 r-   )keyr   r5         zhttps://ubuntu.com/security/{})texturl)sortedr#   r   colorize_priorityr   format)cve_rowsformatted_rowsr7   s      r   _format_cve_rowsrC   /   s    N
 
 	A**3q62AQ8??AG	
	

& r-   c                 V   t        | |      }|st        j                         |j                  rt	        t        |            }|rt        t        g d|             y | j                  rt        t        j                         y | j                  rt        t        j                         y t        t        j                         y | j                  rt        t        j                         y | j                  rt        t        j                         y t        t        j                         y )N)r   )PackagePriorityOriginVulnerability)headersr'   )r   r   r   r   rC   r,   printr   r   r   CLI_UNFIXABLE_CVES_NOT_AFFECTEDr   CLI_FIXABLE_CVES_NOT_AFFECTEDCLI_CVES_NOT_AFFECTED)r   r   r&   r'   s       r   
_list_cvesrN   G   s    24SA2244## 34G HIN ~~h>>?h<<=h445>>(::;\\(889(001r-   c                    | j                   r#| j                  rt        j                  dd      	 t	        | |       y # t
        $ r! t        j                  j                          Y y w xY w)Nr   r   )option1option2)r   r   )	r   r   r   InvalidOptionCombinationrN   BrokenPipeErrorsysstderrclose)r   r   r   s      r   action_cvesrW   g   sU    ~~$,,11
 	
#& 

s   ? 'A)(A)r    Tz--unfixable
store_true)helpactionz	--fixable)	arguments)rY   descriptionrZ   help_categorypreserve_descriptionargument_groups)!rT   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,   rC   rN   rW   CLI_CVESCLI_CVES_DESCSECURITYCLI_CVES_UNFIXABLECLI_CVES_FIXABLEcves_command r-   r   <module>rp      s    
 ) B ! K K 5 , $ 88898  :(02( 2@	h 	 
			&&''!!44'
 !22'	
r-   