
                             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iZ ej"                  ej$                  j&                         G d dej(                               Zy)z+Export a pem-encoded certificate to a file.    )absolute_import)division)unicode_literals)base)	pem_utils)resource_args)log)filesEXAMPLESa          To export a single pem-encoded certificate to a file, run the following:

          $ {command} my-cert --issuer=my-ca --issuer-location=us-west1 --output-file=cert.pem

        To export a pem-encoded certificate along with its issuing chain in the
        same file, run the following:

          $ {command} my-cert --issuer=my-ca --issuer-location=us-west1 --include-chain --output-file=chain.pem

        You can omit the --issuer-location flag in both of the above examples if
        you've already set the privateca/location property. For example:

          $ {top_command} config set privateca/location us-west1

          # The following is equivalent to the first example above.
          $ {command} my-cert --issuer=my-ca --output-file=cert.pem

          # The following is equivalent to the second example above.
          $ {command} my-cert --issuer=my-ca --include-chain --output-file=chain.pem
        c                   &    e Zd ZdZed        Zd Zy)Exporta  Export a pem-encoded certificate to a file.

  ## EXAMPLES

  To export a single pem-encoded certificate to a file, run the following:

    $ {command} my-cert --issuer-pool=my-pool --issuer-location=us-west1 \
      --output-file=cert.pem

  To export a pem-encoded certificate along with its issuing chain in the
  same file, run the following:

  $ {command} my-cert --issuer-pool=my-pool --issuer-location=us-west1 \
    --include-chain \
    --output-file=chain.pem

  You can omit the --issuer-location flag in both of the above examples if
  you've already set the privateca/location property. For example:

  $ {top_command} config set privateca/location us-west1

  # The following is equivalent to the first example above.
  $ {command} my-cert --issuer-pool=my-pool --output-file=cert.pem

  # The following is equivalent to the second example above.
  $ {command} my-cert --issuer-pool=my-pool --include-chain \
    --output-file=chain.pem
  c                     t        j                  | d       t        j                  ddd      j	                  |        t        j                  dddd	d	
      j	                  |        y )Nz	to exportz--output-filezEThe path where the resulting PEM-encoded certificate will be written.T)helprequiredz--include-chainzWhether to include the certificate's issuer chain in the exported file. If this is set, the resulting file will contain the pem-encoded certificate and its issuing chain, ordered from leaf to root.
store_trueF)r   actiondefaultr   )r   AddCertPositionalResourceArgr   ArgumentAddToParser)parsers    ,lib/surface/privateca/certificates/export.pyArgszExport.ArgsV   s`    ..v{CMM	 #{6*MM  $F+    c                 Z   t        j                  d      }t        j                  d      }|j                  j                  j                         }|j                  j                  |j                  |j                                     }|j                  g}|j                  r||j                  z  }t        j                  |j                  t!        j"                  |             t$        j&                  j)                  dj+                  |j                         |j                               y )Nv1)api_version)namez"Exported certificate [{}] to [{}].)privateca_baseGetClientInstanceGetMessagesModuleCONCEPTScertificateParse'projects_locations_caPools_certificatesGet7PrivatecaProjectsLocationsCaPoolsCertificatesGetRequestRelativeNamepemCertificateinclude_chainpemCertificateChainr
   WriteFileContentsoutput_filer   PemChainForOutputr	   statuswriteformat)selfargsclientmessagescertificate_refr#   	pem_chains          r   Runz
Export.Runh   s    --$?F//DAHmm//557O@@DD	@	@ --/ 
A 
12K
 ++,I;222i	D,,%77	BDJJ9@@$$&(8(8: ;r   N)__name__
__module____qualname____doc__staticmethodr   r8    r   r   r   r   7   s     : , ,";r   r   N)r<   
__future__r   r   r    googlecloudsdk.api_lib.privatecar   r   googlecloudsdk.calliope$googlecloudsdk.command_lib.privatecar   r   googlecloudsdk.corer	   googlecloudsdk.core.utilr
   _DETAILED_HELPReleaseTracksReleaseTrackGASilentCommandr   r>   r   r   <module>rJ      ss    2 &  ' C ( : > # * 	4 D%%(()A;T A; *A;r   