
                         l    S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	J
r
  SSKJr  S	 rS
 rg)z-Certificate utilities for Privateca commands.    )absolute_import)division)unicode_literalsN)base)
exceptions)timesc                    SR                  U5      n[        R                  " SS9n[        R                  " SS9nUR                  R                  UR                  U R                  5       US95      nUR                  (       d4  [        R                  " SSR                  U R                  5       5      5      eUR                  S   $ )a  Obtains a certificate by serial num by filtering all certs in a CA pool.

Args:
  ca_pool_ref: The resource reference to the CA pool.
  serial_num: The serial number to lookup the certificate by.

Returns:
  The certificate message of the corresponding serial number. Ignores
  duplicate certificates.

Raises:
  exceptions.InvalidArgumentError if there were no certificates with the
  specified CA pool and serial number.
z@certificate_description.subject_description.hex_serial_number:{}v1)api_version)parentfilterz--serial-numberzBThe serial number specified does not exist under the CA pool [{}]]r   )formatr   GetClientInstanceGetMessagesModule'projects_locations_caPools_certificatesList8PrivatecaProjectsLocationsCaPoolsCertificatesListRequestRelativeNamecertificatesr   InvalidArgumentException)ca_pool_ref
serial_numcert_filterclientmessagesresponses         9lib/googlecloudsdk/api_lib/privateca/certificate_utils.pyGetCertificateBySerialNumr      s      IOO
 
 !!d3&##5(;;@@GG))+K H ( 
		

-
-L	((*	+  
		q	!!    c                  ~  ^^ [         R                  " 5       m[        R                  [        R                  -   mSR                  UU4S j[        S5       5       5      n SR                  UU4S j[        S5       5       5      n[        R                  " [        R                  " 5       S5      nSR                  X U5      $ )zGenerate a certificate id with the date and two length 3 alphanum strings.

E.G. YYYYMMDD-ABC-DEF.

Returns:
  The generated certificate id string.
 c              3   F   >#    U  H  nTR                  T5      v   M     g 7fNchoice.0ialphanumsys_rngs     r   	<genexpr>!GenerateCertId.<locals>.<genexpr>Q        FX7>>(33X   !   c              3   F   >#    U  H  nTR                  T5      v   M     g 7fr#   r$   r&   s     r   r+   r,   R   r-   r.   z%Y%m%dz{}-{}-{})randomSystemRandomstringascii_uppercasedigitsjoinranger   FormatDateTimeNowr   )alphanum_rand1alphanum_rand2date_strr)   r*   s      @@r   GenerateCertIdr=   D   s     !'##fmm3(77FU1XFF.77FU1XFF.!!%))+x8(			8^	DDr   )__doc__
__future__r   r   r   r1   r3    googlecloudsdk.api_lib.privatecar   googlecloudsdk.callioper   googlecloudsdk.core.utilr   r   r=    r   r   <module>rD      s.    4 &  '   1 . *$"NEr   