@@ -133,6 +133,7 @@ def __init__(self):
133133 self ._request_metadata = None
134134 self ._resource_type = None
135135 self ._async_rest_credentials = None
136+ self ._universe_domain = None
136137
137138 def init (
138139 self ,
@@ -153,6 +154,7 @@ def init(
153154 api_key : Optional [str ] = None ,
154155 api_transport : Optional [str ] = None ,
155156 request_metadata : Optional [Sequence [Tuple [str , str ]]] = None ,
157+ universe_domain : Optional [str ] = None ,
156158 ):
157159 """Updates common initialization parameters with provided options.
158160
@@ -220,6 +222,8 @@ def init(
220222 beta state (preview).
221223 request_metadata:
222224 Optional. Additional gRPC metadata to send with every client request.
225+ universe_domain (str):
226+ Optional. The universe domain.
223227 Raises:
224228 ValueError:
225229 If experiment_description is provided but experiment is not.
@@ -291,6 +295,8 @@ def init(
291295 self ._request_metadata = request_metadata
292296 if api_key is not None :
293297 self ._api_key = api_key
298+ if universe_domain is not None :
299+ self ._universe_domain = universe_domain
294300 self ._resource_type = None
295301
296302 # Finally, perform secondary state updates
@@ -348,6 +354,11 @@ def api_key(self) -> Optional[str]:
348354 """API Key, if provided."""
349355 return self ._api_key
350356
357+ @property
358+ def universe_domain (self ) -> Optional [str ]:
359+ """Default universe domain, if provided."""
360+ return self ._universe_domain
361+
351362 @property
352363 def project (self ) -> str :
353364 """Default project."""
@@ -382,7 +393,11 @@ def location(self) -> str:
382393
383394 location = os .getenv ("GOOGLE_CLOUD_REGION" ) or os .getenv ("CLOUD_ML_REGION" )
384395 if location :
385- utils .validate_region (location )
396+ utils .validate_region (
397+ location ,
398+ api_endpoint = self .api_endpoint ,
399+ universe_domain = self .universe_domain ,
400+ )
386401 return location
387402
388403 return constants .DEFAULT_REGION
@@ -449,6 +464,7 @@ def get_client_options(
449464 api_base_path_override : Optional [str ] = None ,
450465 api_key : Optional [str ] = None ,
451466 api_path_override : Optional [str ] = None ,
467+ universe_domain : Optional [str ] = None ,
452468 ) -> client_options .ClientOptions :
453469 """Creates GAPIC client_options using location and type.
454470
@@ -461,6 +477,7 @@ def get_client_options(
461477 api_base_path_override (str): Optional. Override default API base path.
462478 api_key (str): Optional. API key to use for the client.
463479 api_path_override (str): Optional. Override default api path.
480+ universe_domain (str): Optional. Override default universe domain.
464481 Returns:
465482 clients_options (google.api_core.client_options.ClientOptions):
466483 A ClientOptions object set with regionalized API endpoint, i.e.
@@ -491,14 +508,29 @@ def get_client_options(
491508 region = location_override or self .location
492509 region = region .lower ()
493510
494- utils .validate_region (region )
511+ utils .validate_region (
512+ region ,
513+ api_endpoint = self .api_endpoint ,
514+ universe_domain = universe_domain or self .universe_domain ,
515+ )
495516
496517 service_base_path = api_base_path_override or (
497518 constants .PREDICTION_API_BASE_PATH
498519 if prediction_client
499520 else constants .API_BASE_PATH
500521 )
501522
523+ current_universe_domain = (
524+ universe_domain
525+ or self .universe_domain
526+ or constants .DEFAULT_UNIVERSE_DOMAIN
527+ )
528+
529+ if not api_base_path_override and current_universe_domain != "googleapis.com" :
530+ service_base_path = service_base_path .replace (
531+ "googleapis.com" , current_universe_domain
532+ )
533+
502534 api_endpoint = (
503535 f"{ region } -{ service_base_path } "
504536 if not api_path_override
@@ -508,9 +540,14 @@ def get_client_options(
508540 # Project/location take precedence over api_key
509541 if api_key and not self ._project :
510542 return client_options .ClientOptions (
511- api_endpoint = api_endpoint , api_key = api_key
543+ api_endpoint = api_endpoint ,
544+ api_key = api_key ,
545+ universe_domain = universe_domain or self .universe_domain ,
512546 )
513- return client_options .ClientOptions (api_endpoint = api_endpoint )
547+ return client_options .ClientOptions (
548+ api_endpoint = api_endpoint ,
549+ universe_domain = universe_domain or self .universe_domain ,
550+ )
514551
515552 def common_location_path (
516553 self , project : Optional [str ] = None , location : Optional [str ] = None
@@ -524,7 +561,11 @@ def common_location_path(
524561 resource_parent: Formatted parent resource string.
525562 """
526563 if location :
527- utils .validate_region (location )
564+ utils .validate_region (
565+ location ,
566+ api_endpoint = self .api_endpoint ,
567+ universe_domain = self .universe_domain ,
568+ )
528569
529570 return "/" .join (
530571 [
@@ -546,6 +587,7 @@ def create_client(
546587 api_path_override : Optional [str ] = None ,
547588 appended_user_agent : Optional [List [str ]] = None ,
548589 appended_gapic_version : Optional [str ] = None ,
590+ universe_domain : Optional [str ] = None ,
549591 ) -> _TVertexAiServiceClientWithOverride :
550592 """Instantiates a given VertexAiServiceClient with optional
551593 overrides.
@@ -565,6 +607,8 @@ def create_client(
565607 separated by spaces.
566608 appended_gapic_version (str):
567609 Optional. GAPIC version suffix appended in the client info.
610+ universe_domain (str):
611+ Optional. universe domain override.
568612 Returns:
569613 client: Instantiated Vertex AI Service client with optional overrides
570614 """
@@ -607,6 +651,7 @@ def create_client(
607651 api_key = api_key ,
608652 api_base_path_override = api_base_path_override ,
609653 api_path_override = api_path_override ,
654+ universe_domain = universe_domain ,
610655 ),
611656 "client_info" : client_info ,
612657 }
0 commit comments