
                            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rSSK	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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#J$r$  SSK%J&r&  Sr'Sr(\(S-   r) " S S\RT                  5      r* " S S\*5      r+ " S S\*5      r, " S S\*5      r- " S S\*5      r. " S  S!\*5      r/S" r0S?S# jr1\Rd                  S$ 5       r3 " S% S&\Rh                  Rj                  5      r5S'r6 " S( S)\"Rn                  " \Rp                  \Rr                  5      5      r9 " S* S+\95      r: " S, S-\95      r; " S. S/\<5      r=S0r>S1R                  S2R                  \>5      5      rAS3 rBS?S4 jrCS5 rD " S6 S7\95      rE " S8 S9\95      rF " S: S;\95      rGS< rH " S= S>\<5      rIg)@zRun a web flow for oauth2.    )absolute_import)division)unicode_literalsN)flow)config)
exceptions)log)
properties)requests)console_attr)
console_io)universe_descriptor)pkg_resources)errors)input)parsezFailed to start a local webserver listening on any port between {start_port} and {end_port}. Please check your firewall settings or locally running programs that may be blocking or using those ports.i  d   c                       \ rS rSrSrSrg)Error9   zExceptions for the flow module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       +lib/googlecloudsdk/core/credentials/flow.pyr   r   9   s    'r   r   c                       \ rS rSrSrSrg)AuthRequestRejectedError=   z;Exception for when the authentication request was rejected.r   Nr   r   r   r    r"   r"   =   s    Cr   r"   c                       \ rS rSrSrSrg)AuthRequestFailedErrorA   z5Exception for when the authentication request failed.r   Nr   r   r   r    r%   r%   A   s    =r   r%   c                       \ rS rSrSrSrg)LocalServerCreationErrorE   z4Exception for when a local server cannot be created.r   Nr   r   r   r    r(   r(   E   s    <r   r(   c                       \ rS rSrSrSrg)LocalServerTimeoutErrorI   zEException for when the local server timeout before receiving request.r   Nr   r   r   r    r+   r+   I   s    Mr   r+   c                       \ rS rSrSrSrg)WebBrowserInaccessibleM   z@Exception for when a web browser is required but not accessible.r   Nr   r   r   r    r.   r.   M   s    Hr   r.   c                 D    [         R                  " [        S5      U 5        g )Na5  Could not reach the login server. A potential cause of this could be because you are behind a proxy. Please set the environment variables HTTPS_PROXY and HTTP_PROXY to the address of the proxy in the format "protocol://address:port" (without quotes) and try again.
Example: HTTPS_PROXY=http://192.168.0.1:8080)six
raise_fromr%   )
source_excs    r    RaiseProxyErrorr4   Q   s!    ..B 	r   c                     [        U5        [        R                  R                  U R	                  US95        [        S5      R                  5       $ )NurlzEOnce finished, enter the verification code provided in your browser: )ImportReadliner	   errPrintformatr   strip)messageauthorize_urlclient_configs      r    PromptForAuthCoder@   ^   s<    ''--=12	M
	EGr   c               #   \  #     Sv   g! [         R                   a  n [        U 5         Sn A gSn A f[        R                  [        R
                  4 a*  n [        R                  " [        U 5      U 5         Sn A gSn A f[        R                   a5    [        R                  " SS9n [        R                  " [        U 5      U 5      e[         a%  n [        R                  " [        U 5      U 5      eSn A f[        R                   a%  n [        R                  " [        U 5      U 5      eSn A ff = f7f)z:Context manager for handling errors in the OAuth 2.0 flow.NzmToken is not returned from the token endpoint. Re-run the command with --log-http to view the error response.)description)requests_exceptions
ProxyErrorr4   rfc6749_errorsAccessDeniedErrorInvalidGrantErrorr1   r2   r"   MissingTokenErrorr%   
ValueErrorOAuth2Error)es    r    HandleOauth2FlowErrorsrL   f   s     7			'	' A&&&&
 3 NN+A.22		)	) 7
 	((;	A ../2A
66	 7
../2A
66		#	# 7
../2A
667sR   D,	 D,D)-D,'D) A94D,9AD) C--D) D$$D))D,c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)
WSGIServer   a7  WSGI server to handle more than one connections.

A normal WSGI server will handle connections one-by-one. When running a local
server to handle auth redirects, browser opens two connections. One connection
is used to send the authorization code. The other one is opened but not used.
Some browsers (i.e. Chrome) send data in the first connection. Other browsers
(i.e. Safari) send data in the second connection. To make the server working
for all these browsers, the server should be able to handle two connections
and smartly read data from the correct connection.
c                 L    UR                  S[        R                  5      (       + $ )z+Check if conn is closed at the client side.i   )recvsocketMSG_PEEK)selfconns     r    _conn_closedWSGIServer._conn_closed   s    yyv///r   c                     UR                  U5        U Vs/ s H  oDS   ULd  M  UPM     snUS S & U R                  U5        g s  snf Nr   )removeshutdown_request)rT   closed_socketsockets_to_readclient_connectionsrU   s        r    _handle_closed_connWSGIServer._handle_closed_conn   sN    =)++Awm/K+q 	-(s
   AAc                 n    UR                  5       u  pEUR                  XE45        UR                  U5        g N)acceptappend)rT   listening_socketsocket_to_readr^   requestclient_addresss         r    _handle_new_clientWSGIServer._handle_new_client   s2    .557Gw78'"r   c                 H    U H  u  p4X1Ld  M  U R                  U5        M     g rb   )r[   )rT   	data_connr^   rg   _s        r    _handle_non_data_conn WSGIServer._handle_non_data_conn   s"    (
		!g& )r   c                 ,    U H  u  p4X1L d  M  X44s  $    g rb   r   )rT   rl   r^   rg   rh   s        r    #_find_data_conn_with_client_address.WSGIServer._find_data_conn_with_client_address   s    #5		&& $6r   c                 L   U R                   /n/ n [        R                  " U/ / 5      u  n  nU Hq  nXPR                   L a  U R                  XQU5        M%  U R                  U5      (       a  U R	                  XQU5        MO  U R                  XR5        U R                  XR5      s  $    M  )z5Finds the connection which will be used to send data.)rR   selectri   rV   r_   rn   rq   )rT   r]   r^   sockets_ready_to_readrm   ss         r    _find_data_connWSGIServer._find_data_conn   s    {{mO
$*MM/2r$J!Q$!

!
!!6H
Iq!!$$Q9KL &&q=;;' ' % r   c                 $   U R                  5       u  pU R                  X5      (       a   U R                  X5        gU R                  U5        g! [         a%    U R	                  X5        U R                  U5         g  U R                  U5        e = f)zHandle one request.N)rw   verify_requestprocess_request	Exceptionhandle_errorr[   )rT   rg   rh   s      r    handle_requestWSGIServer.handle_request   s    "224G 733W5 G$  ''2g&g&s   A ,B<Br   N)r   r   r   r   r   rV   r_   ri   rn   rq   rw   r~   r   r   r   r    rN   rN      s*    	0)#'
'
'*%r   rN   	localhostc                      ^  \ rS rSrSr    S
U 4S jjrS r\R                  S 5       r	\
S 5       r\
S 5       r\S 5       rS	rU =r$ )InstalledAppFlow   a  Base class of authorization flow for installed app.

Attributes:
  oauth2session: requests_oauthlib.OAuth2Session, The OAuth 2.0 session from
    requests_oauthlib.
  client_type: str, The client type, either "web" or "installed".
  client_config: The client configuration in the Google client secrets format.
  autogenerate_code_verifier: bool, If true, auto-generate a code verifier.
  require_local_server: bool, True if this flow needs a local server to handle
    redirect.
c           	        > [         R                  " US9n[        [        U ]  UUUUUUS9  X0l        U(       a  [        U l        [        5       U l	        [        U R                  U R                  [        [        5      U l        SR                  U R                  U R                  R                  5      U l        OU(       a  X@l        OU R"                  U l        U R$                  R'                  S5      S L U l        g )N)session)redirect_uricode_verifierautogenerate_code_verifierhttp://{}:{}/3pi)r   
GetSessionsuperr   __init__original_client_config
_LOCALHOSThost_RedirectWSGIAppappCreateLocalServer_PORT_SEARCH_START_PORT_SEARCH_ENDserverr;   server_portr   _OOB_REDIRECT_URIr?   getinclude_client_id)
rT   oauth2sessionclient_typer?   r   r   r   require_local_serverr   	__class__s
            r    r   InstalledAppFlow.__init__   s     !!-8G	
D*!##= + ? #0di!#dh%dhh		;M&68dk)00151H1HJd	&00d!//33E:dBDr   c                 p    [        5          U R                  " S0 UD6sS S S 5        $ ! , (       d  f       g = f)Nr   )rL   _RunrT   kwargss     r    RunInstalledAppFlow.Run  s#    		!YY   
"	!	!s   '
5c                     g rb   r   r   s     r    r   InstalledAppFlow._Run  s    r   c                     U R                   R                  S5      =(       d,    U R                   R                  S5      [        R                  :g  $ )z3If the flow is for application default credentials.is_adc	client_id)r?   r   r   CLOUDSDK_CLIENT_IDrT   s    r    _for_adcInstalledAppFlow._for_adc  sB     	x( 	L!!+.&2K2KKr   c                 (    U R                   (       a  gg)N%gcloud auth application-default logingcloud auth login)r   r   s    r    _target_command InstalledAppFlow._target_command  s    }}4 r   c                 t    U R                  UR                  UR                  R                  UR                  S9$ )z>Creates an instance of the current flow from an existing flow.)r   )from_client_configr   r   scoper   )clssource_flows     r    FromInstalledAppFlow%InstalledAppFlow.FromInstalledAppFlow  s?     !!**!!''#.#I#I " K Kr   )r   r   r   r   r   r   )NNFF)r   r   r   r   r   r   r   abcabstractmethodr   propertyr   r   classmethodr   r   __classcell__r   s   @r    r   r      sy    
  !!*/$)C>! 	 	   ! ! K Kr   r   c                   B   ^  \ rS rSrSr   SU 4S jjrS rS rSrU =r	$ )FullWebFlowi$  au  The complete OAuth 2.0 authorization flow.

This class supports user account login using "gcloud auth login" with browser.
Specifically, it does the following:
  1. Try to find an available port for the local server which handles the
     redirect.
  2. Create a WSGI app on the local server which can direct browser to
     Google's confirmation pages for authentication.
c           
      4   > [         [        U ]  UUUUUUSS9  g NTr   r   r   r   )r   r   r   rT   r   r   r?   r   r   r   r   s          r    r   FullWebFlow.__init__/  s.     
+t%!##=! & #r   c                 h   U R                   " S0 UD6u  p#[        R                  " USSS9  Sn[        R                  R                  UR                  US95        U R                  R                  5         U R                  R                  5         U R                  R                  (       d  [        S5      eU R                  R                  R                  SS5      nS	[        R                  S
'   U R!                  UU R"                  SS9  [        R                  S
	 U R%                  5         U R&                  $ )a  Run the flow using the server strategy.

The server strategy instructs the user to open the authorization URL in
their browser and will attempt to automatically open the URL for them.
It will start a local web server to listen for the authorization
response. Once authorization is complete the authorization server will
redirect the user's browser to the local web server. The web server
will get the authorization code from the response and shutdown. The
code is then exchanged for a token.

Args:
    **kwargs: Additional keyword arguments passed through to
      "authorization_url".

Returns:
    google.oauth2.credentials.Credentials: The OAuth 2.0 credentials
      for the user.

Raises:
  LocalServerTimeoutError: If the local server handling redirection timeout
    before receiving the request.
  AuthRequestFailedError: If the user did not consent to the required
    cloud-platform scope.
   Tnew	autoraise2Your browser has been opened to visit:

    {url}
r6   @Local server timed out before receiving the redirection request.http:https:1OAUTHLIB_RELAX_TOKEN_SCOPENauthorization_responser   verifyr   )authorization_url
webbrowseropenr	   r9   r:   r;   r   r~   server_closer   last_request_urir+   replaceosenvironfetch_tokenr   _CheckScopescredentials)rT   r   auth_urlrm   authorization_prompt_messager   s         r    r   FullWebFlow._Run?  s   2 ((262KHOOH!t4 	@ !GGMM.55(5CDKK KK88$$#
LN N "XX66>> 03BJJ+,500  
 	

/0r   c           
         [        U R                  R                  5      nU R                  R                  R                  R	                  S5      n[        U5      [        U5      -
  nSU;   a  [        S5      eU(       aC  [        R                  R                  SU SU S[        U5       S35        X R                  l        gg)	z+Checks requested scopes and granted scopes. z.https://www.googleapis.com/auth/cloud-platformzhttps://www.googleapis.com/auth/cloud-platform scope is required but not consented. Please run the login command again and consent in the login page.zYou have consented to only few of the requested scopes, so some features may not work as expected. If you would like to give consent to all scopes, you can run the login command again. Requested scopes: z.
Scopes you consented for: z.
Missing scopes: .N)
listr   r   tokensplit	frozensetr%   r	   statuswrite)rT   
orig_scopegranted_scopemissing_scopes       r    r   FullWebFlow._CheckScopesu  s    d((../J&&,,2288=Mj)Im,DDM7=H"  	jj  !+| ,_/]0C/DA	G "/ r   r   NNF)
r   r   r   r   r   r   r   r   r   r   r   s   @r    r   r   $  s(     !!*/# 4l/ /r   r   c                   <   ^  \ rS rSrSr   SU 4S jjrS rSrU =r$ )OobFlowi  zeOut-of-band flow.

This class supports user account login using "gcloud auth login" without
browser.
c           
      4   > [         [        U ]  UUUUUUSS9  g NFr   )r   r   r   r   s          r    r   OobFlow.__init__  s.     
'4!!##=" " $r   c                     UR                  SS5        U R                  " S0 UD6u  p#Sn[        XB5      nU R                  USSS9  U R                  $ )  Run the flow using the console strategy.

The console strategy instructs the user to open the authorization URL
in their browser. Once the authorization is complete the authorization
server will give the user a code. The user then must copy & paste this
code into the application. The code is then exchanged for a token.

Args:
    **kwargs: Additional keyword arguments passed through to
      "authorization_url".

Returns:
    google.oauth2.credentials.Credentials: The OAuth 2.0 credentials
      for the user.
promptconsentz5Go to the following link in your browser:

    {url}
TNcoder   r   r   )
setdefaultr   r@   r   r   rT   r   r   rm   r   r   s         r    r   OobFlow._Run  s`      h	*((262KH 	C !9DD$$tDr   r   r   	r   r   r   r   r   r   r   r   r   r   s   @r    r   r     s"     !!*/$  r   r   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)
UrlManageri  zA helper for url manipulation.c                 b   [         R                  " U5      U l        U R                  R                  U R                  R                  U R                  R
                  U R                  R                  4u  U l        U l        U l	        U l
        [         R                  " U R                  5      U l        g rb   )r   urlparse
_parse_urlschemenetlocpathquery_scheme_netloc_path_query	parse_qsl_parsed_query)rT   r7   s     r    r   UrlManager.__init__  ss    nnS)DO 6 68L8L;7DL$,
DK 5Dr   c                 t    U H2  u  p#U R                  U5        U R                  R                  X#45        M4     g)zUpdates query params in the url using query_params.

Args:
   query_params: A list of two-element tuples. The first element in the
     tuple is the query key and the second element is the query value.
N)_RemoveQueryParamr  rd   )rT   query_paramskeyvalues       r    UpdateQueryParamsUrlManager.UpdateQueryParams  s4     #

S!
- #r   c                 8    U H  nU R                  U5        M     g)zXRemoves query params from the url.

Args:
  query_keys: A list of query keys to remove.
N)r  )rT   
query_keysps      r    RemoveQueryParamsUrlManager.RemoveQueryParams  s     
Q r   c                 v    U R                    Vs/ s H  o"S   U:w  d  M  UPM     snU R                   S S & g s  snf rY   r  )rT   	query_keyr  s      r    r  UrlManager._RemoveQueryParam  s5    (,(:(:P(:1di>OQ(:PDqPs   66c                     U R                    VVs1 s H  u  p#UiM	     nnn[        U Vs/ s H  oUU;   PM	     sn5      $ s  snnf s  snf )zIf the url contains the query keys in query_key.

Args:
  query_keys: A list of query keys to check in the url.

Returns:
  True if all query keys in query_keys are contained in url. Otherwise,
    return False.
)r  all)rT   r  kvparsed_query_keysr  s         r    ContainQueryParamsUrlManager.ContainQueryParams  sI     *.););<);v);<
;
1&&
;<< =;s	   ?Ac                 @    U R                    H  u  p#X:X  d  M  Us  $    g)zGets the value of the query_key.

Args:
   query_key: str, A query key to get the value for.

Returns:
  The value of the query_key. None if query_key does not exist in the url.
Nr  )rT   r  r#  r$  s       r    GetQueryParamUrlManager.GetQueryParam  s      ""	 #r   c                     [         R                  " U R                  5      n[         R                  " U R                  U R
                  U R                  SUS45      $ )z*Gets the current url in the string format. )r   	urlencoder  
urlunparser
  r  r  )rT   encoded_querys     r    GetUrlUrlManager.GetUrl  sG    OOD$6$67M	t||TZZ]BGI Ir   c                 v     U R                   R                  SS5      u  p[        U5      $ ! [         a     g f = f)N:r   )r  rsplitintrI   )rT   rm   ports      r    GetPortUrlManager.GetPort  s;    ##C+gaY s   (+ 
88)r  r  r  r  r  r
  N)r   r   r   r   r   r   r  r  r  r&  r)  r0  r7  r   r   r   r    r  r    s/    &6	. Q=Ir   r  )stater   z[The provided authorization response is invalid. Expect a url with query parameters of [{}].z, c                 h    [        U 5      R                  [        5      (       a  g [        [        5      erb   )r  r&  '_REQUIRED_QUERY_PARAMS_IN_AUTH_RESPONSEr%   _AUTH_RESPONSE_ERR_MSG)auth_responses    r    _ValidateAuthResponser>    s,    11-/ /
566r   c                     [        U5        [        R                  R                  U 5        [        R                  R                  S5        [	        U5      R                  5       $ )N
)r8   r	   r9   r:   r   r<   )
helper_msg
prompt_msgr?   s      r    PromptForAuthResponserC    s>    ''--
''--	z		 	 	""r   c                     U bU  SU ;   aN  [         R                  R                  S5      (       d$  [         R                  R                  S5      (       a  SS Kng g g g )Nr   darlinuxr   )sysplatform
startswithreadline)r?   rJ  s     r    r8   r8   #  sN    
=
 <<""5))S\\-D-DW-M-M  .N !  r   c                   V   ^  \ rS rSrSrSrSrSrSrSr	   SU 4S jjr
S	 rS
 rSrU =r$ )NoBrowserFlowi0  a  Flow to authorize gcloud on a machine without access to web browsers.

Out-of-band flow (OobFlow) is deprecated. This flow together with the helper
flow NoBrowserHelperFlow is the replacement. gcloud in
environments without access to browsers (i.e. access via ssh) can use this
flow to authorize gcloud. This flow will print authorization parameters
which will be taken by the helper flow to build the final authorization
request. The helper flow (run by a gcloud instance
with access to browsers) will launch the browser and ask for user's
authorization. After the authorization, the helper flow will print the
authorization response to pass back to this flow to continue the process
(exchanging for the refresh/access tokens).
z506.0.0z420.0.0z372.0.0a	  You are authorizing {target} without access to a web browser. Please run the following command on a machine with a web browser and copy its output back here. Make sure the installed gcloud version is {version} or newer.

{command} --remote-bootstrap="{partial_url}"z'Enter the output of the above command: c           
      4   > [         [        U ]  UUUUUUSS9  g r   )r   rL  r   r   s          r    r   NoBrowserFlow.__init__L  s.     
-'!##=" ( $r   c                    U R                   (       d  SnSnOSnSn[        R                  R                  R                  nUbM  [        R                  R                  R                  R                  5       UR                  :w  a  U R                  nO9U R                  R                  S5      (       a  U R                  nOU R                  nU R                  R                  UUUUS9n[        X`R                  U R                  5      $ )Nz
gcloud CLIr   zclient librariesr   r   )targetversioncommandpartial_url)r   r
   VALUEScoreuniverse_domainGetdefault _REQUIRED_GCLOUD_VERSION_FOR_TPCr?   r   "_REQUIRED_GCLOUD_VERSION_FOR_BYOID_REQUIRED_GCLOUD_VERSION_HELPER_MSGr;   rC  _PROMPT_MSG)rT   rS  rP  rR  universe_domain_propertyrequired_gcloud_versionrA  s          r    _PromptForAuthResponse$NoBrowserFlow._PromptForAuthResponse\  s    ==f#g!f7g)0055EE ,""22668#++, !% E E						&	& $ G G $ = =!!(('	 ) J !$$d&8&8 r   c                    U R                   " S0 UD6u  p#[        U5      nUR                  S/5        UR                  S/5        U R	                  UR                  5       5      n[        U5        [        U5      R                  5       nSR                  [        U5      U l
        U R                  R                  S5      S L nU R                  UUS S9  U R                  $ )Nr   )token_usageremoter   r   r   r   )r   r  r  r  r`  r0  r>  r7  r;   r   r   r?   r   r   r   )rT   r   r   rm   url_managerr=  redirect_portr   s           r    r   NoBrowserFlow._Run{  s    ((262KHX&K !!>"23 !!#<"=>//0B0B0DEM-(}-557M (..z=ID **..u5=,+  
 r   )r   r   )r   r   r   r   r   rY  rZ  r[  r\  r]  r   r`  r   r   r   r   s   @r    rL  rL  0  sJ    " &/"'0$&@+
 :+ !!*/$ > r   rL  c                   d   ^  \ rS rSrSrSrSrSr   SU 4S jjr\	S 5       r
S rS	 rS
 rSrU =r$ )NoBrowserHelperFlowi  a  Helper flow for the NoBrowserFlow to help another gcloud to authorize.

This flow takes the authorization parameters (i.e. requested scopes) generated
by the NoBrowserFlow and launches the browser for users to authorize.
After users authorize, print the authorization response which will be taken
by NoBrowserFlow to continue the login process
(exchanging for refresh/access token).
zRCopy the following line back to the gcloud CLI waiting to continue the login flow.z{bold}WARNING: The following line enables access to your Google Cloud resources. Only copy it to the trusted machine that you ran the `{command} --no-browser` command on earlier.{normal}zDO NOT PROCEED UNLESS YOU ARE BOOTSTRAPPING GCLOUD ON A TRUSTED MACHINE WITHOUT A WEB BROWSER AND THE ABOVE COMMAND WAS THE OUTPUT OF `{command} --no-browser` FROM THE TRUSTED MACHINE.c           
      B   > [         [        U ]  UUUUUUSS9  S U l        g r   )r   ri  r   partial_auth_urlr   s          r    r   NoBrowserHelperFlow.__init__  s9     

t-!##=! . # !Dr   c                 p    [        U R                  5      R                  S5      nU[        R                  :g  $ )Nr   )r  rk  r)  r   r   )rT   r   s     r    r   NoBrowserHelperFlow._for_adc  s.    4001??LI1111r   c                    [         R                  " 5       n[        R                  R	                  U R
                  S-   5        [        R                  R                  U R                  R                  UR                  SS9U R                  UR                  5       S95        [        R                  R	                  S5        [        R                  R                  U5        g )Nr   T)bold)rp  rR  normalr@  )r   GetConsoleAttrr	   r   r   _COPY_AUTH_RESPONSE_INSTRUCTIONr:   _COPY_AUTH_RESPONSE_WARNINGr;   GetFontCoder   )rT   r=  cons      r    _PrintCopyInstruction)NoBrowserHelperFlow._PrintCopyInstruction  s    

%
%
'CJJT99C?@JJ((//d+((??$ 	0 	&'
 JJTJJ]#r   c                 p    [         R                  " U R                  R                  U R                  S9SSS9$ )z6Ask users to confirm before actually running the flow.)rR  ProceedF)prompt_stringrX  )r   PromptContinue_PROMPT_TO_CONTINUE_MSGr;   r   r   s    r    _ShouldContinue#NoBrowserHelperFlow._ShouldContinue  s8    $$$$++D4H4H+I r   c                    UR                  S5      U l        [        U R                  5      nUR                  SU R                  4/[        UR                  5       5      -   5        UR                  5       nU R                  5       (       d  g [        R                  " USSS9  Sn[        R                  R                  UR                  US95        U R                  R!                  5         U R                  R#                  5         U R$                  R&                  (       d  [)        S5      eU R$                  R&                  R+                  S	S
5      nU R-                  U5        g )Nrk  r   r   Tr   r   r6   r   r   r   )poprk  r  r  r   r   itemsr0  r~  r   r   r	   r9   r:   r;   r   r~   r   r   r   r+   r   rw  )rT   r   auth_url_managerr   r   r   s         r    r   NoBrowserHelperFlow._Run  s    "JJ'9:D!$"7"78&&9J9J(K'L'+FLLN';(< =&&(H!!OOH!t4 	@ !GGMM.55(5CDKK KK88$$#
LN N "XX66>>56r   )rk  r   )r   r   r   r   r   rs  rt  r}  r   r   r   rw  r~  r   r   r   r   s   @r    ri  ri    s_     "= 
I  !!*/!" 2 2
$7 7r   ri  c                   <   ^  \ rS rSrSr   SU 4S jjrS rSrU =r$ )RemoteLoginWithAuthProxyFlowi  a(  Flow to authorize gcloud on a machine without access to web browsers.

Out-of-band flow (OobFlow) is deprecated. gcloud in
environments without access to browsers (eg. access via ssh) can use this
flow to authorize gcloud. This flow will print a url which the user has to
copy to a browser in any machine and perform authorization. After the
authorization, the user is redirected to gcloud's auth proxy which displays
the auth code. User copies the auth code back to gcloud to continue the
process (exchanging auth code for the refresh/access tokens).
c           
      4   > [         [        U ]  UUUUUUSS9  g r   )r   r  r   r   s          r    r   %RemoteLoginWithAuthProxyFlow.__init__  s/     

&6!##=" 7 $r   c                     UR                  SS5        UR                  SS5        U R                  " S0 UD6u  p#Sn[        XBU R                  5      nU R	                  XPR
                  SS9  U R                  $ )	r   r   r   rc  rd  zWGo to the following link in your browser, and complete the sign-in prompts:

    {url}
Nr   r   )r   r   r@   r?   r   r   r   r   s         r    r   !RemoteLoginWithAuthProxyFlow._Run  s    " h	* mX.((262KH	# !
 $0B0BD
 	%;%;D   r   r   r   r   r   s   @r    r  r    s"    	 !!*/$ % %r   r  c                 @   UnSnU(       dG  XC:  aB   [         R                  R                  UUU [        [        R
                  S9nU(       d  XC:  a  MB  U(       a  U$ [        [        R                  X#S-
  S95      e! [        R                  [        4 a    US-  n NWf = f)a  Creates a local wsgi server.

Finds an available port in the range of [search_start_port, search_end_point)
for the local server.

Args:
  wsgi_app: A wsgi app running on the local server.
  host: hostname of the server.
  search_start_port: int, the port where the search starts.
  search_end_port: int, the port where the search ends.

Raises:
  LocalServerCreationError: If it cannot find an available port for
    the local server.

Returns:
  WSGISever, a wsgi server.
N)server_classhandler_classr   )
start_portend_port)wsgirefsimple_servermake_serverrN   google_auth_flow_WSGIRequestHandlerrR   errorOSErrorr(   _PORT_SEARCH_ERROR_MSGr;   )wsgi_appr   search_start_portsearch_end_portr6  local_servers         r    r   r   6  s    & 
$,T3**66


!(<< 7 >l T3  ##&11D $ F	G G	 LL'" 
aids   3A; ;BBc                   $    \ rS rSrSrS rS rSrg)r   i\  znWSGI app to handle the authorization redirect.

Stores the request URI and responds with a confirmation page.
c                     S U l         g rb   r   r   s    r    r   _RedirectWSGIApp.__init__b  s
     Dr   c                 j   U" [         R                  " S5      [         R                  " S5      [         R                  " S5      4/5        [        R                  R	                  U5      U l        U R
                  R                  SS5      S   n[        [        R                  " U5      5      nSU;   a  SnOS	n[        R                  " [        U5      n[        R                  " 5       (       dG  [        [        U5      R!                  S
5      R#                  S[$        R&                  " 5       5      S
5      nU/$ )zWSGI Callable.

Args:
    environ (Mapping[str, Any]): The WSGI environment.
    start_response (Callable[str, list]): The WSGI start_response callable.

Returns:
    Iterable[bytes]: The response body.
z200 OKzContent-typez	text/html?r   r   zoauth2_landing.htmlzoauth2_landing_error.htmlzutf-8zcloud.google.com)r1   
ensure_strr  utilrequest_urir   r   dictr   r  r   GetResourcer   r
   IsDefaultUniversebytesdecoder   r   GetUniverseDocumentDomain)rT   r   start_responser	  pagepage_strings         r    __call___RedirectWSGIApp.__call__e  s     x 
..
(#..*E	FGI $LL44W=D!!''Q/3E'(E"d(d++Hd;K''))

6'?7 !;;= k =r   r  N)r   r   r   r   r   r   r  r   r   r   r    r   r   \  s    
!"r   r   rb   )Jr   
__future__r   r   r   r   
contextlibr   rt   rR   rG  r   r  google_auth_oauthlibr   r  googlecloudsdk.corer   r   c_exceptionsr	   r
   r   googlecloudsdk.core.consoler   r   'googlecloudsdk.core.universe_descriptorr   googlecloudsdk.core.utilr   oauthlib.oauth2.rfc6749r   rE   rC   r1   	six.movesr   six.moves.urllibr   r  r   r   r   r"   r%   r(   r+   r.   r4   r@   contextmanagerrL   r  rN   r   with_metaclassABCMetar   r   r   objectr  r;  r;   joinr<  r>  rC  r8   rL  ri  r  r   r   r   r   r    <module>r     s    ! &  ' 
  	   
   9 & : # * ( 4 2 G 2 < 6 
  "%   %+ (L (Du D>U >=u =Ne NIU I
 7 7:M%&&11 M%` 
JKs{{$4$E$EFJKZi/" i/Z0 0fF FR +< '%%+V		9:&< 7#
f$ fRV7* V7rA#3 AH#GL+v +r   