
                         ^    S r SSKrSSKJr  SSKJr  SrSrSrS r	S	 r
S
 rS rS rS rS rg)z3Hooks for Certificate Manager declarative commands.    N)
api_client)timesz{}/dnsAuthorizations/{}z {}/certificateIssuanceConfigs/{}z{}/caPools/{}c                      g)Nglobal r       ;lib/googlecloudsdk/command_lib/certificate_manager/hooks.pyGetLocationr
      s    	r   c                 J   A U(       d  U$ UR                   (       a  / nUR                    H[  nUR                  S5      (       d1  UR                  [        R	                  UR
                  U5      5        MJ  UR                  U5        M]     X2R                  R                  l        U$ )zConverts the dns-authorization argument into a relative URL with project name and location.

Args:
  ref: Reference to the membership object.
  args: Command line arguments.
  request: API request to be issued

Returns:
  Modified request
	projects/)	dns_authorizations
startswithappendDNS_AUTHORIZATIONS_TEMPLATEformatparentcertificatemanageddnsAuthorizations)refargsrequestauthorizationsfields        r	   SetAuthorizationURLr       s     
	N	N((k**'..w~~uE	G 	e$ ) 5C1	.r   c                 $   A U(       d  U$ [        US5      (       at  UR                  (       ac  UR                  R                  S5      (       dC  [        R	                  UR
                  UR                  5      UR                  R                  l        U$ )zConverts the issuance-config argument into a relative URL with project name and location.

Args:
  ref: Reference to the membership object.
  args: Command line arguments.
  request: API request to be issued.

Returns:
  Modified request
issuance_configr   )	hasattrr   r   ISSUANCE_CONFIG_TEMPLATEr   r   r   r   issuanceConfigr   r   r   s      r	   SetIssuanceConfigURLr"   ?   s|     
	N T$  &&t/C/C/N/N0 01I1P1P,,2.G. 
.r   c                    A U(       d  U$ UR                   (       am  UR                   R                  S5      (       dM  [        R                  UR                  UR                   5      UR
                  R                  R                  l        U$ )zConverts the ca-pool argument into a relative URL with project name and location.

Args:
  ref: reference to the membership object.
  args: command line arguments.
  request: API request to be issued

Returns:
  modified request
r   )	ca_poolr   CA_POOL_TEMPLATEr   r   certificateIssuanceConfigcertificateAuthorityConfig!certificateAuthorityServiceConfigcaPoolr!   s      r	   SetCAPoolURLr*   Y   sm     
	N	\\<<"";//n~  oF  oF
..$,,o(g''BBddk 
.r   c                 V    [         R                  " [         R                  " U 5      5      $ )zParses the ISO 8601 lifetime argument.

Args:
  value: An ISO 8601 valid value.

Returns:
  modified value as expected by the API
)r   FormatDurationForJsonParseDuration)values    r	   ParseIso8601LifetimeFlagr/   q   s      
	$	$U%8%8%?	@@r   c           	      j   A U(       d  U$ UR                  S5      (       d.  UR                  S5      (       d  UR                  S5      (       d  U$ UR                  R                  S5      S:X  a;  UR                  (       a  U=R                  S-  sl        U=R                  S-  sl        [        R                  " 5       nUR
                  nUR                  nUR                  UR                  S9nUR                  U5      R                  UR                  l
        UR                  S5      (       a  [        UR                   Vs/ s H  nSU;   d  M  [        US   5      PM     sn5      nUR                  R                   Vs/ s H   n[        UR                  5      U;  d  M  UPM"     snUR                  l
        UR                  S5      (       a  / UR                  l
        UR                  S5      (       a2  UR                  R                  UR                   -   UR                  l
        U$ s  snf s  snf )	zUpdates allowlisted certificates based on the used flag.

Args:
  ref: reference to the membership object.
  args: command line arguments.
  request: API request to be issued

Returns:
  modified request
add_allowlisted_certificatesremove_allowlisted_certificatesclear_allowlisted_certificatesallowlistedCertificates,)namepemCertificate)IsSpecified
updateMaskfindr   GetClientInstanceprojects_locations_trustConfigsMESSAGES_MODULE9CertificatemanagerProjectsLocationsTrustConfigsGetRequestr7   Getr4   trustConfigsetr2   NormalizePemCertificater8   r1   )	r   r   r   clientservicemessagesget_trust_config_requestacpem_certificates_to_be_removeds	            r	   (UpdateTrustConfigAllowlistedCertificatesrJ   ~   s    
	N 

9
:
:@AA?@@N672=C33'')&22'##(HH|| I  
 181 
- 
788%(66*6Br! 	6#3 456* &" %%==3=B"2#4#45-. 	=3G/ 
67724G/	45533

+
+	, /
 
.+*
3s   
H+H+H0"H0c                 L    [         R                  " SSU [         R                  S9$ )zNormalizes the PEM certificate for the comparison by removing all whitespace characters.

Args:
  pem_certificate: PEM certificate to be normalized.

Returns:
  PEM certificate without whitespace characters.
z\s+ )flags)resubASCII)pem_certificates    r	   rC   rC      s     
O288	<<r   )__doc__rN   *googlecloudsdk.api_lib.certificate_managerr   googlecloudsdk.core.utilr   r   r   r%   r
   r   r"   r*   r/   rJ   rC   r   r   r	   <module>rU      sL    : 
 A *7 = " >40
A>B	=r   