
                         X    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5      rg	)
z.Utilities for handling API endpoint overrides.    )gkehub_api_util)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. If the
`gkehub` endpoint is overridden, the `connectgateway` endpoint will use the
same environment.

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                  R                  R                  [        R
                  5      R                  5       n[        R                  nU(       a&  [        R                  " [        R
                  U5      nO+[        R                  " U R                  U R                  5      nU(       a  UR                  SS5      nU R                  S:X  d  U R                  U;   a  X0l        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 $ ! [         R                   a    S nS n GNtf = f)
Ngkehubconnectgatewayglobalzhttps://-   zhttp://   z"Invalid Connect Gateway endpoint: )r   r   r   r   r   GKEHUB_API_NAMEGetGKEHUB_GA_API_VERSIONNoSuchPropertyError	core_apisGetEffectiveApiEndpointr   API_VERSIONreplacer   r   
startswithr   r   r   r   Set)r   hub_overridehub_versionsubdomain_endpoints       r   	__enter__!RegionalGatewayEndpoint.__enter__A   s   &&==FF

)
)  $99k
 $<<

)
); %<<
--)) '//:JK{{h$++1C"C(m		&	&z	2	2"4;;-q1CAB1G0HI((33!$++a0B120F/GH01C0DE
 	
 #mm//1DMMdmm$K; )) lks   AF0 0GGc                 N    U R                   R                  U R                  5        g )N)r   r+   r   )r   exc_type	exc_value	tracebacks       r   __exit__ RegionalGatewayEndpoint.__exit__f   s    MMd--.r   )r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__connectgateway_api_utilr   VERSION_MAPDEFAULT_TRACKr(   strr   r/   r5   __static_attributes__ r   r   r	   r	      sD    	 %--('33+++&S &.#J/r   r	   N)r;   &googlecloudsdk.api_lib.container.fleetr   5googlecloudsdk.api_lib.container.fleet.connectgatewayr   r<   googlecloudsdk.api_lib.utilr   r&   googlecloudsdk.corer   r   r	   rA   r   r   <module>rF      s(    5 C a 9 * *N/ N/r   