Skip to content

Commit

Permalink
fix: fix vm universe_domain bug (#1433)
Browse files Browse the repository at this point in the history
  • Loading branch information
arithmetic1728 committed Dec 6, 2023
1 parent b6b2b2c commit 8683520
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion google/auth/compute_engine/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from google.auth import jwt
from google.auth import metrics
from google.auth.compute_engine import _metadata
from google.auth.transport import requests as google_auth_requests
from google.oauth2 import _client


Expand Down Expand Up @@ -74,6 +75,7 @@ def __init__(
self._scopes = scopes
self._default_scopes = default_scopes
self._universe_domain_cached = False
self._universe_domain_request = google_auth_requests.Request()

def _retrieve_info(self, request):
"""Retrieve information about the service account.
Expand Down Expand Up @@ -136,7 +138,9 @@ def requires_scopes(self):
def universe_domain(self):
if self._universe_domain_cached:
return self._universe_domain
self._universe_domain = _metadata.get_universe_domain()
self._universe_domain = _metadata.get_universe_domain(
self._universe_domain_request
)
self._universe_domain_cached = True
return self._universe_domain

Expand Down
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
8 changes: 6 additions & 2 deletions tests/compute_engine/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,16 @@ def test_universe_domain(self, get_universe_domain):
assert self.credentials.universe_domain == "fake_universe_domain"
assert self.credentials._universe_domain == "fake_universe_domain"
assert self.credentials._universe_domain_cached
get_universe_domain.assert_called_once()
get_universe_domain.assert_called_once_with(
self.credentials._universe_domain_request
)

# calling the universe_domain property the second time should use the
# cached value instead of calling get_universe_domain
assert self.credentials.universe_domain == "fake_universe_domain"
get_universe_domain.assert_called_once()
get_universe_domain.assert_called_once_with(
self.credentials._universe_domain_request
)


class TestIDTokenCredentials(object):
Expand Down

0 comments on commit 8683520

Please sign in to comment.