HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: //usr/lib/google-cloud-sdk/lib/surface/artifacts/sbom/__pycache__/load.cpython-312.pyc
�

�����2�dZddlmZddlmZddlmZddlmZddlmZddlmZddl	m
Z
dd	l	mZdd
l	mZddl	m
Z
ddlmZdd
lmZej"ej$ej&j(�Gd�dej*���Zy)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�0�eZdZdZddd�Zed��Zd�Zy)�Loadz6Upload 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�J�|jddddd��|jdddd	�
�|jddd
dtjdd���|jdddddtjdd���tj�j|�y)z[Set up arguments for this command.

    Args:
      parser: An argparse.ArgumentPaser.
    z--source�SOURCET�.zThe 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.
            )rrrz--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/[^/]+$z�Must be in format of 'projects/[KEY_PROJECT_ID]/locations/[LOCATION]/keyRings/[RING_NAME]/cryptoKeys/[KEY_NAME]/cryptoKeyVersions/[KEY_VERSION]')rrr�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])rrrrr)�add_argumentr�RegexpValidatorr
�GetOptionalAALocationFlag�AddToParser)�parsers �"lib/surface/artifacts/sbom/load.py�Argsz	Load.Args;s����������
+����������	�
�������
�
�
(�
(�g�O�
���$���������
(�
(��D�
���
�#�#�%�1�1�&�9�c��tj|j�}tjdj|j|j��|jstjdd��tj|j�}tjdj|j|j|j|jj!dd���tj"|j$k(r"|j&stjdd��tj(|j|||j&�	�}tjd
j|��|j}|so|jxs2t*j,j.jj1�}tjdj|j|��t3j4||j�}t7j8|j�5tj:|||||j<��}d
d
d
�tjdj��tj>jAdj|jC���y
#1swY�jxYw)zRun the load command.z3Successfully loaded the SBOM file. Format: {0}-{1}.rz--uri is required.zFProcessed artifact. Project: {0}, Location: {1}, URI: {2}, Digest {3}.�sha256�rzT--destination is required for images not in Artifact Registry or Container Registry.)�source�artifact�sbom�gcs_pathzUploaded 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_versionNzWrote 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�WriteReferenceOccurrencer.�status�Print�GetOccurrenceResourceUri)�self�args�s�a�remote_pathr,�parent�
occurrence_ids        r"�RunzLoad.Runvs*��	������,�A��H�H�=�D�D�
�M�M�1�9�9�	
���8�8��/�/�
�
�
��
	�!�!�$�(�(�+�A��H�H�
C�
�&�
�I�I�q�z�z�1�>�>�1�9�9�=�=��2�3N�
�	�	�%�%����8�� � ��/�/�
�%�
���+�+��{�{��
��!�!�	�K��H�H�
,�
3�
3�K�
@�A�
���J���<�<�M�:�#4�#4�#9�#9�#A�#A�#K�#K�#M�j�	�h�h�-��F�4�8�8�Z�(�	��^�^�J��
�
�
6�F�	�	!�	!�$�-�-�	0��8�8������.�.��m�
1��H�H�
.�
5�
5�m�
D�E��J�J���;�B�B�
�&�&�(�	
��
1�	0�s�%K�KN)�__name__�
__module__�__qualname__�__doc__�
detailed_help�staticmethodr#rP�r$r"rr s3��?�%���-�,�8:��8:�tIr$rN)rT�
__future__rrr�googlecloudsdk.callioperrr�$googlecloudsdk.command_lib.artifactsr	r
rr�googlecloudsdk.corer
r�DefaultUniverseOnly�
ReleaseTracks�ReleaseTrack�GA�CommandrrWr$r"�<module>rasw��5�&��'�/�(�.�>�6�:�5�#�*��������D�%�%�(�(�)�]�4�<�<�]�*��]r$