
    2                        S 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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.    N)config)log)
properties)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    Dlib/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   5   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"   M                N)	__name__
__module____qualname____firstlineno__r%   r#   r'   WORKLOAD__static_attributes__r0   r   r   r"   r"   M   s    &('(r   r"   c                       \ rS rSrSrS rSrg)WindowsBinaryPathConfigT   zConfiguration for the paths to the ECP binaries on Windows.

Attributes:
  ecp: Path to the ECP binary.
  ecp_http_proxy: Path to the ECP HTTP proxy binary.
  ecp_client: Path to the ECP client library.
  tls_offload: Path to the TLS offload library.
c                    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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ecp_http_proxy.exez
libecp.dllzlibtls_offload.dll	r   r   r   r   ecpecp_http_proxyr   
ecp_clienttls_offloadselfr<   r>   r?   r=   s        r   __init__ WindowsBinaryPathConfig.__init__^   s    srww||N,<iHDH  	WW\\.*,@A 	  	WW\\-/> 	O  	 	 WW\\-/1EF 	r   r<   r>   r=   r?   Nr1   r2   r3   r4   __doc__rB   r6   r0   r   r   r8   r8   T       r   r8   c                       \ rS rSrSrS rSrg)LinuxPathConfigq   zConfiguration for the paths to the ECP binaries on Linux.

Attributes:
  ecp: Path to the ECP binary.
  ecp_http_proxy: Path to the ECP HTTP proxy binary.
  ecp_client: Path to the ECP client library.
  tls_offload: Path to the TLS offload library.
c                    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O'[         R                  R                  [        5       S5      U l        U(       a  UU l        g [         R                  R                  [        5       S5      U l        g )Nr<   r=   z	libecp.sozlibtls_offload.sor;   r@   s        r   rB   LinuxPathConfig.__init__{   s    srww||N,<eDDH  	WW\\.*,<= 	  	WW\\-/= 	O  	 	 WW\\-/1DE 	r   rD   NrE   r0   r   r   rI   rI   q   rG   r   rI   c                       \ rS rSrSrS rSrg)MacOSBinaryPathConfig   zConfiguration for the paths to the ECP binaries on MacOS.

Attributes:
  ecp: Path to the ECP binary.
  ecp_http_proxy: Path to the ECP HTTP proxy binary.
  ecp_client: Path to the ECP client library.
  tls_offload: Path to the TLS offload library.
c                    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O'[         R                  R                  [        5       S5      U l        U(       a  UU l        g [         R                  R                  [        5       S5      U l        g )Nr<   r=   zlibecp.dylibzlibtls_offload.dylibr;   r@   s        r   rB   MacOSBinaryPathConfig.__init__   s    srww||N,<eDDH  	WW\\.*,<= 	  	WW\\-/@ 	O  	 	 WW\\-/1GH 	r   rD   NrE   r0   r   r   rN   rN      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)rA   rV   rW   rX   rY   s        r   rB   PKCS11Config.__init__   s    KIJm r   )rX   rV   rW   rY   Nr1   r2   r3   r4   rB   r6   r0   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)rA   ra   rb   s      r   rB   KeyChainConfig.__init__   s    K&r   r`   Nr[   r0   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   )ra   storeprovider)rA   ra   rh   ri   s       r   rB   MyStoreConfig.__init__   s    KJMr   )ra   ri   rh   Nr[   r0   r   r   re   re      s    r   re   c                       \ rS rSrS rSrg)WorkloadConfig   c                     Xl         X l        g r   	cert_pathkey_path)rA   rp   rq   s      r   rB   WorkloadConfig.__init__   s    NMr   ro   Nr[   r0   r   r   rl   rl      s    r   rl   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      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?   r=   )getrS   rI   vars)base_configkwargsbase_linux_configbase_libs_config
ecp_config
lib_configs         r   create_linux_configr      s    #;??"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jj!4( 6			.	5* D$	%Z0@'A	AAr   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      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      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.
rt   macos_keychainrv   ra   Nrb   allr<   r>   r?   r=   )r]   rw   rN   rx   )ry   rz   base_macos_configr|   r}   r~   s         r   create_macos_configr      s6    #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jj!4( 6			.	5* 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      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.
rt   windows_storerv   ra   Nrh   ri   r<   r>   r?   r=   )re   rw   r8   rx   )ry   rz   base_windows_configr|   r}   r~   s         r   create_windows_configr     sT    %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jj!4( 6			.	5* 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.
rt   workloadrp   Nrq   )rl   rw   rx   )ry   rz   base_workload_configworkload_configs       r   create_workload_configr   9  s     &~6zB"jjd# 5		!	!+t	4jjT" 4		!	!*d	3	/ d?+	,b	00r   c                 &   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[        R                  R                  R                  R                  5       (       a  [        R                   " 5       (       d  SU;   a  SUS   ;   a  US   S	 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]rv   r=   rt   )r"   r%   r   r#   r   r'   r   r5   r   r   r(   r   VALUEScontext_awareuse_ecp_http_proxyGetBoolIsInternalUserCheck)config_typery   rz   r}   libs_configs        r   create_ecp_configr   T  s     J%%%1+HHJj)))1+HHJj(((3KJ6JJj)))4[KFKJ
M
&
	  


)
)
<
<
D
D
F
F,,..
K

k&1
1F,-
*	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   rw   r   WriteFileContentsjsondumpsr   CreatedResourceRESOURCE_TYPE)r   rz   outputconfig_paths       r   create_configr     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   rw   r   ReadFileContentsr   loadsr   r   r   r   r   r   )r   rz   r   dataactive_configr   s         r   update_configr     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   i  c                 6   > [         [        U ]  5         Xl        g r   )superr   rB   message)rA   r   	__class__s     r   rB   ECPConfigError.__init__  s    	.$(*Lr   )r   )r1   r2   r3   r4   rB   r6   __classcell__)r   s   @r   r   r     s     r   r   r   )#rF   enumr   r   googlecloudsdk.corer   r   r   googlecloudsdk.core.utilr   r   r   r   r   r   r)   Enumr"   objectr8   rI   rN   rS   r]   re   rl   r   r   r   r   r   r   r   	Exceptionr   r0   r   r   <module>r      s    !   	 & # * * .A?,$ f :f :F :6 'V 'F V "BJ!JH!IH16+5\22(Y r   