
                         2   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SS	K	Jr  SS
K	Jr  SSK	Jr  SSKJr  SSKJr  \R"                  \R$                  " \R&                  R(                  5       " S S\R*                  5      5       5       rg)z.Implements the command to upload an SBOM file.    )absolute_import)division)unicode_literals)arg_parsers)base)
exceptions)endpoint_util)flags)	sbom_util)util)log)
propertiesc                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g	)
Load    z6Upload an SBOM file and create a reference occurrence.z{description}a            To upload an SBOM file at /path/to/sbom.json for a Docker image in Artifact Registry:

          $ {command} --source=/path/to/sbom.json               --uri=us-west1-docker.pkg.dev/my-project/my-repository/busy-box@sha256:abcxyz

          To upload an SBOM file at /path/to/sbom.json for a Docker image with a KMS key version to sign the created SBOM reference:

          $ {command} --source=/path/to/sbom.json               --uri=us-west1-docker.pkg.dev/my-project/my-repository/busy-box@sha256:abcxyz               --kms-key-version=projects/my-project/locations/us-west1/keyRings/my-key-ring/cryptoKeys/my-key/cryptoKeyVersions/1

          To upload an SBOM file at /path/to/sbom.json for a Docker image from a Docker registry:

          $ {command} --source=/path/to/sbom.json               --uri=my-docker-registry/my-image@sha256:abcxyz               --destination=gs://my-cloud-storage-bucket
          )DESCRIPTIONEXAMPLESc                 8   U R                  SSSSSS9  U R                  SSSS	S
9  U R                  SSSS[        R                  " SS5      S9  U R                  SSSSS[        R                  " SS5      S9  [        R                  " 5       R                  U 5        g)zOSet up arguments for this command.

Args:
  parser: An argparse.ArgumentPaser.
z--sourceSOURCET.zThe SBOM file for uploading.)metavarrequireddefaulthelpz--uriARTIFACT_URIa              The URI of the artifact the SBOM is generated from.
            The URI can be a Docker image from any Docker registries. A URI provided with a tag (e.g. `[IMAGE]:[TAG]`) will be resolved into a URI with a digest (`[IMAGE]@sha256:[DIGEST]`).
            When passing an image which is not from Artifact Registry or Container Registry with a tag, only public images can be resolved.
            Also, when passing an image which is not from Artifact Registry or Container Registry, the `--destination` flag is required.
            )r   r   r   z--kms-key-versionNa#              Cloud KMS key version to sign the SBOM reference.
            The key version provided should be the resource ID in the format of
            `projects/[KEY_PROJECT_ID]/locations/[LOCATION]/keyRings/[RING_NAME]/cryptoKeys/[KEY_NAME]/cryptoKeyVersions/[KEY_VERSION]`.
            FzX^projects/[^/]+/locations/[^/]+/keyRings/[^/]+/cryptoKeys/[^/]+/cryptoKeyVersions/[^/]+$zMust be in format of 'projects/[KEY_PROJECT_ID]/locations/[LOCATION]/keyRings/[RING_NAME]/cryptoKeys/[KEY_NAME]/cryptoKeyVersions/[KEY_VERSION]')r   r   r   typez--destinationDESTINATIONz            The storage path will be used to store the SBOM file.
            Currently only supports Cloud Storage paths start with 'gs://'.
        z	^gs://.*$z(Must be in format of gs://[STORAGE_PATH])r   r   r   r   r   )add_argumentr   RegexpValidatorr
   GetOptionalAALocationFlagAddToParser)parsers    "lib/surface/artifacts/sbom/load.pyArgs	Load.Args;   s     +   	  
 
 ((gO
  $  ((D
   
##%11&9    c                    [         R                  " UR                  5      n[        R                  " SR                  UR                  UR                  5      5        UR                  (       d  [        R                  " SS5      e[         R                  " UR                  5      n[        R                  " SR                  UR                  UR                  UR                  UR                  R!                  SS5      5      5        [         R"                  UR$                  :X  a(  UR&                  (       d  [        R                  " SS5      e[         R(                  " UR                  UUUR&                  S	9n[        R                  " S
R                  U5      5        UR                  nU(       du  UR                  =(       d2    [*        R,                  R.                  R                  R1                  5       n[        R                  " SR                  UR                  U5      5        [2        R4                  " XQR                  5      n[6        R8                  " UR                  5         [         R:                  " UUUUUR<                  S9nSSS5        [        R                  " SR                  W5      5        [        R>                  RA                  SR                  URC                  5       5      5        g! , (       d  f       Np= f)zRun the load command.z3Successfully loaded the SBOM file. Format: {0}-{1}.r   z--uri is required.zFProcessed artifact. Project: {0}, Location: {1}, URI: {2}, Digest {3}.sha256 r   zT--destination is required for images not in Artifact Registry or Container Registry.)sourceartifactsbomgcs_pathzUploaded the SBOM file at {0}zUFailed to get project_id from the artifact URI {0}. Using project {1} for occurrence.)r+   
project_idstorager,   kms_key_versionNzWrote reference occurrence {0}.z1Uploaded the SBOM file under the resource URI {}.)"r   ParseJsonSbomr*   r   infoformatsbom_formatversionurir   InvalidArgumentExceptionProcessArtifactprojectlocationresource_uridigestsgetARTIFACT_TYPE_OTHERartifact_typedestinationUploadSbomToGCSr   VALUEScore	GetOrFailr   	GetParentr	   
WithRegionWriteReferenceOccurrencer0   statusPrintGetOccurrenceResourceUri)selfargssaremote_pathr.   parentoccurrence_ids           r#   RunLoad.Runv   s(    	,AHH=DDMM199	
 88//

 
 	!!$((+AHHC
&IIqzz1>>199==23N
	 	%%8  //
%  ++{{!!	K HH,33K@A
 J<<M:#4#4#9#9#A#A#K#K#Mj	hh-F488Z(	 ^^J6F		!	!$--	088..m 
1 HH.55mDEJJ;BB&&(	
 
1	0s   !#K..
K< N)
__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr$   rR   __static_attributes__rT   r&   r#   r   r       s3     ? %-, 8: 8:tIr&   r   N)rY   
__future__r   r   r   googlecloudsdk.callioper   r   r   $googlecloudsdk.command_lib.artifactsr	   r
   r   r   googlecloudsdk.corer   r   DefaultUniverseOnlyReleaseTracksReleaseTrackGACommandr   rT   r&   r#   <module>rf      su    5 &  ' / ( . > 6 : 5 # * D%%(()]4<< ] * ]r&   