
    =3                        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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)
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   8   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%   P                N)	__name__
__module____qualname____firstlineno__r(   r&   r*   WORKLOAD__static_attributes__r3   r   r   r%   r%   P   s    &('(r   r%   c                       \ rS rSrSrS rSrg)WindowsBinaryPathConfigW   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?   rA   rB   r@   s        r   __init__ WindowsBinaryPathConfig.__init__a   s    srww||N,<iHDH  	WW\\.*,@A 	  	WW\\-/> 	O  	 	 WW\\-/1EF 	r   r?   rA   r@   rB   Nr4   r5   r6   r7   __doc__rE   r9   r3   r   r   r;   r;   W       r   r;   c                       \ rS rSrSrS rSrg)LinuxPathConfigt   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>   rC   s        r   rE   LinuxPathConfig.__init__~   s    srww||N,<eDDH  	WW\\.*,<= 	  	WW\\-/= 	O  	 	 WW\\-/1DE 	r   rG   NrH   r3   r   r   rL   rL   t   rJ   r   rL   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>   rC   s        r   rE   MacOSBinaryPathConfig.__init__   s    srww||N,<eDDH  	WW\\.*,<= 	  	WW\\-/@ 	O  	 	 WW\\-/1GH 	r   rG   NrH   r3   r   r   rQ   rQ      rJ   r   rQ   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)rD   rY   rZ   r[   r\   s        r   rE   PKCS11Config.__init__   s    KIJm r   )r[   rY   rZ   r\   Nr4   r5   r6   r7   rE   r9   r3   r   r   rV   rV      s    r   rV   c                       \ rS rSrS rSrg)KeyChainConfig   c                     Xl         X l        g r   issuerkeychain_type)rD   rd   re   s      r   rE   KeyChainConfig.__init__   s    K&r   rc   Nr^   r3   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   )rd   storeprovider)rD   rd   rk   rl   s       r   rE   MyStoreConfig.__init__   s    KJMr   )rd   rl   rk   Nr^   r3   r   r   rh   rh      s    r   rh   c                       \ rS rSrS rSrg)WorkloadConfig   c                     Xl         X l        g r   	cert_pathkey_path)rD   rs   rt   s      r   rE   WorkloadConfig.__init__   s    NMr   rr   Nr^   r3   r   r   ro   ro      s    r   ro   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libsrY   NrZ   r   r[   r\   r?   rA   rB   r@   )getrV   rL   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.
rw   macos_keychainry   rd   Nre   allr?   rA   rB   r@   )r`   rz   rQ   r{   )r|   r}   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.
rw   windows_storery   rd   Nrk   rl   r?   rA   rB   r@   )rh   rz   r;   r{   )r|   r}   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.
rw   workloadrs   Nrt   )ro   rz   r{   )r|   r}   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                 &   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]ry   r@   rw   )r%   r(   r   r&   r   r*   r   r8   r   r   r+   r   VALUEScontext_awareuse_ecp_http_proxyGetBoolIsInternalUserCheck)config_typer|   r}   r   libs_configs        r   create_ecp_configr   W  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   r0   indent)
r   r   rz   r	   WriteFileContentsjsondumpsr   CreatedResourceRESOURCE_TYPE)r   r}   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   Nr0   r   )r   rz   r	   ReadFileContentsr   loadsr   r   r   r   r   r   )r   r}   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   rE   message)rD   r   	__class__s     r   rE   ECPConfigError.__init__  s    	.$(*Lr   )r   )r4   r5   r6   r7   rE   r9   __classcell__)r   s   @r   r   r     s     r   r   r   )'rI   
__future__r   r   r   enumr   r   googlecloudsdk.corer   r   r   googlecloudsdk.core.utilr	   r
   r   r   r   r   r,   Enumr%   objectr;   rL   rQ   rV   r`   rh   ro   r   r   r   r   r   r   r   	Exceptionr   r3   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   