
                             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 dd
lmZ  G d dej(                        Zy)zCommand for listing images.    )absolute_import)division)unicode_literals)base_classes)lister)util)base)flags)
propertiesc                   ,    e Zd ZdZed        Zd Zd Zy)Lista  List Google occurrences of PACKAGE_VULNERABILITY.

  Lists occurrences with the "kind" field set to "PACKAGE_VULNERABILITY".

  The default value of the `--filter` flag for this command is:

      vulnerabilityDetails.packageIssue.fixedLocation.version.kind != "MAXIMUM"

  so that only vulnerabilities with a known fix are shown. Passing `--filter`
  will override this so *all* PACKAGE_VULNERABILITY occurrences are shown, with
  any additional provided filters applied.
  c                    t        j                  |        | j                  j                  d       t	        j
                  dd      t        _        t        j                  j                  | d       | j                  j                  d       y )Na          table(
          name,
          noteName.basename():label=NOTE,
          vulnerabilityDetails.severity,
          vulnerabilityDetails.cvssScore,
          vulnerabilityDetails.packageIssue.affectedLocation.package.join(','):label=PACKAGES
        )Fz--image)requirednamecreate)operation_typezIvulnerabilityDetails.packageIssue.fixedLocation.version.kind != "MAXIMUM")
r   AddBaseListerArgsdisplay_info	AddFormatimage_flagsMakeDiskImageArgr   
_image_argAddArgument	AddFilter)parsers    2lib/surface/compute/images/vulnerabilities/list.pyArgsz	List.Args,   st    
V$
!! #  "22Y(DOOOx@ !!	    c                 .   ddg}|j                   ru| j                  j                  ||j                  t	        j
                  |j                              }|j                         }|j                  dj                  |             dj                  |      S )Nzkind = "PACKAGE_VULNERABILITY"zBhas_prefix(resource_url,"https://compute.googleapis.com/compute/"))scope_listerzhas_prefix(resource_url, "{}")z AND )imager   ResolveAsResource	resourcescompute_flagsGetDefaultScopeListerclientSelfLinkappendformatjoin)selfargsholderfilters	image_ref	image_urls         r   
_GetFilterzList._GetFilterA   s    (LG
 zz//33



$::mm 4 i
 $$&inn5<<YGH<<  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coreprojectGetr   ComputeApiHolderr	   ReleaseTrackGAr1   containeranalysis_utilMakeOccurrenceRequest)r+   r,   r9   r-   r4   s        r   RunzList.RunR   sk    $$,,002G**4+<+<+?+?@FoodF3O!77Od4 4r   N)__name__
__module____qualname____doc__staticmethodr   r1   r@    r   r   r   r      s%      (!"4r   r   N)rD   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   (googlecloudsdk.api_lib.containeranalysisr   r>   googlecloudsdk.callioper	   "googlecloudsdk.command_lib.computer
   r$   )googlecloudsdk.command_lib.compute.imagesr   googlecloudsdk.corer   ListCommandr   rF   r   r   <module>rO      s:    " &  ' 7 1 S ( E J *<44 <4r   