
                         0   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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SKrSSKJr  SSKJr  SSKrSr " S S\R.                  5      rS r " S S\R4                  5      rS rS rS rg)z:A module for diagnosing common network and proxy problems.    )absolute_import)division)unicode_literalsN)config)http)
properties)requests)
check_base)diagnostic_base)http_proxy_setup)http_client)urllib<   c                   8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )NetworkDiagnostic*   z1Diagnose and fix local network connection issues.c                 B   > Sn[         [        U ]  US[        5       /S9  g )NzENetwork diagnostic detects and fixes local network connection issues.zNetwork diagnostic)introtitle	checklist)superr   __init__ReachabilityChecker)selfr   	__class__s     :lib/googlecloudsdk/core/diagnostics/network_diagnostics.pyr   NetworkDiagnostic.__init__-   s.    E	
T+/&() , +    c                 V   > [         R                  " 5       (       d  g[        TU ]  5       $ NT)r   IsDefaultUniverser   	RunChecks)r   r   s    r   r"   NetworkDiagnostic.RunChecks4   s#    ''))7r    )	__name__
__module____qualname____firstlineno____doc__r   r"   __static_attributes____classcell__)r   s   @r   r   r   *   s    9+ r   r   c                     / SQn [         R                  R                  R                  R	                  5       =(       d    [
        R                  R                  nU R                  S UR                  S5       5       5        U $ )zReturns a list of hosts whose reachability is essential for the Cloud SDK.

Returns:
  A list of urls (str) to check reachability for.
)zhttps://accounts.google.comz<https://cloudresourcemanager.googleapis.com/v1beta1/projectsz.https://www.googleapis.com/auth/cloud-platformc              3      #    U  H6  n[         R                  R                  U5      R                  S ;   d  M2  Uv   M8     g7f))r   httpsN)r   parseurlparsescheme).0us     r   	<genexpr>DefaultUrls.<locals>.<genexpr>G   s8      G1A&&q)004EE a1s
   1A 	A ,)	r   VALUEScomponent_managersnapshot_urlGetr   INSTALLATION_CONFIGextendsplit)urlsdownload_urlss     r   DefaultUrlsr@   ;   sm    
<$ $$66CCGGI ;--:: ++ G,,S1 G G	+r   c                   2    \ rS rSrSr\S 5       rSS jrSrg)r   L   z5Checks whether the hosts of given urls are reachable.c                     g)Nznetwork connectionr$   )r   s    r   issueReachabilityChecker.issueO   s    r   Nc                    Uc
  [        5       n/ nU H(  n[        U5      nU(       d  M  UR                  U5        M*     U H(  n[        U5      nU(       d  M  UR                  U5        M*     U(       a4  [	        X25      n[
        R                  " SUUS9n[        R                  nXx4$ SR                  U(       a  SOS5      n	[
        R                  " SU(       d  SOU	S	9nUS4$ )
a  Run reachability check.

Args:
  urls: iterable(str), The list of urls to check connection to. Defaults to
    DefaultUrls() (above) if not supplied.
  first_run: bool, True if first time this has been run this invocation.

Returns:
  A tuple of (check_base.Result, fixer) where fixer is a function that can
    be used to fix a failed check, or  None if the check passed or failed
    with no applicable fix.
NF)passedmessagefailureszReachability Check {0}.rG   z
now passesTzNo URLs to check.)rG   rH   )
r@   CheckURLHttplib2appendCheckURLRequestsConstructMessageFromFailuresr
   Resultr   ChangeGcloudProxySettingsformat)
r   r>   	first_runrI   urlfailfail_messageresultfixerpass_messages
             r   CheckReachabilityChecker.CheckS   s     |]dHc"d	  c"d	 
 1(Fl  |*24f88e],33	H4@BLd&* 5H0<>F4<r   r$   r    )	r%   r&   r'   r(   r)   propertyrD   rX   r*   r$   r   r   r   r   L   s    =   (r   r   c                 X    [         R                  " [        S9R                  U SS9  g ! [        R
                  [        R                  [        R                  [        R                  [        R                  4 a/  nSR                  X5      n[        R                   " X!S9s S nA$ S nAff = f)NtimeoutGET)methodzhttplib2 cannot reach {0}:
{1}
rH   	exception)r   Http_NETWORK_TIMEOUTrequestr   HTTPExceptionsocketerrorsslSSLErrorhttplib2HttpLib2Errorsocks	HTTPErrorrP   r
   FailurerR   errmsgs      r   rJ   rJ   ~   s~    :II&'//E/B

#
#V\\3<<

 
 %//
3 :
-
4
4Cc99	:s   &) AB):$B$B)$B)c                      [         R                  " [        S9R                  SU 5        g ! [        R
                  R                   a/  nSR                  X5      n[        R                  " X!S9s S nA$ S nAff = f)Nr\   r^   zrequests cannot reach {0}:
{1}
r`   )
core_requests
GetSessionrc   rd   r	   
exceptionsRequestExceptionrP   r
   rn   ro   s      r   rL   rL      sc    :%56>>ucJ				-	- :
-
4
4Cc99:s   (+ A8	$A3-A83A8c                     SR                  U(       a  SOS5      nU  H!  nUSR                  UR                  5      -  nM#     U(       a  US-  nU$ )z<Constructs error messages along with diagnostic information.zReachability Check {0}.
failedzstill does not passz    {0}
zFNetwork connection problems may be due to proxy or firewall settings.
)rP   rH   )rI   rQ   rH   failures       r   rM   rM      sV    '..9x/DF'g{!!'//22G  ' (G 
.r   )r)   
__future__r   r   r   rf   rh   googlecloudsdk.corer   r   r   r	   rs   googlecloudsdk.core.diagnosticsr
   r   r   rj   	six.movesr   r   rl   rc   
Diagnosticr   r@   Checkerr   rJ   rL   rM   r$   r   r   <module>r      s}     A &  '  
 & $ * 9 6 ; <   !   22 ""/*,, /d::
r   