Skip to content

feat(api-core): add get_universe_domain helper to universe.py - #17799

Merged
hebaalazzeh merged 5 commits into
mainfrom
feat/api-core-universe-domain-helper
Jul 21, 2026
Merged

feat(api-core): add get_universe_domain helper to universe.py#17799
hebaalazzeh merged 5 commits into
mainfrom
feat/api-core-universe-domain-helper

Conversation

@hebaalazzeh

Copy link
Copy Markdown
Contributor

Description

This PR consolidates and centralizes all universe-related configuration helpers and routing logic into google/api_core/universe.py. This avoids polluting gapic_v1 with duplicate routing logic and keeps universe/endpoint utilities unified.

Changes:

  1. get_universe_domain:
    • Added a more general version of get_universe_domain that accepts *potential_universes in order of preference.
    • Made default_universe a required keyword-only argument to align with other client helpers.
  2. determine_domain:
    • Refactored determine_domain to wrap get_universe_domain to preserve backward compatibility.
  3. Endpoint & mTLS Helpers:
    • Moved get_api_endpoint and get_default_mtls_endpoint from the gapic_v1.client_utils namespace into google/api_core/universe.py.
  4. Unit Tests:
    • Migrated all related test cases to tests/unit/test_universe.py.
@hebaalazzeh
hebaalazzeh marked this pull request as ready for review July 20, 2026 23:54
@hebaalazzeh
hebaalazzeh requested a review from a team as a code owner July 20, 2026 23:54

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces helper functions get_universe_domain, get_default_mtls_endpoint, and get_api_endpoint in universe.py to handle universe domain resolution and mTLS endpoint conversion, along with corresponding unit tests. Feedback was provided to avoid using hardcoded magic numbers (-23 and -15) when slicing the host string in get_default_mtls_endpoint, suggesting dynamic calculation based on suffix lengths instead.

Comment thread packages/google-api-core/google/api_core/universe.py Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@hebaalazzeh
hebaalazzeh merged commit d461da7 into main Jul 21, 2026
39 checks passed
@hebaalazzeh
hebaalazzeh deleted the feat/api-core-universe-domain-helper branch July 21, 2026 01:13
This was referenced Jul 21, 2026
hebaalazzeh added a commit that referenced this pull request Jul 30, 2026
This PR refactors the generated client templates to utilize centralized
endpoint routing and universe domain logic.

* **Helper Relocation**: Moved `_get_default_mtls_endpoint`,
`_get_api_endpoint`, and `_get_universe_domain` from generated client
classes to the compatibility layer (`_compat.py`).
* **Backward Compatibility**: Implemented these helpers locally in
`_compat.py` to maintain compatibility with older `google-api-core`
versions, laying groundwork for importing directly from
`google.api_core.universe` (centralized in PR #17799) once the minimum
dependency is bumped.
* **Test Migration**: Moved unit tests for these routing functions from
`test_%service.py.j2` to `test_compat.py.j2`.

Towards: #17883
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants