
    "                        d Z ddlmZ ddlmZ ddlmZ ddl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ZdZd Zd Z ej4                  ej6                  j8                         G d dej:                               Z ej4                  ej6                  j>                  ej6                  j@                         G d de             Z!y)z>Command to show Container Analysis Data for a specified image.    )absolute_import)division)unicode_literalsN)docker_name)container_data_util)util)filter_util)base)requests)flags)log)BUILDVULNERABILITYIMAGE
DEPLOYMENT	DISCOVERYz_^(?P<project>([^\/]+\.[^\/]+\/)?([^\/\.]+))\/(?P<repo>(us\.|eu\.|asia\.)?gcr.io)\/(?P<image>.*)c                    d| j                   vr| S t        j                  t        | j                        }|s| S t        j                         }t        j                  |j                  d            }|j                  |j                  j                  j                  k(  rt        j                  d       | S t        j                  dj                  |j                  d      |j                  d                   t!        j"                  dj                  |j                  d      dj                  |j                  d      |j                  d            | j$                  	            S )
zConverts gcr.io repos on AR from pkg.dev->gcr.io.

  Args:
    image_name: Image to convert to GCR.

  Returns:
    The same image_name, but maybe in GCR format.
  zpkg.devprojectzgcr.io repositories in Artifact Registry are only scanned if redirected. Redirect this project before checking scanning resultsz{Container Analysis API uses the gcr.io hostname for scanning results of gcr.io repositories. Using https://{}/{} instead...repoz {registry}/{repository}@{sha256}z{}/{}image)registry
repositorysha256)r   rematchGCR_REPO_REGEXr   ar_requestsGetMessagesGetProjectSettingsgrouplegacyRedirectionStateProjectSettings%LegacyRedirectionStateValueValuesEnum REDIRECTION_FROM_GCR_IO_DISABLEDr   warningformatr   Digestdigest)
image_namematchesmessagessettingss       (lib/surface/container/images/describe.pyMaybeConvertToGCRr.   .   s4    j))) HH^Z%:%:;'	$$&(++GMM),DE(%%		!	!	G	G	h	hi KK	N ++==CV
--
y!9> 
		(//==(^^mmI&g(> "" 0 
     c                 4    t        j                  | dd       y )NdescribeF)verbrepeated)r   AddTagOrDigestPositionalparsers    r-   _CommonArgsr7   ]   s      j5Ir/   c                   &    e Zd ZdZed        Zd Zy)Describea  Lists information about the specified image.

  ## EXAMPLES

  Describe the specified image:

    $ {command} gcr.io/myproject/myimage@digest

          Or:

    $ {command} gcr.io/myproject/myimage:tag

  Find the digest for a tag:

    $ {command} gcr.io/myproject/myimage:tag \
      --format="value(image_summary.digest)"

          Or:

    $ {command} gcr.io/myproject/myimage:tag \
      --format="value(image_summary.fully_qualified_digest)"

  c                     t        |        y )N)r7   r5   s    r-   ArgszDescribe.Args|   s
    r/   c                 (   t        j                  |j                        5  t        t        j                  |j                              }t        j                  |j                  |j                  |j                        cddd       S # 1 sw Y   yxY w)N  This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Raises:
      InvalidImageNameError: If the user specified an invalid image name.
    Returns:
      Some value that we want to have printed later.
    r   r   r(   N)
r   WrapExpectedDockerlessErrorsr)   r.   GetDigestFromNamer   ContainerDatar   r   r(   )selfargsimg_names      r-   RunzDescribe.Run   sb     
	*	*4??	;"4#9#9$//#JKh ..$$((" 
<	;	;s   ABBN__name__
__module____qualname____doc__staticmethodr;   rE    r/   r-   r9   r9   b   s     0  "r/   r9   c                   &    e Zd ZdZed        Zd Zy)DescribeAlphaAndBetaa  Lists container analysis data for a given image.

  Lists container analysis data for a valid image.

  ## EXAMPLES

  Describe the specified image:

    $ {command} gcr.io/myproject/myimage@digest

          Or:

    $ {command} gcr.io/myproject/myimage:tag

  Find the digest for a tag:

    $ {command} gcr.io/myproject/myimage:tag \
      --format="value(image_summary.digest)"

          Or:

    $ {command} gcr.io/myproject/myimage:tag \
      --format="value(image_summary.fully_qualified_digest)"

  See package vulnerabilities found by the Container Analysis API for the
  specified image:

    $ {command} gcr.io/myproject/myimage@digest --show-package-vulnerability
  c                 
   t        |        | j                  ddd       | j                  ddd       | j                  d	dd
       | j                  ddd       | j                  ddd       | j                  ddd       y )Nz--metadata-filter zPAdditional filter to fetch metadata for a given fully qualified image reference.)defaulthelpz--show-build-details
store_truez%Include build metadata in the output.)actionrR   z--show-package-vulnerabilityz-Include vulnerability metadata in the output.z--show-image-basisz*Include base image metadata in the output.z--show-deploymentz*Include deployment metadata in the output.z--show-all-metadataz#Include all metadata in the output.)r7   add_argumentr5   s    r-   r;   zDescribeAlphaAndBeta.Args   s     9  ;
 4  6 &<  > 9  ; 9  ; 2  4r/   c                    g }|j                   r|j                  d       |j                  r"|j                  d       |j                  d       |j                  r|j                  d       |j                  r|j                  d       |j
                  rt        }|s|j                  rt        j                         }|j                  |       |j                  |j                         t        j                  |j                        5  t        t        j                   |j                              }|j#                  dj%                  |      g       t        j&                  ||      }|j(                  j*                  s|j                   s|j
                  s|`|j,                  j.                  s|j                  s|j
                  s|`|j0                  j2                  s|j                  s|j
                  s|`|j4                  j6                  s|j                  s|j
                  s|`|j8                  j:                  s|j                  s|j
                  s|`|cddd       S t        j                  |j                        5  t        t        j                   |j                              }t=        j>                  |j@                  |jB                  |jD                        cddd       S # 1 sw Y   yxY w# 1 sw Y   yxY w)	r=   r   r   r   r   r   z
https://{}Nr>   )#show_build_detailsappendshow_package_vulnerabilityshow_image_basisshow_deploymentshow_all_metadata_DEFAULT_KINDSmetadata_filterr	   ContainerAnalysisFilter	WithKindsWithCustomFilterr   r?   r)   r.   r@   WithResourcesr&   TransformContainerAnalysisDatabuild_details_summarybuild_detailspackage_vulnerability_summaryvulnerabilitiesdiscovery_summary	discoveryimage_basis_summarybase_imagesdeployment_summarydeploymentsr   rA   r   r   r(   )rB   rC   filter_kindsfrD   datas         r-   rE   zDescribeAlphaAndBeta.Run   sJ    L'"&&/*+&'",'#lt++

-
-
/akk,--.,,T__=$T%;%;DOO%LM 	
,,X678228Q?**88''0F0F(22BB//8N8N0&&00//8N8N$((44%%d.D.D&''33$$T-C-C%- >=0 ,,T__=$T%;%;DOO%LM"00&&**??$ >=1 >=0 >=s   EK*AK6*K36K?NrF   rL   r/   r-   rN   rN      s     < 4 4<=$r/   rN   )"rJ   
__future__r   r   r   r   containerregistry.clientr   'googlecloudsdk.api_lib.container.imagesr   r   (googlecloudsdk.api_lib.containeranalysisr	   googlecloudsdk.callioper
   $googlecloudsdk.command_lib.artifactsr   r   $googlecloudsdk.command_lib.containerr   googlecloudsdk.corer   r]   r   r.   r7   ReleaseTracksReleaseTrackGADescribeCommandr9   ALPHABETArN   rL   r/   r-   <module>r      s    E &  ' 	 0 G 8 @ ( H 6 # t,^J
 D%%(()/"t## /" */"d D%%++T->->-C-CD{$8 {$ E{$r/   