Skip to content

chore(api_core): move universe and endpoint routing logic to gapic_v1 public helpers#17745

Open
hebaalazzeh wants to merge 5 commits into
mainfrom
feat/gapic-centralization-api-core-routing
Open

chore(api_core): move universe and endpoint routing logic to gapic_v1 public helpers#17745
hebaalazzeh wants to merge 5 commits into
mainfrom
feat/gapic-centralization-api-core-routing

Conversation

@hebaalazzeh

@hebaalazzeh hebaalazzeh commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Centralizes generic routing, mTLS, and universe domain resolution helpers under google.api_core.gapic_v1.routing.

Exposes get_api_endpoint, get_default_mtls_endpoint, and get_universe_domain as public API helpers to be used by newly generated clients.

The unit tests added in test_routing.py are identical to the generator's original routing test cases in test_service.py.j2 (namely test__get_api_endpoint and test__get_universe_domain), modified only to call the public helpers directly:

  • test__get_api_endpoint maps to the new get_api_endpoint helper.
  • test__get_universe_domain maps to the new get_universe_domain helper.

@hebaalazzeh hebaalazzeh changed the title feat: move universe and endpoint routing logic to gapic_v1 public helpers chore(api_core): move universe and endpoint routing logic to gapic_v1 public helpers Jul 16, 2026
@hebaalazzeh
hebaalazzeh marked this pull request as ready for review July 16, 2026 19:17
@hebaalazzeh
hebaalazzeh requested a review from a team as a code owner July 16, 2026 19:17
@hebaalazzeh
hebaalazzeh marked this pull request as draft July 16, 2026 19:17

@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 a new routing module to handle mTLS endpoint resolution and universe domain configuration, along with corresponding unit tests and a test fixture for mTLS environment isolation. It also includes minor refactoring in noxfile.py and test_bidi.py. The reviewer identified an issue with the regex-based endpoint conversion logic in routing.py and suggested a more robust string-based implementation to prevent potential security vulnerabilities.

Comment thread packages/google-api-core/google/api_core/gapic_v1/routing.py Outdated
@hebaalazzeh
hebaalazzeh marked this pull request as ready for review July 16, 2026 19:42
…public helpers

Introduces routing module containing get_api_endpoint, get_default_mtls_endpoint, and get_universe_domain helpers. Exposes the module as public in gapic_v1.
@hebaalazzeh
hebaalazzeh force-pushed the feat/gapic-centralization-api-core-routing branch from 3e2d8e2 to 0fe63b5 Compare July 16, 2026 20:00
# limitations under the License.
#

"""Helpers for routing and endpoint resolution."""

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.

In #17738, you added a new request.py file. In this PR, you added a routing.py. Is there a way we can group these better, to avoid adding too many new files?

default_mtls_endpoint: Optional[str],
default_endpoint_template: Optional[str],
) -> Optional[str]:
"""Return the API endpoint used by the client."""

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.

Can you add better docstrings, now that these are public?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added detailed, standardized docstrings for the public helpers get_api_endpoint, get_universe_domain, and get_default_mtls_endpoint documenting all parameters, return values, and exceptions.


Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
"*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
Args:

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.

IIRC I think you need a blank line above the Args section

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Added blank line and documented the arguments.

default_universe: str,
) -> str:
"""Return the universe domain used by the client."""
universe_domain = default_universe

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.

why rename the variable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the unnecessary variable renaming (universe_domain = default_universe) and simplified the default fallback assignments.

use_mtls_endpoint: str,
default_universe: str,
default_mtls_endpoint: Optional[str],
default_endpoint_template: Optional[str],

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.

These types don't seem to agree with the source. Why is that? This could lead to mypy issues

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed type annotations (such as making default_endpoint_template a required str and the return type of get_api_endpoint a non-optional str) to ensure complete alignment with usages and prevent any mypy type check failures.

@hebaalazzeh hebaalazzeh self-assigned this Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants