Skip to content

Commit 0b5c1d5

Browse files
authored
feat: support universe resolution (#1774)
* feat: support universe resolution This PR wires up consumption of the universe_domain client option for resolving the endpoint for constructing the BQ client. Testing universes is not yet something we want to in this repo, so validation was done out of band. * formatting and testing * conditionals for stale core * formatting * unused import
1 parent cf920f4 commit 0b5c1d5

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

google/cloud/bigquery/_helpers.py

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
_DEFAULT_HOST = "https://bigquery.googleapis.com"
5656
"""Default host for JSON API."""
5757

58+
_DEFAULT_UNIVERSE = "googleapis.com"
59+
"""Default universe for the JSON API."""
60+
5861

5962
def _get_bigquery_host():
6063
return os.environ.get(BIGQUERY_EMULATOR_HOST, _DEFAULT_HOST)

google/cloud/bigquery/client.py

+9
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
from google.cloud.bigquery._helpers import _verify_job_config_type
7979
from google.cloud.bigquery._helpers import _get_bigquery_host
8080
from google.cloud.bigquery._helpers import _DEFAULT_HOST
81+
from google.cloud.bigquery._helpers import _DEFAULT_UNIVERSE
8182
from google.cloud.bigquery._job_helpers import make_job_id as _make_job_id
8283
from google.cloud.bigquery.dataset import Dataset
8384
from google.cloud.bigquery.dataset import DatasetListItem
@@ -252,6 +253,14 @@ def __init__(
252253
if client_options.api_endpoint:
253254
api_endpoint = client_options.api_endpoint
254255
kw_args["api_endpoint"] = api_endpoint
256+
elif (
257+
hasattr(client_options, "universe_domain")
258+
and client_options.universe_domain
259+
and client_options.universe_domain is not _DEFAULT_UNIVERSE
260+
):
261+
kw_args["api_endpoint"] = _DEFAULT_HOST.replace(
262+
_DEFAULT_UNIVERSE, client_options.universe_domain
263+
)
255264

256265
self._connection = Connection(self, **kw_args)
257266
self._location = location

tests/unit/test_client.py

+17
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,23 @@ def test_ctor_w_client_options_object(self):
201201
client._connection.API_BASE_URL, "https://www.foo-googleapis.com"
202202
)
203203

204+
@pytest.mark.skipif(
205+
packaging.version.parse(getattr(google.api_core, "__version__", "0.0.0"))
206+
< packaging.version.Version("2.15.0"),
207+
reason="universe_domain not supported with google-api-core < 2.15.0",
208+
)
209+
def test_ctor_w_client_options_universe(self):
210+
creds = _make_credentials()
211+
http = object()
212+
client_options = {"universe_domain": "foo.com"}
213+
client = self._make_one(
214+
project=self.PROJECT,
215+
credentials=creds,
216+
_http=http,
217+
client_options=client_options,
218+
)
219+
self.assertEqual(client._connection.API_BASE_URL, "https://bigquery.foo.com")
220+
204221
def test_ctor_w_location(self):
205222
from google.cloud.bigquery._http import Connection
206223

0 commit comments

Comments
 (0)