
                         p    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
5      rg)z.Utilities for handling API endpoint overrides.    )absolute_import)division)unicode_literals)util)apis)
exceptions)
propertiesc                   |    \ rS rSrSr\R                  r\R                  \R                     r	S\
4S jrS rS rSrg)	RegionalGatewayEndpoint   a"  Context manager for connecting to a particular regional Connect Gateway endpoint.

This uses the provided region to temporarily override
`api_endpoint_overrides/connectgateway` to a regional endpoint.

This context manager is a no-op if the `connectgateway` endpoint is already
overridden.
regionc                     U(       d  [         R                  " S5      eXl        SU l        [        R
                  R                  R                  U R                  5      U l	        SU l
        g)zInitializes the context manager.

Args:
  region: The Connect Gateway region to connect to.

Raises:
  exceptions.Error: If `region` is Falsy.
z3A region must be provided for the Gateway endpoint. N)r   Errorr   endpointr	   VALUESapi_endpoint_overridesPropertyAPI_NAMEoverride_original_endpoint)selfr   s     ;lib/googlecloudsdk/command_lib/container/fleet/overrides.py__init__ RegionalGatewayEndpoint.__init__*   sZ     
?  KDM%%<<EEDM $&D    c                 (   [         R                  " U R                  U R                  5      nU R                  S:X  d  U R                  U;   a  Xl        O{UR                  S5      (       a  SU R                   SUSS   3U l        OJUR                  S5      (       a  SU R                   SUSS   3U l        O[        R                  " SU 35      eU R                  R                  5       U l        U R                  R                  U R
                  5        U $ )Nglobalzhttps://-   zhttp://   z"Invalid Connect Gateway endpoint: )	core_apisGetEffectiveApiEndpointr   API_VERSIONr   r   
startswithr   r   r   Getr   Set)r   subdomain_endpoints     r   	__enter__!RegionalGatewayEndpoint.__enter__A   s    "::t'' {{h$++1C"C(m		&	&z	2	2"4;;-q1CAB1G0HI((33!$++a0B120F/GH01C0DE
 	
 #mm//1DMMdmm$Kr   c                 N    U R                   R                  U R                  5        g )N)r   r'   r   )r   exc_type	exc_value	tracebacks       r   __exit__ RegionalGatewayEndpoint.__exit__V   s    MMd--.r   )r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__connectgateway_api_utilr   VERSION_MAPDEFAULT_TRACKr$   strr   r)   r/   __static_attributes__ r   r   r   r      sC     %--('33+++&S &.*/r   r   N)r5   
__future__r   r   r   5googlecloudsdk.api_lib.container.fleet.connectgatewayr   r6   googlecloudsdk.api_lib.utilr   r"   googlecloudsdk.corer   r	   r   r;   r   r   <module>r@      s)    5 &  ' a 9 * *</ </r   