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: //lib/google-cloud-sdk/lib/surface/artifacts/attachments/__pycache__/create.cpython-312.pyc
�

��"��~�dZddlmZddlmZddlmZddlZddlZddlmZddl	m
Zddlm
Z
dd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZej:ej<ej>j@�Gd�dejB���Z"y)zIImplements the command to create nand upload attachments to a repository.�)�absolute_import)�division)�unicode_literalsN)�transfer)�
exceptions)�waiter)�arg_parsers)�base)�docker_util)�flags)�requests)�util)�log)�
properties)�	resources)�files)�scaled_integerc�F�eZdZdZdZddd�Zed��Zd�Zd�Z	d	�Z
d
�Zy)�Createz8Creates an Artifact Registry attachment in a repository.�v1z
{description}aH    To create an attachment for target `projects/myproject/locations/us-central1/packages/mypackage/versions/sha256:123` using a file located in `/path/to/file/sbom.json`:

        $ {command} --target=projects/myproject/locations/us-central1/packages/mypackage/versions/sha256:123
          --files=/path/to/file/sbom.json
    )�DESCRIPTION�EXAMPLESc��tj�j|�|jdddd��|jdddd��|jd	d
dd��|jd
ddt	j
�d��y)z[Set up arguments for this command.

    Args:
      parser: An argparse.ArgumentPaser.
    z--target�TARGETTz@Target of the attachment, should be fully qualified version name)�metavar�required�helpz--attachment-type�ATTACHMENT_TYPEzType of the attachmentz--attachment-namespace�ATTACHMENT_NAMESPACEFzNamespace of the attachmentz--files�FILESz>Comma-seperated list of files that are part of this attachment)rr�typerN)r�GetRequiredAttachmentFlag�AddToParser�add_argumentr	�ArgList)�parsers �+lib/surface/artifacts/attachments/create.py�ArgszCreate.Args9s���
�#�#�%�1�1�&�9�
������
O�	������!��
%�	����� �&��
*�	��������
�
 �
 �
"�
M���c���tj�}|j}|jjj�}t
j|j�}|jjj|jk7rAtjdj|j!�|j#����t
j$|jjj&�}||j(k7rAtjdj|j!�|j#����|jjj*|j,k7rAtjdj|j!�|j#����g}|j.D]5}|j1||||j3��}	|j5|	��7|j7|j9|j#�|j:|j<|��|j3�j!�|j>��}
|j@jC|
�}tDjFjI|jJd��}tMjNtMjP|jR�|d�}
|
S)	aGRun the attachment create command.

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

    Returns:
      Result of CreateAttachment operation.

    Raises:
      InvalidInputValueError: when target and attachment
      project/location/repository match.
    z7Attachment {} must be in the same project as target {}.z8Attachment {} must be in the same location as target {}.z:Attachment {} must be in the same repository as target {}.)�targetr!�attachmentNamespacer)�
attachment�parent�attachmentId�.artifactregistry.projects.locations.operations��
collectionzCreating Attachment)*r
�	GetClient�MESSAGES_MODULE�CONCEPTSr-�Parser�ParseDockerVersionStrr+�image�docker_repo�project�
projectsId�
ar_exceptions�InvalidInputValueError�format�RelativeName�GetVersionName�RemoveEndpointPrefix�location�locationsId�repo�repositoriesIdr�upload_file�Parent�append�EArtifactregistryProjectsLocationsRepositoriesAttachmentsCreateRequest�
Attachment�attachment_type�attachment_namespace�
attachmentsId�+projects_locations_repositories_attachmentsrr�REGISTRY�ParseRelativeName�namer�WaitFor�CloudOperationPollerNoResources�projects_locations_operations)�self�args�client�messages�attachment_ref�docker_version�loc�
file_names�file�	file_name�create_request�op_obj�op_ref�results              r'�Runz
Create.Run^s����
�
�
!�F��%�%�H��]�]�-�-�3�3�5�N� �6�6�t�{�{�C�N����'�'�/�/�>�3L�3L�L��0�0�
C�
J�
J��)�)�+�^�-J�-J�-L��
��
�
*�
*����(�(�1�1��C��n�(�(�(��0�0�
D�
K�
K��)�)�+�^�-J�-J�-L��
��
���'�'�,�,��0M�0M�M��0�0�
F�
M�
M��)�)�+�^�-J�-J�-L��
���J��
�
���"�"�
���.�"7�"7�"9��i����	�"�	��c�c��&�&�!�0�0�2��%�%� $� 9� 9��	'�
��$�$�&�3�3�5�#�1�1�d�	�N��
?�
?�
F�
F���F��
�
�
1�
1���� P�2��F�
�^�^��.�.��0�0�	
�	���F��Mr)c�|�tjtjjj
j
��}|j|j�|j���}tj|�}d}	tjj|||��}	|jj||	��}
|
j }t"j$j'|j(d��}t+j,t+j.|j|j0�|dj3|��}
t"j$j'|
j(d��}|j�}|r1|j?|t@jBjE|�||�|S#t*j4$rg}dt7|�vrPt9j:d	|�d
�j3|��|j=|�}|j�}|�d|��}Yd}~��d}~wwxYw)N)�uploadFileRequestr.)�	mime_type�	chunksize)�uploadr0r1zUploading file: {}z6artifactregistry.projects.locations.repositories.fileszalready existszFile z already existsz/files/)#r�ParseIntegerr�VALUES�storage�upload_chunk_size�Get�?ArtifactregistryProjectsLocationsRepositoriesFilesUploadRequest�UploadFileRequestr?r�GetMimetyper�Upload�FromFile�%projects_locations_repositories_files�	operationrrOrPrQrrR�CloudOperationPollerrTr>�OperationError�strr�info�computeSha256OfFile�update_file_name_annotation�os�path�basename)rU�	file_pathrWrX�repo_refrg�requestrf�result_file_namerhr`�oprarb�result_file_ref�e�digest�repo_relative_names                  r'rFzCreate.upload_file�s���+�+����!�!�3�3�7�7�9��I��V�V�"�4�4�6��$�$�&�W��G�
� � ��+�I���B����'�'�
�y�I�(��f��;�;�B�B�
�&�C��f����b��!�!�3�3�
�'�'�N�4��f�
�~�~�
�
%�
%��:�:��2�2���
�
%�
%�i�
0�
�f�"�*�*�<�<�
�+�+�M�=��o�)�5�5�7���
�&�&�
�B�G�G�,�,�Y�7�������� � �B�	�S��V�	#����5���?�3�:�:�9�E�F��)�)�)�4��%�2�2�4��0�1����A����B�s�
C?G�H;�AH6�6H;c��|j||j|jj|jjjd|��g����d��}|jj|�y)Nz)artifactregistry.googleapis.com/file_name)�key�value)�additionalProperties)�annotationsr�)rQ�$googleDevtoolsArtifactregistryV1File�
updateMask)�>ArtifactregistryProjectsLocationsRepositoriesFilesPatchRequest�$GoogleDevtoolsArtifactregistryV1File�AnnotationsValue�AdditionalPropertyrs�Patch)rU�file_resource_namer^rWrX�update_requests      r'rzz"Create.update_file_name_annotation�s����\�\�
�-5�-Z�-Z� �E�E�V�V��A�A�R�R�e�e�G�'�f��&�W��.[�	.
�!�]�
�N��0�0�6�6�~�Fr)c��tj�}tj|�}|j	|�d|j�zS)Nzsha256:)�hashlib�sha256r�ReadBinaryFileContents�update�	hexdigest)rUr~r��datas    r'ryzCreate.computeSha256OfFile�s>��
�^�^�
�F��'�'�	�2�D�
�M�M�$���v�'�'�)�)�)r)N)�__name__�
__module__�__qualname__�__doc__�api_version�
detailed_help�staticmethodr(rcrFrzry�r)r'rr(sK��A��+�%���-��"��"�HI�V2�hG�&*r)r)#r��
__future__rrrr�r{�apitools.base.pyr� googlecloudsdk.api_lib.artifactsrr<�googlecloudsdk.api_lib.utilr�googlecloudsdk.callioper	r
�$googlecloudsdk.command_lib.artifactsrrr
r�googlecloudsdk.corerrr�googlecloudsdk.core.utilrr�DefaultUniverseOnly�
ReleaseTracks�ReleaseTrack�GA�Commandrr�r)r'�<module>r�s���P�&��'��	�%�H�.�/�(�<�6�9�5�#�*�)�*�3��������D�%�%�(�(�)�J*�T�\�\�J*�*��J*r)