
    P                     ^   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iZd Z ej&                  ej(                  j*                  ej(                  j,                  ej(                  j.                         G d dej0                               Zy)z7Get a PEM-format certificate chain for a given version.    )absolute_import)division)unicode_literals)base)
exceptions)flags)log)filesEXAMPLESa          The following command saves the Cavium certificate chain for
        CryptoKey ``frodo'' Version 2 to ``/tmp/my/cavium.pem'':

          $ {command} 2 --key=frodo --keyring=fellowship --location=us-east1 --certificate-chain-type=cavium --output-file=/tmp/my/cavium.pem
        c                 ~   |dk(  rdj                  | j                        S |dk(  rdj                  | j                        S |dk(  rdj                  | j                        S |dk(  r5dj                  | j                  | j                  z   | j                  z         S t	        j
                  dj                  |            )am  Returns the specified certificate chain(s) from a CertChains object.

  Args:
    chains: a KeyOperationAttestation.CertChains object.
    chain_type: a string specifying the chain(s) to retrieve.

  Returns:
    A string containing the PEM-encoded certificate chain(s).

  Raises:
    exceptions.InvalidArgumentException if chain_type is not a valid chain type.
  cavium zgoogle-cardzgoogle-partitionallz{} is not a valid chain type.)joincaviumCertsgoogleCardCertsgooglePartitionCertsr   InvalidArgumentExceptionformat)chains
chain_types     6lib/surface/kms/keys/versions/get_certificate_chain.py_GetCertificateChainPemr   '   s     8776%%&&]"776))**''776..//U776%%(C(CC))* + +++%,,Z8	: :    c                   *    e Zd ZdZeZed        Zd Zy)GetCertificateChainzGet a certificate chain for a given version.

  Returns the PEM-format certificate chain for the specified key version.
  The optional flag `output-file` indicates the path to store the PEM. If not
  specified, the PEM will be printed to stdout.
  c                     t        j                  | d       t        j                  |        t        j                  | d       y )Nz'from which to get the certificate chainzto store PEM)r   AddKeyVersionResourceArgumentAddCertificateChainFlagAddOutputFileFlag)parsers    r   ArgszGetCertificateChain.ArgsM   s4    	''9;	!!&)	FN3r   c                 \   t        j                         }t        j                         }t        j                  |      }|j                         st        j                  dd      |j                  }|j                  |j                  |j                                     }|j                  |j                  j                  j                  k7  rt!        j"                  d      |j$                  |j                  j&                  j(                  k(  rt!        j"                  d      	 t+        j,                  |j.                  r|j.                  ndt1        |j2                  j4                  |j6                        dd	       y # t8        j:                  $ r}t        j<                  |      d }~ww xY w)
Nversionzversion id must be non-empty.)namez;Certificate chains are only available for HSM key versions.zBCertificate chains are unavailable until the version is generated.-TF)	overwritebinary)cloudkms_baseGetClientInstanceGetMessagesModuler   ParseCryptoKeyVersionNameNamer   r   8projects_locations_keyRings_cryptoKeys_cryptoKeyVersionsGetFCloudkmsProjectsLocationsKeyRingsCryptoKeysCryptoKeyVersionsGetRequestRelativeNameprotectionLevelCryptoKeyVersionProtectionLevelValueValuesEnumHSMkms_exceptionsArgumentErrorstateStateValueValuesEnumPENDING_GENERATIONr	   WriteToFileOrStdoutoutput_filer   attestation
certChainscertificate_chain_typer
   ErrorBadFileException)selfargsclientmessagesversion_refversionsr$   es           r   RunzGetCertificateChain.RunT   sv   ,,.F..0H11$7K//
46 6NNHll	O	O))+ 
P 
-.G 	!!@@DD	E((
GI I!!66II	J((
NP P+	"..$

C
!'"5"5"@"@"&"="=? ;; +''**+s   $AE> >F+F&&F+N)	__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpstaticmethodr"   rI    r   r   r   r   A   s%      -4 4+r   r   N)rM   
__future__r   r   r   googlecloudsdk.api_lib.cloudkmsr   r)   googlecloudsdk.callioper   googlecloudsdk.command_lib.kmsr6   r   googlecloudsdk.corer	   googlecloudsdk.core.utilr
   rN   r   ReleaseTracksReleaseTrackALPHABETAGADescribeCommandr   rQ   r   r   <module>r^      s    > &  ' A ( . G 0 # * 	:4 D%%++T->->-C-C%%((*-+$.. -+*-+r   