
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl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ej&                        Zy)z-Command for listing instance vulnerabilities.    )absolute_import)division)unicode_literals)base_classes)util)base)
completers)flags)
propertiesc            	       r    e Zd ZdZ ej
                  ddej                  dddd      Ze	d	        Z
d
 Zd Zy)Listz{List vulnerability occurrences for instances.

  Lists occurrences with the "kind" field set to "PACKAGE_VULNERABILITY".
  instancez
--instanceFzcompute.instancesz5The name of the instance to show vulnerabilities for.z5If not specified, it will be set to the same as zone.)resource_namename	completerrequiredzonal_collection
short_helpzone_explanationc                 x    t         j                  j                  |        | j                  j	                  d       y )Na^          table(
          name.basename(),
          resource_url.basename():label=INSTANCE,
          resource_url.scope().split('/').slice(0).join(''):label=ZONE,
          noteName.basename():label=NOTE,
          vulnerabilityDetails.severity,
          vulnerabilityDetails.packageIssue.affectedLocation.package.join(','):label=PACKAGES
        ))r   _INSTANCE_ARGAddArgumentdisplay_info	AddFormat)parsers    5lib/surface/compute/instances/vulnerabilities/list.pyArgsz	List.Args,   s/    ""6*
!! #     c                 t   dg}dj                  |      }|j                  rht        j                  j	                  ||j
                  t        j                  |j                              }dj                  |j                               }|j                  dj                  |             dj                  |      S )Nzkind = "PACKAGE_VULNERABILITY"z5https://www.googleapis.com/compute/projects/{}/zones/)scope_listerz%https://www.googleapis.com/compute/{}zhas_prefix(resource_url, "{}")z AND )formatr   r   r   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerclientRelativeNameappendjoin)selfprojectargsholderfiltersprefixinsts          r   
_GetFilterzList._GetFilter:   s    (G EKKF}}11



$::6==I 2 d
 7==



f NN3::6BC<<  r   c                    t         j                  j                  j                  j	                         }t        j                  t        j                  j                        }| j                  |||      }t        j                  ||dd      S )z Yields filtered vulnerabilities.N)
project_idresource_filteroccurrence_filterresource_urls)r   VALUEScorer+   Getr   ComputeApiHolderr   ReleaseTrackALPHAr1   containeranalysis_utilMakeOccurrenceRequest)r*   r,   r+   r-   r4   s        r   RunzList.RunN   so    $$,,002G**4+<+<+B+BCFoogtV<O!77'	 r   N)__name__
__module____qualname____doc__r$   ResourceArgumentcompute_completersInstancesCompleterr   staticmethodr   r1   r?    r   r   r   r      sU    
 1-00"55*HNP-  !(
r   r   N)rC   
__future__r   r   r   googlecloudsdk.api_lib.computer   (googlecloudsdk.api_lib.containeranalysisr   r=   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   rE   r
   r$   googlecloudsdk.corer   ListCommandr   rH   r   r   <module>rP      s7    4 &  ' 7 S ( O E *;4 ;r   