
    h                         S 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SKJr  SSK	J
r
  SS	KJr  SS
KJr  SSKrS rS rS rS r  SS jrg)z=A module for changing Cloud SDK proxy settings interactively.    )absolute_import)division)unicode_literals)
http_proxy)log)
properties)
console_io)encoding)http_proxy_typesNc                  "    [        5       u  p[        X5        [        R                  R                  R                  R                  5       (       a  gU(       aZ  / SQn[        R                  " USS9nUS:X  a
  [        5       $ US:X  a*  [        5         [        R
                  R                  S	5        gg[        R                  " S
S9(       a
  [        5       $ g! [        R                   a$    [        R
                  R                  S5        Sn Nf = f)zDisplays proxy information and helps user set up gcloud proxy properties.

Returns:
  Whether properties were successfully changed.
zCloud SDK network proxy settings appear to be invalid. Proxy type, address, and port must be specified. Run [gcloud info] for more details.
TF)z)Change Cloud SDK network proxy propertiesz!Clear all gcloud proxy propertiesExitzWhat would you like to do?messager      z$Cloud SDK proxy properties cleared.
z;Do you have a network proxy you would like to set in gcloud)prompt_string)EffectiveProxyInfo_DisplayGcloudProxyInfor   InvalidValueErrorr   statusPrintVALUEScoredisable_promptsGetBoolr	   PromptChoice_ProxySetupWalkthroughSetGcloudProxyPropertiesPromptContinue)
proxy_infois_existing_proxyoptionsexisting_proxy_idxs       7lib/googlecloudsdk/core/diagnostics/http_proxy_setup.pyChangeGcloudProxySettingsr$       s    	;$6$8!J J:++3355G $0057 Q#%%Q 	jj>?   0C D#%%A 
	%	% JJ	 s   C 5DDc                     [        S [        R                   5       5      n [        R                  " U SS9nUc  gX   R                  5       n[        R                  " S5      n[        R                  R                  5         U(       d  g[        R                  " S5      n[        R                  R                  5         U(       d  g S[        U5      s=::  a  S::  d"  O  [        R                  R                  S	5        g Su  pV[        R                  " SSS9nU(       ax  [        R                  " S5      n[        R                  R                  5         U(       d  g[        R                  " S5      n[        R                  R                  5         U(       d  g[        X#UXVS9  [        R                  R                  S5        g! [         a"    [        R                  R                  S
5         gf = f)z6Walks user through setting up gcloud proxy properties.c              3   @   #    U  H  oR                  5       v   M     g 7f)N)upper).0ts     r#   	<genexpr>)_ProxySetupWalkthrough.<locals>.<genexpr>M   s      :8Aggii8s   zSelect the proxy type:r   FzEnter the proxy host address: zEnter the proxy port: r   i  z(Port number must be between 0 and 65535.z,Please enter an integer for the port number.)NNzIs your proxy authenticated)r   defaultzEnter the proxy username: zEnter the proxy password: 
proxy_typeaddressportusernamepasswordz Cloud SDK proxy properties set.
T)sortedr   PROXY_TYPE_MAPr	   r   lowerPromptResponser   r   r   int
ValueErrorr   r   )proxy_type_optionsproxy_type_idxr.   r/   r0   r1   r2   authenticateds           r#   r   r   K   s    :)88: :**":<.!1779*%%&FG'**			"	"#;	<$**	D	"U"	jjAB # "(++15B-(()EFHJJ(()EFHJJj$,A**67	) 
 JJCDs   7G )G-,G-c                      [         R                  " 5       n U (       d  gSn[        U [        R                  5      (       d
  SnU " S5      n X4$ )a  Returns ProxyInfo effective in gcloud and if it is from gloud properties.

Returns:
  A tuple of two elements in which the first element is an httplib2.ProxyInfo
    object and the second is a bool that is True if the proxy info came from
    previously set Cloud SDK proxy properties.

Raises:
  properties.InvalidValueError: If the properties did not include a valid set.
    "Valid" means all three of these attributes are present: proxy type, host,
    and port.
)NFTFhttps)r   GetHttpProxyInfo
isinstancehttplib2	ProxyInfo)r   from_gcloud_propertiess     r#   r   r   z   sL     **,*	
  	J 2 2	3	3"G$J		++    c                    U (       d  [         R                  R                  5         g[         R                  R                  S5        U(       d  [         R                  R                  S5        [        R                  R                  U R                  S5      n[         R                  R                  SR                  U5      5        [         R                  R                  SR                  U R                  5      5        [         R                  R                  SR                  U R                  5      5        [         R                  R                  SR                  [        R                  " U R                  5      5      5        [         R                  R                  S	R                  [        R                  " U R                  5      5      5        [         R                  R                  5         g)
z%Displays Cloud SDK proxy information.Nz3Current effective Cloud SDK network proxy settings:zL(These settings are from your machine's environment, not gcloud properties.)zUNKNOWN PROXY TYPEz    type = {0}z    host = {0}z    port = {0}z    username = {0}z    password = {0})r   r   r   r   REVERSE_PROXY_TYPE_MAPgetr.   format
proxy_host
proxy_portr
   Decode
proxy_user
proxy_pass)r   from_gcloudproxy_type_names      r#   r   r      sC   	JJ
**HI	JJ / 0$;;??13/**#**?;<**#**:+@+@AB**#**:+@+@AB **'..ooj++,. /**'..ooj++,. /**rC   c                 >   [         R                  " [         R                  R                  R                  U 5        [         R                  " [         R                  R                  R
                  U5        [         R                  " [         R                  R                  R                  U5        [         R                  " [         R                  R                  R                  U5        [         R                  " [         R                  R                  R                  U5        g)zDSets proxy group properties; clears any property not explicitly set.N)	r   PersistPropertyr   proxyr.   r/   r0   r1   r2   r-   s        r#   r   r      s     Z..44??LZ..44<<gFZ..44994@Z..44==xHZ..44==xHrC   )NNNNN)__doc__
__future__r   r   r   googlecloudsdk.corer   r   r   googlecloudsdk.core.consoler	   googlecloudsdk.core.utilr
   r   r@   r$   r   r   r   r    rC   r#   <module>rX      sO     D &  ' * # * 2 - 5 (V,^,:2 BF59IrC   