
    E                     "   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	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  \R0                   " S S\R2                  5      5       rS rg)z(Command for proxying to a given service.    )absolute_import)division)unicode_literals)base)config_helper)connection_context)
exceptions)flags)messages_util)	platforms)pretty_print)proxy)resource_args)serverless_operations)concept_parsers)presentation_specs)storec                   T    \ rS rSrSrSSS.r\S 5       r\S 5       rS r	S	 r
S
 rSrg)Proxy%   a  Proxy a service to localhost authenticating as the active account or with the specified token.

Runs a server on localhost that proxies requests to the specified Cloud Run
Service with credentials attached.

You can use this to test services protected with IAM authentication.

The Cloud Run service must be reachable from the machine running this
command. For example, if the Cloud Run Service is configured to only allow
`internal` ingress, this command will not work from outside the service's
VPC network.
z"          {description}
          a            To proxy the service 'my-service' at localhost port 8080:

              $ {command} my-service --port=8080

          To proxy the existing traffic tag 'my-tag' on the service 'my-service:

              $ {command} my-service --tag=my-tag
          )DESCRIPTIONEXAMPLESc                 &   [         R                  " S[        R                  " 5       SSSS9n[        R
                  " U SS9  [        R                  " U 5        [        R                  " U SS9  [        R                  " U/5      R                  U 5        g )	NSERVICEzService to proxy locally.TF)requiredprefixeszZLocal port number to expose the proxied service. If not specified, it will be set to 8080.)	help_texta7  Traffic tag of the service to expose via the proxy. If not specified, the default service URL will be proxied which may serve different revisions based on traffic-splits. Custom tags can be used to proxy specific revisions. Please see https://cloud.google.com/run/docs/rollouts-rollbacks-traffic-migration#tags.)r   ResourcePresentationSpecr   GetServiceResourceSpecr
   AddPortFlagAddTokenFlagAddDeployTagFlagr   ConceptParserAddToParser)parserservice_presentations     !lib/surface/run/services/proxy.py
CommonArgsProxy.CommonArgsC   s    -FF,,.# 
8 
v	[	 !!#7"89EEfM    c                 .    [         R                  U 5        g N)r   r(   )r%   s    r'   Args
Proxy.Args`   s    	Vr*   c                     [         R                  " 5       nU[         R                  :w  a  [        R                  " S5      eg )Nz;This command is only supported for fully managed Cloud Run.)r   GetPlatformPLATFORM_MANAGEDr	   PlatformError)selfplatforms     r'   _CheckPlatformProxy._CheckPlatformd   s9    $$&H9---$$
G  .r*   c                    U R                  5         [        R                  " U[        R                  R
                  U R                  5       5      nUR                  R                  R                  5       n[        R                  " U5        [        R                  " U5       nUR                  U5      nS S S 5        W(       d*  [        R                  " [         R"                  " X#5      5      eSUR$                  (       a  UR$                  OS-   nU R'                  XQR(                  UR*                  5      n[,        R.                  " 5       n[0        R2                  " [         R4                  " UUS5      5        [0        R2                  " SR7                  Xg5      5        UR8                  (       a  U" XqR8                  US9n	O& U" U[;        5       USS9n	U	R<                  (       a  OM%  U R?                  U	5      $ ! , (       d  f       GNH= f)Nz
127.0.0.1:8080zProxying tozhttp://{} proxies to {})hosttokenbind55m)r9   r:   r;   duration) r5   r   GetConnectionContextr
   ProductRUNReleaseTrackCONCEPTSserviceParseValidateResourcer   Connect
GetServicer	   ArgumentErrorr   GetNotFoundMessageport_GetUrltag
servicesIdr   ProxyWrapperr   InfoGetStartDeployMessageformatr:   _GetFreshIdTokenfailed _DefaultOperationResponseHandler)
r3   argsconn_contextservice_refclientservr;   r9   command_executorresponses
             r'   Run	Proxy.Runk   s   %::emm!2!2!4L --''--/K	;'		&	&|	4{+d 
5$$

*
*<
E  		499v>D<<hh(>(>?D))+++	
 /66tBCzz!t::DIh #-/dU
 ??
  00::A 
5	4s   G22
Hc                 T   UR                   (       d%  [        R                  " SR                  U5      5      eU(       a  UR                   R                   HW  nUR
                  U:X  d  M  UR                  (       d%  [        R                  " SR                  X#5      5      eUR                  s  $    [        R                  " SR                  X#5      5      eUR                   R                  (       d%  [        R                  " SR                  U5      5      eUR                   R                  $ )Nz#Status of service [{}] is not readyz-URL for tag [{}] in service [{}] is not readyz%Cannot find tag [{}] in service [{}].z!URL for service [{}] is not ready)statusr	   rH   rQ   trafficrL   url)r3   rY   rL   serv_idts        r'   rK   Proxy._GetUrl   s    ;;$$
/
6
6w
?  {{""!55C<**?FF 
 , # $$
1
8
8
F  ;;??$$
-
4
4W
=  ;;??r*    N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr(   r-   r5   r\   rK   __static_attributes__re   r*   r'   r   r   %   sR    	- N N8  (;Tr*   r   c                  p    [         R                  " 5       n [        R                  " U 5      nUR                  $ r,   )r   LoadFreshCredentialr   
Credentialid_token)cred
credentials     r'   rR   rR      s,    		"	"	$$''-*			r*   N)rj   
__future__r   r   r   googlecloudsdk.callioper   !googlecloudsdk.command_lib.configr   googlecloudsdk.command_lib.runr   r	   r
   r   r   r   r   r   r   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.core.credentialsr   UniverseCompatibleBinaryBackedCommandr   rR   re   r*   r'   <module>r|      sm    / &  ' ( ; = 5 0 8 4 7 0 8 @ D G 1 FD$$ F FRr*   