Skip to content

Commit 9bb64c8

Browse files
fix: make requests import conditional for gce universe domain (#1476)
* fix: make requests import conditional for gce universe domain * remove if for creating request object * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 30743b0 commit 9bb64c8

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

google/auth/compute_engine/credentials.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from google.auth import jwt
2929
from google.auth import metrics
3030
from google.auth.compute_engine import _metadata
31-
from google.auth.transport import requests as google_auth_requests
3231
from google.oauth2 import _client
3332

3433

@@ -84,7 +83,6 @@ def __init__(
8483
self._scopes = scopes
8584
self._default_scopes = default_scopes
8685
self._universe_domain_cached = False
87-
self._universe_domain_request = google_auth_requests.Request()
8886
if universe_domain:
8987
self._universe_domain = universe_domain
9088
self._universe_domain_cached = True
@@ -150,8 +148,11 @@ def requires_scopes(self):
150148
def universe_domain(self):
151149
if self._universe_domain_cached:
152150
return self._universe_domain
151+
152+
from google.auth.transport import requests as google_auth_requests
153+
153154
self._universe_domain = _metadata.get_universe_domain(
154-
self._universe_domain_request
155+
google_auth_requests.Request()
155156
)
156157
self._universe_domain_cached = True
157158
return self._universe_domain

tests/compute_engine/test_credentials.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,12 @@ def test_universe_domain(self, get_universe_domain):
257257
assert self.credentials.universe_domain == "fake_universe_domain"
258258
assert self.credentials._universe_domain == "fake_universe_domain"
259259
assert self.credentials._universe_domain_cached
260-
get_universe_domain.assert_called_once_with(
261-
self.credentials._universe_domain_request
262-
)
260+
get_universe_domain.assert_called_once()
263261

264262
# calling the universe_domain property the second time should use the
265263
# cached value instead of calling get_universe_domain
266264
assert self.credentials.universe_domain == "fake_universe_domain"
267-
get_universe_domain.assert_called_once_with(
268-
self.credentials._universe_domain_request
269-
)
265+
get_universe_domain.assert_called_once()
270266

271267
@mock.patch("google.auth.compute_engine._metadata.get_universe_domain")
272268
def test_user_provided_universe_domain(self, get_universe_domain):

0 commit comments

Comments
 (0)