
    *                        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 ddlmZ dZej2                   ej4                  ej6                  j8                         G d dej:                                      Zej2                   ej4                  ej6                  j>                         G d de                    Z y)zAccess a secret version's data.    )absolute_import)division)unicode_literals)api)
exceptions)base)parser_arguments)parser_extensions)args)fmt)util)crc32ca  An incorrect data_crc32c was calculated for the provided payload. This might be a transient issue that resolves with a retry. If this is happening repeatedly open an issue with Secret Manager at https://issuetracker.google.com/issues/new?component=784854&template=1380926.c                   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)	AccessS  Access a secret version's data.

  Access the data for the specified secret version.

  ## EXAMPLES

  Access the data for version 123 of the secret 'my-secret':

    $ {command} 123 --secret=my-secret

  Note: The output will be formatted as UTF-8 which can corrupt binary secrets.

  To write raw bytes to a file use --out-file flag:

    $ {command} 123 --secret=my-secret --out-file=/tmp/secret

  To get the raw bytes, have Google Cloud CLI print the response as
  base64-encoded and decode:

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

    Args:
      parser: An argparse parser that you can use to add arguments that will be
        available to this command.
    	to accessTpurpose
positionalrequiredto access secretFr   hiddenNsecrets_argsAddVersionOrAliasAddLocation
AddOutFilesecrets_fmtUseSecretDatar   s    &lib/surface/secrets/versions/access.pyArgszAccess.ArgsH   sL     ""t V-?NF#f%    r   returnc                    t        j                  | j                               }|j                  j                  j                         }t        j                  |      j                  ||j                        }|j                  j                  >t        j                  |j                  j                  |j                  j                        ry|j                  d      rf|j                  st!        j"                  | j$                        d|_        t)        j*                  |j                  |j                  j                         |S t-        j.                  t0              )a  Run is called by calliope to implement the secret versions access command.

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

    Returns:
      API call to invoke secret version access.
    api_versionsecret_locationout_filedisablesecrets_apiGetApiFromTrackReleaseTrackCONCEPTSversionParseVersionsr   locationpayload
dataCrc32cr   does_data_match_checksumdataIsSpecifiedr-   calliope_exceptionsBadFileExceptionEMPTY_OUT_FILE_MESSAGEformatsecrets_utilWriteBinaryFiler   HttpException%CHECKSUM_VERIFICATION_FAILURE_MESSAGEselfr   r*   version_refr4   s        r$   Runz
Access.RunW   s    --d.?.?.ABK--''--/K""{;BBT]] C G !!)V-L-Lgoo88. 
		*	%}}#44))+ +  $$T]]GOO4H4HIn

"
"#H
IIr&   N)__name__
__module____qualname____doc__r?   staticmethodr	   ArgumentInterceptorr%   r
   	Namespacer0   r6   rH    r&   r$   r   r   )   sV    ,5  &#77 & &J'11 Jk6J6J Jr&   r   c                   &    e Zd ZdZed        Zd Zy)
AccessBetar   c                     t        j                  | ddd       t        j                  | dd       t        j                  |        t	        j
                  |        y )Nr   Tr   r   Fr   r   r#   s    r$   r%   zAccessBeta.Args   sJ    ""t V-?NF#f%r&   c                    t        j                  | j                               }|j                  j                  j                         }t        j                  |      j                  ||j                        }|j                  j                  >t        j                  |j                  j                  |j                  j                        ry|j                  d      rf|j                  st!        j"                  | j$                        d|_        t)        j*                  |j                  |j                  j                         |S t-        j.                  t0              )Nr)   r+   r-   r.   r/   rE   s        r$   rH   zAccessBeta.Run   s   --d.?.?.ABK--''--/K""{;BBT]] C G !!)V-L-Lgoo88. 
		*	%}}#44))+ +  $$T]]GOO4H4HIn

"
"#H
IIr&   N)rI   rJ   rK   rL   rM   r%   rH   rP   r&   r$   rR   rR   u   s!    . & &Jr&   rR   N)!rL   
__future__r   r   r   googlecloudsdk.api_lib.secretsr   r0   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r=   r	   r
   "googlecloudsdk.command_lib.secretsr   r   r   r!   r   rA   googlecloudsdk.command_lib.utilr   rD   DefaultUniverseOnlyReleaseTracksr2   GADescribeCommandr   BETArR   rP   r&   r$   <module>r`      s    & &  ' = 2 ( E 4 5 C A C 2T & D%%(()GJT!! GJ * GJT D%%**+4J 4J , 4Jr&   