Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 6458f5a

Browse files
committed
Fix minor issues
1 parent 2d69358 commit 6458f5a

7 files changed

Lines changed: 35 additions & 6 deletions

File tree

google/auth/_regional_access_boundary_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import datetime
44
import threading
55

6+
import logging
7+
68
from google.auth import _helpers
7-
from google.auth._default import _LOGGER
9+
10+
_LOGGER = logging.getLogger(__name__)
811

912

1013
# The default lifetime for a cached Regional Access Boundary.

google/auth/compute_engine/credentials.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def with_scopes(self, scopes, default_scopes=None):
242242
def with_universe_domain(self, universe_domain):
243243
creds = self._make_copy()
244244
creds._universe_domain = universe_domain
245+
creds._universe_domain_cached = True
245246
return creds
246247

247248

google/auth/external_account.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ def with_scopes(self, scopes, default_scopes=None):
348348
scoped = self.__class__(**kwargs)
349349
scoped._cred_file_path = self._cred_file_path
350350
scoped._metrics_options = self._metrics_options
351+
self._copy_regional_access_boundary_state(scoped)
351352
return scoped
352353

353354
@abc.abstractmethod
@@ -505,7 +506,11 @@ def _build_regional_access_boundary_lookup_url(self):
505506
return url
506507
else:
507508
# If both fail, the audience format is invalid.
508-
raise exceptions.InvalidValue("Invalid audience format.")
509+
_LOGGER.error(
510+
"Invalid audience format for Regional Access Boundary lookup: %s",
511+
self._audience,
512+
)
513+
return None
509514

510515
def _make_copy(self):
511516
kwargs = self._constructor_args()

google/oauth2/_service_account_async.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ async def refresh(self, request):
7777

7878
@_helpers.copy_docstring(credentials_async.Credentials)
7979
async def before_request(self, request, method, url, headers):
80+
# Explicit override to bypass synchronous CredentialsWithRegionalAccessBoundary.
8081
await credentials_async.Credentials.before_request(
8182
self, request, method, url, headers
8283
)
83-
self._maybe_start_regional_access_boundary_refresh(request, url)
8484

8585

8686
class IDTokenCredentials(
@@ -137,3 +137,11 @@ async def refresh(self, request):
137137
)
138138
self.token = access_token
139139
self.expiry = expiry
140+
141+
@_helpers.copy_docstring(credentials_async.Credentials)
142+
async def before_request(self, request, method, url, headers):
143+
# Explicit override to bypass synchronous CredentialsWithRegionalAccessBoundary
144+
# and disable Regional Access Boundary refresh for async credentials.
145+
await credentials_async.Credentials.before_request(
146+
self, request, method, url, headers
147+
)

tests/oauth2/test__client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ def test_lookup_regional_access_boundary_non_retryable_error(status_code):
699699
# Non-retryable errors should only be called once.
700700
mock_request.assert_called_once_with(method="GET", url=url, headers=headers)
701701

702+
702703
def test_lookup_regional_access_boundary_internal_failure_and_retry_failure_error():
703704
retryable_error = mock.create_autospec(transport.Response, instance=True)
704705
retryable_error.status = http_client.BAD_REQUEST

tests/oauth2/test_service_account.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ def test_build_regional_access_boundary_lookup_url(self):
242242
credentials = self.make_credentials()
243243
expected_url = (
244244
"https://iamcredentials.googleapis.com/v1/projects/-/"
245-
"serviceAccounts/{}/allowedLocations".format(credentials.service_account_email)
245+
"serviceAccounts/{}/allowedLocations".format(
246+
credentials.service_account_email
247+
)
246248
)
247249
assert credentials._build_regional_access_boundary_lookup_url() == expected_url
248250

tests/test_external_account.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,16 @@ def test_with_scopes(self):
351351
assert scoped_credentials.has_scopes(["email"])
352352
assert not scoped_credentials.requires_scopes
353353

354+
def test_with_scopes_copies_regional_access_boundary(self):
355+
credentials = self.make_credentials()
356+
credentials = credentials._with_regional_access_boundary(
357+
self.VALID_TRUST_BOUNDARY
358+
)
359+
scoped_credentials = credentials.with_scopes(["email"])
360+
361+
assert scoped_credentials.has_scopes(["email"])
362+
assert scoped_credentials._regional_access_boundary == self.VALID_TRUST_BOUNDARY
363+
354364
def test_with_scopes_workforce_pool(self):
355365
credentials = self.make_workforce_pool_credentials(
356366
workforce_pool_user_project=self.WORKFORCE_POOL_USER_PROJECT
@@ -1750,8 +1760,7 @@ def test_build_regional_access_boundary_lookup_url_workforce(self):
17501760
def test_build_regional_access_boundary_lookup_url_invalid_audience(self, audience):
17511761
credentials = self.make_credentials()
17521762
credentials._audience = audience
1753-
with pytest.raises(exceptions.InvalidValue, match="Invalid audience format."):
1754-
credentials._build_regional_access_boundary_lookup_url()
1763+
assert credentials._build_regional_access_boundary_lookup_url() is None
17551764

17561765
def test_with_regional_access_boundary(self):
17571766
credentials = self.make_credentials()

0 commit comments

Comments
 (0)