Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Add static code for supporting universe domain (to be used in both GAPICs and Apiary) #624

Description

@ohmayr

Universes other than the default "googleapis.com" need to be supported in both GAPICs and Apiary. The following code was added to GAPICs but can be moved to python-api-core:

def_get_universe_domain(
client_universe_domain: Optional[str], universe_domain_env: Optional[str]
) ->str: # temp disable Optional"""Return the universe domain used by the client. Args: client_universe_domain (Optional[str]): The universe domain configured via the client options. universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. Returns: str: The universe domain to be used by the client. Raises: ValueError: If the universe domain is an empty string. """universe_domain=_DEFAULT_UNIVERSEifclient_universe_domainisnotNone:
universe_domain=client_universe_domainelifuniverse_domain_envisnotNone:
universe_domain=universe_domain_enviflen(universe_domain.strip()) ==0:
raise_Empty_Universe_Errorreturnuniverse_domaindef_compare_universes(
client_universe: str, credentials: Union[ga_credentials, oauth2_credentials]
) ->bool:
"""Returns True iff the universe domains used by the client and credentials match. Args: client_universe (str): The universe domain configured via the client options. credentials Union[google.auth.credentials.Credentials, oauth2client.client.Credentials]: The credentials being used in the client. Returns: bool: True iff client_universe matches the universe in credentials. Raises: ValueError: when client_universe does not match the universe in credentials. """credentials_universe=getattr(credentials, "universe_domain", _DEFAULT_UNIVERSE)
ifclient_universe!=credentials_universe:
raise_UniverseMismatchError(client_universe, credentials_universe)
returnTrue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions