From 016d00ea3bf2f67dbedaf350a5fda74062e21f45 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Tue, 21 Jul 2026 16:18:01 +0000 Subject: [PATCH 1/2] feat(api-core): centralize endpoint routing and universe domain resolution --- .../google/api_core/gapic_v1/__init__.py | 5 ++- .../google/api_core/gapic_v1/client_utils.py | 24 ++++++++++++++ packages/google-api-core/tests/conftest.py | 31 +++++++++++++++++++ .../tests/unit/gapic/test_client_utils.py | 20 ++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 packages/google-api-core/google/api_core/gapic_v1/client_utils.py create mode 100644 packages/google-api-core/tests/conftest.py create mode 100644 packages/google-api-core/tests/unit/gapic/test_client_utils.py diff --git a/packages/google-api-core/google/api_core/gapic_v1/__init__.py b/packages/google-api-core/google/api_core/gapic_v1/__init__.py index 78937c032670..aaebf2ba9e8e 100644 --- a/packages/google-api-core/google/api_core/gapic_v1/__init__.py +++ b/packages/google-api-core/google/api_core/gapic_v1/__init__.py @@ -25,10 +25,12 @@ # Older Python versions safely ignore this variable. __lazy_modules__: Set[str] = { "google.api_core.gapic_v1.client_info", + "google.api_core.gapic_v1.client_utils", "google.api_core.gapic_v1.requests", "google.api_core.gapic_v1.routing_header", } -__all__ = ["client_info", "requests", "routing_header"] +__all__ = ["client_info", "client_utils", "requests", "routing_header"] + if _has_grpc: __lazy_modules__.update( @@ -42,6 +44,7 @@ from google.api_core.gapic_v1 import ( # noqa: E402 client_info, + client_utils, requests, routing_header, ) diff --git a/packages/google-api-core/google/api_core/gapic_v1/client_utils.py b/packages/google-api-core/google/api_core/gapic_v1/client_utils.py new file mode 100644 index 000000000000..ec26bc0d793f --- /dev/null +++ b/packages/google-api-core/google/api_core/gapic_v1/client_utils.py @@ -0,0 +1,24 @@ +# 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. +# + +"""Helpers for client setup and configuration.""" + +from google.api_core.universe import ( + get_universe_domain, +) + +__all__ = [ + "get_universe_domain", +] diff --git a/packages/google-api-core/tests/conftest.py b/packages/google-api-core/tests/conftest.py new file mode 100644 index 000000000000..62a3c999f733 --- /dev/null +++ b/packages/google-api-core/tests/conftest.py @@ -0,0 +1,31 @@ +# 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 os +from unittest import mock + +import pytest + + +@pytest.fixture(scope="session", autouse=True) +def mock_mtls_env(): + """Autouse session-scoped fixture to isolate unit tests from workstation mTLS environments.""" + with mock.patch.dict( + os.environ, + { + "GOOGLE_API_USE_CLIENT_CERTIFICATE": "false", + "CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE": "false", + }, + ): + yield diff --git a/packages/google-api-core/tests/unit/gapic/test_client_utils.py b/packages/google-api-core/tests/unit/gapic/test_client_utils.py new file mode 100644 index 000000000000..a34cb9998b4d --- /dev/null +++ b/packages/google-api-core/tests/unit/gapic/test_client_utils.py @@ -0,0 +1,20 @@ +# 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. + +from google.api_core.gapic_v1 import client_utils +from google.api_core import universe + + +def test_exports(): + assert client_utils.get_universe_domain is universe.get_universe_domain From 417133d2a24295099fe06b7308cf1d8f8cf8d496 Mon Sep 17 00:00:00 2001 From: Heba Alazzeh Date: Tue, 21 Jul 2026 20:47:18 +0000 Subject: [PATCH 2/2] chore: address review comments --- .../google/api_core/gapic_v1/__init__.py | 4 +--- .../google/api_core/gapic_v1/client_utils.py | 24 ------------------- packages/google-api-core/tests/conftest.py | 1 - .../tests/unit/gapic/test_client_utils.py | 20 ---------------- 4 files changed, 1 insertion(+), 48 deletions(-) delete mode 100644 packages/google-api-core/google/api_core/gapic_v1/client_utils.py delete mode 100644 packages/google-api-core/tests/unit/gapic/test_client_utils.py diff --git a/packages/google-api-core/google/api_core/gapic_v1/__init__.py b/packages/google-api-core/google/api_core/gapic_v1/__init__.py index aaebf2ba9e8e..0d7e53b54c5e 100644 --- a/packages/google-api-core/google/api_core/gapic_v1/__init__.py +++ b/packages/google-api-core/google/api_core/gapic_v1/__init__.py @@ -25,11 +25,10 @@ # Older Python versions safely ignore this variable. __lazy_modules__: Set[str] = { "google.api_core.gapic_v1.client_info", - "google.api_core.gapic_v1.client_utils", "google.api_core.gapic_v1.requests", "google.api_core.gapic_v1.routing_header", } -__all__ = ["client_info", "client_utils", "requests", "routing_header"] +__all__ = ["client_info", "requests", "routing_header"] if _has_grpc: @@ -44,7 +43,6 @@ from google.api_core.gapic_v1 import ( # noqa: E402 client_info, - client_utils, requests, routing_header, ) diff --git a/packages/google-api-core/google/api_core/gapic_v1/client_utils.py b/packages/google-api-core/google/api_core/gapic_v1/client_utils.py deleted file mode 100644 index ec26bc0d793f..000000000000 --- a/packages/google-api-core/google/api_core/gapic_v1/client_utils.py +++ /dev/null @@ -1,24 +0,0 @@ -# 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. -# - -"""Helpers for client setup and configuration.""" - -from google.api_core.universe import ( - get_universe_domain, -) - -__all__ = [ - "get_universe_domain", -] diff --git a/packages/google-api-core/tests/conftest.py b/packages/google-api-core/tests/conftest.py index 62a3c999f733..ffa69d61f1a2 100644 --- a/packages/google-api-core/tests/conftest.py +++ b/packages/google-api-core/tests/conftest.py @@ -25,7 +25,6 @@ def mock_mtls_env(): os.environ, { "GOOGLE_API_USE_CLIENT_CERTIFICATE": "false", - "CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE": "false", }, ): yield diff --git a/packages/google-api-core/tests/unit/gapic/test_client_utils.py b/packages/google-api-core/tests/unit/gapic/test_client_utils.py deleted file mode 100644 index a34cb9998b4d..000000000000 --- a/packages/google-api-core/tests/unit/gapic/test_client_utils.py +++ /dev/null @@ -1,20 +0,0 @@ -# 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. - -from google.api_core.gapic_v1 import client_utils -from google.api_core import universe - - -def test_exports(): - assert client_utils.get_universe_domain is universe.get_universe_domain