
    7                        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 ddlmZ ddlmZ e	j,                   e	j.                  e	j0                  j2                         G d de	j4                                      Ze	j,                   e	j.                  e	j0                  j8                         G d de                    Zy)z*Enable the version of the provided secret.    )absolute_import)division)unicode_literals)api)base)
exceptions)parser_arguments)parser_extensions)args)log)util)crc32cc                   v    e Zd ZdZdZedej                  fd       Zde	j                  dej                  fdZy)	Create  Create a new version of an existing secret.

  Create a new version of an existing secret with the provided data. The
  command will return an error if no such secret exists.

  ## EXAMPLES

  Create a new version of an existing secret named 'my-secret' with secret data
  "s3cr3t":

    $ printf "s3cr3t" | {command} my-secret --data-file=-

  Create a new version of an existing secret named 'my-secret' with secret data
  "s3cr3t" using PowerShell (Note: PowerShell will add a newline to the
  resulting secret):

    $ Write-Output "s3cr3t" | {command} my-secret --data-file=-

  Create a new version of an existing secret named 'my-secret' with secret data
  from a file:

    $ {command} my-secret --data-file=/tmp/secret
  zThe value provided for --data-file is the empty string. This can happen if you pass or pipe a variable that is undefined. Please verify that the --data-file flag is not the empty string.parserc                     t        j                  | ddd       t        j                  | dd       t        j                  | d       y)	zArgs is called by calliope to gather arguments for secrets versions add command.

    Args:
      parser: An argparse parser that you can use to add arguments that will be
        available to this command.
    	to createTpurpose
positionalrequiredto create secret versionFr   hiddenr   Nsecrets_args	AddSecretAddLocationAddDataFiler   s    #lib/surface/secrets/versions/add.pyArgszCreate.Args@   sE     t 25 Vd3    r   returnc                 
   t        j                  | j                               }|j                  j                  j                         }|j                  du}t        j                  |j                        }|j                  dk(  rt        j                  | j                        t        j                  |      }t        j                  |      j!                  ||t        j"                  |      |j                        }|r t%        j&                  |j(                        }nt%        j*                  |j(                        }t-        j.                         j1                  |       |j2                  st        j4                  d      |S )zRun is called by calliope to implement the secret versions add command.

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

    Returns:
      API call to invoke secret version add.
    N api_versionsecret_locationVersion created but payload data corruption may have occurred, please destroy the created version, and retry. See also https://cloud.google.com/secret-manager/docs/data-integrity.secrets_apiGetApiFromTrackReleaseTrackCONCEPTSsecretParselocationsecrets_utilReadFileOrStdin	data_filer   BadFileExceptionEMPTY_DATA_FILE_MESSAGEr   
get_crc32cSecrets
AddVersionget_checksumr   ParseRegionalVersionRefnameParseVersionRefsecrets_logVersionsCreatedclientSpecifiedPayloadChecksumHttpException	selfr   r*   
secret_refis_regionaldatadata_crc32cversionversion_refs	            r#   Runz
Create.RunP   s5    --d.?.?.ABK%%++-J--t+K''7D ~~''(D(DEE##D)K!!k:EEK(	 F G  88Fk 00>k"";/11$$I 
 Nr%   N)__name__
__module____qualname____doc__r:   staticmethodr	   ArgumentInterceptorr$   r
   	Namespacer/   rC   rO    r%   r#   r   r       sS    26 
 4#77 4 4&'11 &k6J6J &r%   r   c                   &    e Zd ZdZed        Zd Zy)
CreateBetar   c                     t        j                  | ddd       t        j                  | dd       t        j                  | d       y )Nr   Tr   r   Fr   r   r   r"   s    r#   r$   zCreateBeta.Args   sC    t 25 Vd3r%   c                 
   t        j                  | j                               }|j                  j                  j                         }|j                  d u}t        j                  |j                        }|j                  dk(  rt        j                  | j                        t        j                  |      }t        j                  |      j!                  ||t        j"                  |      |j                        }|r t%        j&                  |j(                        }nt%        j*                  |j(                        }t-        j.                         j1                  |       |j2                  st        j4                  d      |S )Nr(   r)   r+   r-   r.   rG   s	            r#   rO   zCreateBeta.Run   s5   --d.?.?.ABK%%++-J--t+K''7D ~~''(D(DEE##D)K!!k:EEK(	 F G  88Fk 00>k"";/11$$IJ J Nr%   N)rP   rQ   rR   rS   rT   r$   rO   rW   r%   r#   rY   rY   y   s     0 4 4r%   rY   N)rS   
__future__r   r   r   googlecloudsdk.api_lib.secretsr   r/   googlecloudsdk.callioper   r   r	   r
   "googlecloudsdk.command_lib.secretsr   r   r   rB   r   r6   googlecloudsdk.command_lib.utilr   DefaultUniverseOnlyReleaseTracksr1   GACreateCommandr   BETArY   rW   r%   r#   <module>rf      s    1 &  ' = ( . 4 5 C A C 2 D%%(()TT T * Tn D%%**+? ? , ?r%   