
    w+                        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rSSKJ	r	  SSKJ
r
  SSKJr  SS	KJr  S
rS rS rS rS r " S S\R&                  5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rS rS  rS! rS" r S(S# jr!S$ r"S% r# " S& S'\$5      r%g))zCreate ECP configurations.    )absolute_import)division)unicode_literalsN)config)log)files)	platformsz/enterprise-certificate-proxy configuration filec                      [         R                  " 5       R                  n U (       d  [        S5      e[        R
                  R                  U SS5      $ )NzKUnable to find the SDK root path. The gcloud installation may be corrupted.platformenterprise_cert)r   Pathssdk_rootECPConfigErrorospathjoin)r   s    [/root/google-cloud-sdk/lib/googlecloudsdk/command_lib/auth/enterprise_certificate_config.pyget_platform_folderr   !   sB    \\^$$(	
	 
 
h
,=	>>    c                  h    [         R                  " 5       R                  n U (       d  [        S5      eU $ )NzJUnable to find the SDK bin path. The gcloud installation may be corrupted.)r   r   sdk_bin_pathr   )r   s    r   get_bin_folderr   ,   s0    ,,,	
	 
 
r   c                 >    U (       a  U $ [         R                  " 5       $ N)r   CertConfigDefaultFilePath)output_files    r   get_config_pathr   7   s    		)	)	++r   c                    U (       d  [         R                  R                  5       n U R                  [         R                  R
                  :X  a  [        R                  $ U R                  [         R                  R                  :X  a  [        R                  $ U R                  [         R                  R                  :X  a  [        R                  $ [        SR                  U R                  5      5      e)NzfUnsupported platform {}. Enterprise Certificate Proxy currently only supports OSX, Windows, and Linux.)r	   PlatformCurrentoperating_systemOperatingSystemMACOSX
ConfigTypeKEYCHAINLINUXPKCS11WINDOWSMYSTOREr   format)r   s    r   platform_to_configr+   =   s    	!!))+H)";";"B"BB  I$=$=$C$CC  I$=$=$E$EE
6
&**
+	 r   c                   $    \ rS rSrSrSrSrSrSrg)r$   O                N)	__name__
__module____qualname____firstlineno__r'   r%   r)   WORKLOAD__static_attributes__r2   r   r   r$   r$   O   s    &('(r   r$   c                       \ rS rSrS rSrg)WindowsBinaryPathConfigV   c                 T   U(       a  UO'[         R                  R                  [        5       S5      U l        U(       a  UO'[         R                  R                  [        5       S5      U l        U(       a  UU l        g [         R                  R                  [        5       S5      U l        g )Nzecp.exez
libecp.dllzlibtls_offload.dllr   r   r   r   ecpr   
ecp_clienttls_offloadselfr>   r?   r@   s       r   __init__ WindowsBinaryPathConfig.__init__X   sy    srww||N,<iHDH  	WW\\-/> 	O  	 	 WW\\-/1EF 	r   r>   r?   r@   Nr3   r4   r5   r6   rC   r8   r2   r   r   r:   r:   V       r   r:   c                       \ rS rSrS rSrg)LinuxPathConfigf   c                 T   U(       a  UO'[         R                  R                  [        5       S5      U l        U(       a  UO'[         R                  R                  [        5       S5      U l        U(       a  UU l        g [         R                  R                  [        5       S5      U l        g )Nr>   z	libecp.sozlibtls_offload.sor=   rA   s       r   rC   LinuxPathConfig.__init__h   sy    srww||N,<eDDH  	WW\\-/= 	O  	 	 WW\\-/1DE 	r   rE   NrF   r2   r   r   rI   rI   f   rG   r   rI   c                       \ rS rSrS rSrg)MacOSBinaryPathConfigv   c                 T   U(       a  UO'[         R                  R                  [        5       S5      U l        U(       a  UO'[         R                  R                  [        5       S5      U l        U(       a  UU l        g [         R                  R                  [        5       S5      U l        g )Nr>   zlibecp.dylibzlibtls_offload.dylibr=   rA   s       r   rC   MacOSBinaryPathConfig.__init__x   sy    srww||N,<eDDH  	WW\\-/@ 	O  	 	 WW\\-/1GH 	r   rE   NrF   r2   r   r   rN   rN   v   rG   r   rN   c                       \ rS rSrS rSrg)PKCS11Config   c                 D    Xl         X l        X0l        U(       a  X@l        g g r   )moduleslotlabeluser_pin)rB   rV   rW   rX   rY   s        r   rC   PKCS11Config.__init__   s    KIJm r   )rX   rV   rW   rY   NrF   r2   r   r   rS   rS      s    r   rS   c                       \ rS rSrS rSrg)KeyChainConfig   c                     Xl         X l        g r   issuerkeychain_type)rB   r`   ra   s      r   rC   KeyChainConfig.__init__   s    K&r   r_   NrF   r2   r   r   r\   r\      s    'r   r\   c                       \ rS rSrS rSrg)MyStoreConfig   c                 (    Xl         X l        X0l        g r   )r`   storeprovider)rB   r`   rg   rh   s       r   rC   MyStoreConfig.__init__   s    KJMr   )r`   rh   rg   NrF   r2   r   r   rd   rd      s    r   rd   c                       \ rS rSrS rSrg)WorkloadConfig   c                     Xl         X l        g r   	cert_pathkey_path)rB   ro   rp   s      r   rC   WorkloadConfig.__init__   s    NMr   rn   NrF   r2   r   r   rk   rk      s    r   rk   c           	      *   U (       a5  U R                  S0 5      R                  S0 5      nU R                  S0 5      nO0 n0 n[        UR                  SS5      =(       d    UR                  SS5      UR                  SS5      =(       d    UR                  SS5      UR                  SS5      =(       d    UR                  SS5      UR                  S	S5      =(       d    UR                  S	S5      5      n[        UR                  S
S5      =(       d    UR                  S
S5      UR                  SS5      =(       d    UR                  SS5      UR                  SS5      =(       d    UR                  SS5      5      nS[        U5      0S[        U5      04$ )a   Creates a Linux ECP Config.

Args:
  base_config: Optional parameter to use as a fallback for parameters that are
    not set in kwargs.
  **kwargs: Linux config parameters. See go/enterprise-cert-config for valid
    variables.

Returns:
  A dictionary object containing the ECP config.
cert_configspkcs11libsrV   NrW   r   rX   rY   r>   r?   r@   )getrS   rI   vars)base_configkwargsbase_linux_configbase_libs_config
ecp_config
lib_configs         r   create_linux_configr~      sd    #;??"M"vr2jj4 I$5$9$9(D$IjjB"3"7"7"Bjj$G#4#8#8$#GjjT"M&7&;&;J&M	* jjB!1!5!5eT!Bjjt$ 2			lD	1jj% 3			mT	2* D$	%Z0@'A	AAr   c                 4   U (       a  U S   S   nU S   nO0 n0 n[        UR                  SS5      =(       d    UR                  SS5      UR                  SS5      =(       d    UR                  SS5      5      n[        UR                  SS5      =(       d    UR                  SS5      UR                  S	S5      =(       d    UR                  S	S5      UR                  S
S5      =(       d    UR                  S
S5      5      nS[        U5      0S[        U5      04$ )a   Creates a MacOS ECP Config.

Args:
  base_config: Optional parameter to use as a fallback for parameters that are
    not set in kwargs.
  **kwargs: MacOS config parameters. See go/enterprise-cert-config for valid
    variables.

Returns:
  A dictionary object containing the ECP config.
rs   macos_keychainru   r`   Nra   allr>   r?   r@   )r\   rv   rN   rw   )rx   ry   base_macos_configr{   r|   r}   s         r   create_macos_configr      s    #N34DE"6*jj4 I$5$9$9(D$Ijj%( 7				6*
 %jjB!1!5!5eT!Bjjt$ 2			lD	1jj% 3			mT	2* D,	-Z8H/I	IIr   c                    U (       a  U S   S   nU S   nO0 n0 n[        UR                  SS5      =(       d    UR                  SS5      UR                  SS5      =(       d    UR                  SS5      UR                  SS5      =(       d    UR                  SS5      5      n[        UR                  SS5      =(       d    UR                  SS5      UR                  S	S5      =(       d    UR                  S	S5      UR                  S
S5      =(       d    UR                  S
S5      5      nS[        U5      0S[        U5      04$ )a$  Creates a Windows ECP Config.

Args:
  base_config: Optional parameter to use as a fallback for parameters that are
    not set in kwargs.
  **kwargs: Windows config parameters. See go/enterprise-cert-config for valid
    variables.

Returns:
  A dictionary object containing the ECP config.
rs   windows_storeru   r`   Nrg   rh   r>   r?   r@   )rd   rv   r:   rw   )rx   ry   base_windows_configr{   r|   r}   s         r   create_windows_configr      s/    %n5oF"6*jj4 K$7$;$;Hd$Kjj$I#6#:#:7D#IjjT"O&9&=&=j$&O*
 'jjB!1!5!5eT!Bjjt$ 2			lD	1jj% 3			mT	2* 4
+	,vtJ7G.H	HHr   c                     U (       a	  U S   S   nO0 n[        UR                  SS5      =(       d    UR                  SS5      UR                  SS5      =(       d    UR                  SS5      5      nS[        U5      00 4$ )a&  Creates a Workload ECP Config.

Args:
  base_config: Optional parameter to use as a fallback for parameters that are
    not set in kwargs.
  **kwargs: Workload config parameters. See go/enterprise-cert-config for
    valid variables.

Returns:
  A dictionary object containing the ECP config.
rs   workloadro   Nrp   )rk   rv   rw   )rx   ry   base_workload_configworkload_configs       r   create_workload_configr     s     &~6zB"jjd# 5		!	!+t	4jjT" 4		!	!*d	3	/ d?+	,b	00r   c                 Z   U [         R                  :X  a  [        U40 UD6u  p4OU [         R                  :X  a  [	        U40 UD6u  p4O`U [         R
                  :X  a  [        U40 UD6u  p4O=U [         R                  :X  a  [        U40 UD6u  p4O[        SR                  U 5      5      eSU0UE$ )a  Creates an ECP Config.

Args:
  config_type: An ConfigType Enum that describes the type of ECP config.
  base_config: Optional parameter to use as a fallback for parameters that are
    not set in kwargs.
  **kwargs: config parameters. See go/enterprise-cert-config for valid
    variables.

Returns:
  A dictionary object containing the ECP config.
Raises:
  ECPConfigError: No valid config_type is specified.
z|Unknown config_type {} passed to create enterprise certificate configuration. Valid options are: [PKCS11, KEYCHAIN, MYSTORE]rs   )r$   r'   r~   r%   r   r)   r   r7   r   r   r*   )config_typerx   ry   r|   libs_configs        r   create_ecp_configr   )  s      J%%%1+HHJj)))1+HHJj(((3KJ6JJj)))4[KFKJ
M
&
	  *	4	44r   c                     [        U S40 UD6n[        UR                  SS5      5      n[        R                  " U[
        R                  " USS95        [        R                  " U[        5        g)z<Creates the ECP config based on the passed in CLI arguments.Nr   r/   indent)
r   r   rv   r   WriteFileContentsjsondumpsr   CreatedResourceRESOURCE_TYPE)r   ry   outputconfig_paths       r   create_configr   K  sS    [$9&9&

=$ ?@++tzz&'CDk=1r   c                 4   [        UR                  SS5      5      n[        R                  " U5      n[        R
                  " U5      n[        X40 UD6n[        R                  " U[        R                  " USS95        [        R                  " U[        5        g)a+  Updates the ECP config based on the passed in CLI arguments.

Args:
  config_type: An ConfigType Enum that describes the type of ECP config.
  **kwargs: config parameters that will be updated. See
    go/enterprise-cert-config for valid variables.

Only explicit args will overwrite existing values
r   Nr/   r   )r   rv   r   ReadFileContentsr   loadsr   r   r   r   r   r   )r   ry   r   dataactive_configr   s         r   update_configr   T  sq      

=$ ?@+				,$**T"-[B6B&+tzz&'CDk=1r   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )r   ih  c                 6   > [         [        U ]  5         Xl        g r   )superr   rC   message)rB   r   	__class__s     r   rC   ECPConfigError.__init__j  s    	.$(*Lr   )r   )r3   r4   r5   r6   rC   r8   __classcell__)r   s   @r   r   r   h  s     r   r   r   )&__doc__
__future__r   r   r   enumr   r   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   r	   r   r   r   r   r+   Enumr$   objectr:   rI   rN   rS   r\   rd   rk   r~   r   r   r   r   r   r   	Exceptionr   r2   r   r   <module>r      s    ! &  '   	 & # * .A?,$ f  f  F  6 'V 'F V  BFJDID165D22(Y r   