
    =                         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  ej"                  ej$                  j&                         G d dej(                               Zy)z6Get the root CA certs for all active CAs in a CA Pool.    )absolute_import)division)unicode_literals)base)request_utils)	pem_utils)resource_args)log)filesc                   ,    e Zd ZdZed        Zd Zd Zy)
GetCaCertszGet the root CA certs for all active CAs in the CA pool.

  ## EXAMPLES

    To get the root CA certs for all active CAs in the CA pool:

      $ {command} my-pool --output-file=ca-certificates.pem \
          --location=us-west1
  c                 ~    t        j                  | d       t        j                  ddd      j	                  |        y )Nz'whose CA certificates should be fetchedz--output-filezThe path where the concatenated PEM certificates will be written. This will include the root CA certificate for each active CA in the CA pool. T)helprequired)r	   AddCaPoolPositionalResourceArgr   ArgumentAddToParser)parsers    +lib/surface/privateca/pools/get_ca_certs.pyArgszGetCaCerts.Args*   s;    009;MM* 
 #{6*    c           	         t        j                  d      }t        j                  d      }|j                  j	                  |j                  |j                         |j                  t        j                                           }|j                  D cg c]  }|j                  d    }}dj                  t        j                  |            S c c}w )z<Returns the root CA certs for all active CAs in the CA pool.v1)	requestId)caPoolfetchCaCertsRequest )privateca_baseGetClientInstanceGetMessagesModuleprojects_locations_caPoolsFetchCaCerts4PrivatecaProjectsLocationsCaPoolsFetchCaCertsRequestRelativeNameFetchCaCertsRequestr   GenerateRequestIdcaCertscertificatesjoinr   PemChainForOutput)selfca_pool_refclientmessagesfetch_ca_certs_responsechain
root_certss          r   _GetRootCertszGetCaCerts._GetRootCerts5   s    --d3F//5H$??LLEE++- ( < <'99; != != 	F 	>? -D,K,K,K52,K   779..z:;;s   Cc                    |j                   j                  j                         }| j                  |      }t	        j
                  |j                  |       t        j                  j                  dj                  |j                               y )Nz%Exported the CA certificates to [{}].)CONCEPTSca_poolParser3   r   WriteFileContentsoutput_filer
   statuswriteformat)r,   argsr-   pem_bags       r   RunzGetCaCerts.RunD   si    --''--/K  -G	D,,g6JJ<CC r   N)__name__
__module____qualname____doc__staticmethodr   r3   r?    r   r   r   r      s%     + +<r   r   N)rC   
__future__r   r   r    googlecloudsdk.api_lib.privatecar   r   r   googlecloudsdk.calliope$googlecloudsdk.command_lib.privatecar   r	   googlecloudsdk.corer
   googlecloudsdk.core.utilr   ReleaseTracksReleaseTrackGACommandr   rE   r   r   <module>rP      s`    = &  ' C : ( : > # * D%%(()* * **r   