
    /                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 dZ
d	Zd
Zd Zd Zd Zd Zd Zd Zd Zy)z3Hooks for Certificate Manager declarative commands.    )absolute_import)division)unicode_literalsN)
api_client)timesz{}/dnsAuthorizations/{}z {}/certificateIssuanceConfigs/{}z{}/caPools/{}c                       y)Nglobal r
       ;lib/googlecloudsdk/command_lib/certificate_manager/hooks.pyGetLocationr      s    	r   c                 (   ~ |s|S |j                   rg }|j                   D ]T  }|j                  d      s0|j                  t        j	                  |j
                  |             D|j                  |       V ||j                  j                  _        |S )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G1	.r   c                     ~ |s|S t        |d      rj|j                  r^|j                  j                  d      sCt        j	                  |j
                  |j                        |j                  j                  _        |S )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%   B   sr     
	N T$ &&t/C/C/N/N01I1P1P,,2.G. 
.r   c                     ~ |s|S |j                   rh|j                   j                  d      sMt        j                  |j                  |j                         |j
                  j                  j                  _        |S )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-   \   sj     
	N	\\<<"";/n~  oF  oF
..$,,o(g''BBddk 
.r   c                 R    t        j                  t        j                  |             S )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   ParseIso8601LifetimeFlagr2   t   s      
	$	$U%8%8%?	@@r   c           	          ~ |s|S |j                  d      s$|j                  d      s|j                  d      s|S |j                  j                  d      dk(  r6|j                  r|xj                  dz  c_        |xj                  dz  c_        t        j                         }|j
                  }|j                  }|j                  |j                        }|j                  |      j                  |j                  _
        |j                  d      r}t        |j                  D cg c]  }d|v rt        |d          c}      }|j                  j                  D cg c]  }t        |j                        |vr| c}|j                  _
        |j                  d      rg |j                  _
        |j                  d      r2|j                  j                  |j                   z   |j                  _
        |S c c}w c c}w )	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_MODULE9CertificatemanagerProjectsLocationsTrustConfigsGetRequestr:   Getr7   trustConfigsetr5   NormalizePemCertificater;   r4   )	r   r   r   clientservicemessagesget_trust_config_requestacpem_certificates_to_be_removeds	            r   (UpdateTrustConfigAllowlistedCertificatesrM      s    
	N 

9
:@A?@N672=C33'')&22'##(HH|| I  
 181 
- 
78%(66*6Br! 	 #3 456* &" %%==3=B"2#4#45-. 	=3G/ 
6724G/	4533

+
+	, /
 
.+*
3s   %G6 G;c                 P    t        j                  dd| t         j                        S )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   rF   rF      s     
O288	<<r   )__doc__
__future__r   r   r   rQ   *googlecloudsdk.api_lib.certificate_managerr   googlecloudsdk.core.utilr   r   r"   r(   r   r   r%   r-   r2   rM   rF   r
   r   r   <module>rY      sS    : &  ' 	 A *7 = " >40
A>B	=r   