Repository navigation
fix(firestore): resolve universe_domain and validate credentials #19252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
20a1ae2
1f9d9a0
6d75f72
90107cb
3a7ec09
6d4706f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ | |
| import google.api_core.path_template | ||
| import grpc # type: ignore | ||
| from google.api_core import retry as retries | ||
| from google.api_core import universe | ||
| from google.api_core.gapic_v1 import client_info | ||
| from google.auth.credentials import AnonymousCredentials | ||
| from google.cloud.client import ClientWithProject # type: ignore | ||
|
|
@@ -164,6 +165,12 @@ def __init__( | |
| ) | ||
| self._client_options = client_options | ||
|
|
||
| self._universe_domain = _helpers._resolve_client_universe(self._client_options) | ||
| if self._emulator_host is None: | ||
| _helpers._validate_credentials_universe( | ||
| self._universe_domain, self._credentials | ||
| ) | ||
|
|
||
| self._database = database | ||
|
|
||
| def _firestore_api_helper(self, transport, client_class, client_module) -> Any: | ||
|
|
@@ -178,6 +185,9 @@ def _firestore_api_helper(self, transport, client_class, client_module) -> Any: | |
| if self._emulator_host is not None: | ||
| channel = self._emulator_channel(transport) | ||
| else: | ||
| _helpers._validate_credentials_universe( | ||
| self._universe_domain, self._credentials | ||
| ) | ||
| channel = transport.create_channel( | ||
| self._target, | ||
| credentials=self._credentials, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just below this block ( If the client was initialized via Repro test (fails on this branch with @pytest.mark.parametrize(
"later_env",
[
{},
{"GOOGLE_CLOUD_UNIVERSE_DOMAIN": ""},
],
)
def test_client_firestore_api_preserves_universe_domain_after_env_change(later_env):
from google.cloud.firestore_v1.client import Client
creds = _make_credentials()
creds.universe_domain = "example.com"
with mock.patch.dict(
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "example.com"}, clear=True
):
client = Client(project=PROJECT, credentials=creds)
with mock.patch.dict("os.environ", later_env, clear=True):
with mock.patch(
"google.cloud.firestore_v1.services.firestore.transports.grpc."
"FirestoreGrpcTransport.create_channel",
return_value=mock.create_autospec(grpc.Channel, instance=True),
):
api = client._firestore_api
assert api.universe_domain == "example.com"Propagating
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
|
|
@@ -186,8 +196,12 @@ def _firestore_api_helper(self, transport, client_class, client_module) -> Any: | |
|
|
||
| self._transport = transport(host=self._target, channel=channel) | ||
|
|
||
| client_options = _helpers._inherit_universe_in_client_options( | ||
| self._universe_domain, | ||
| self._client_options, | ||
| ) | ||
| self._firestore_api_internal = client_class( | ||
| transport=self._transport, client_options=self._client_options | ||
| transport=self._transport, client_options=client_options | ||
| ) | ||
| client_module._client_info = self._client_info | ||
|
|
||
|
|
@@ -233,9 +247,18 @@ def _target_helper(self, client_class) -> str: | |
| return self._emulator_host | ||
| elif self._client_options and self._client_options.api_endpoint: | ||
| return self._client_options.api_endpoint | ||
| elif self._universe_domain != universe.DEFAULT_UNIVERSE: | ||
| return client_class._DEFAULT_ENDPOINT_TEMPLATE.format( | ||
| UNIVERSE_DOMAIN=self._universe_domain | ||
| ) | ||
| else: | ||
| return client_class.DEFAULT_ENDPOINT | ||
|
|
||
| @property | ||
| def universe_domain(self) -> str: | ||
| """The universe domain used by the client.""" | ||
| return self._universe_domain | ||
|
|
||
| @property | ||
| def _target(self): | ||
| """Return the target (where the API is). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _clean_universe_domain_env(monkeypatch): | ||
| """Isolate unit tests from workstation GOOGLE_CLOUD_UNIVERSE_DOMAIN.""" | ||
| monkeypatch.delenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN", raising=False) |
Uh oh!
There was an error while loading. Please reload this page.