Skip to content

fix(storage): support universe_domain in gRPC clients - #19160

Draft
daniel-sanche wants to merge 2 commits into
mainfrom
storage-grpc-universe-domain
Draft

daniel-sanche wants to merge 2 commits into
mainfrom
storage-grpc-universe-domain

Conversation

@daniel-sanche

@daniel-sanche daniel-sanche commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Updates GrpcClient and AsyncGrpcClient to honor universe_domain (via client_options or GOOGLE_CLOUD_UNIVERSE_DOMAIN) and disable DirectPath outside the default googleapis.com universe.

Changes

  • Added _resolve_grpc_config and _validate_universe_domain helpers, shared between sync and async client init methods. These helpers will avoid direct path on non-default universes

@daniel-sanche
daniel-sanche requested review from a team as code owners November 20, 2026 21:30

@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 universe domain support and validation for both synchronous and asynchronous gRPC clients in the Google Cloud Storage library. It refactors configuration resolution into shared helper functions and ensures DirectPath is disabled for non-default universes. The review feedback highlights a potential issue in _validate_universe_domain where un-specced mock.Mock() credentials used in user tests could cause unexpected failures because they dynamically return truthy Mock objects for the universe_domain attribute. A defensive check is suggested to ensure the retrieved universe domain is a string before validating it.

Comment on lines +115 to +124
def _validate_universe_domain(universe_domain: str, credentials) -> None:
"""Raises UniverseMismatchError unless the credentials belong to ``universe_domain``.
Credentials that do not expose a universe domain are treated as
``googleapis.com``, so they are rejected in any other universe.
"""
if credentials is not None and not isinstance(
credentials, auth_credentials.AnonymousCredentials
):
universe.compare_domains(universe_domain, credentials)

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.

medium

When users write unit tests for their applications, they often use mock.Mock() to mock credentials. Since mock.Mock dynamically creates attributes on access, getattr(credentials, "universe_domain", None) will return a truthy Mock object instead of None or a string. This causes universe.compare_domains to fail or raise unexpected errors because it expects a string or None.

To prevent breaking user tests that use un-specced mocks, we should defensively check if the retrieved universe_domain is a string before calling compare_domains.

Suggested change
def _validate_universe_domain(universe_domain: str, credentials) -> None:
"""Raises UniverseMismatchError unless the credentials belong to ``universe_domain``.
Credentials that do not expose a universe domain are treated as
``googleapis.com``, so they are rejected in any other universe.
"""
if credentials is not None and not isinstance(
credentials, auth_credentials.AnonymousCredentials
):
universe.compare_domains(universe_domain, credentials)
def _validate_universe_domain(universe_domain: str, credentials) -> None:
"""Raises UniverseMismatchError unless the credentials belong to 'universe_domain'.
Credentials that do not expose a universe domain are treated as
'googleapis.com', so they are rejected in any other universe.
"""
if credentials is not None and not isinstance(
credentials, auth_credentials.AnonymousCredentials
):
creds_universe = getattr(credentials, "universe_domain", None)
if creds_universe is not None and not isinstance(creds_universe, str):
return
universe.compare_domains(universe_domain, credentials)

@daniel-sanche
daniel-sanche marked this pull request as draft November 21, 2026 00:35

This branch has not been deployed

No deployments
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.

1 participant