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

Commit 21196fd

Browse files
committed
Remove manual override and reactie reftesh
1 parent e482e53 commit 21196fd

6 files changed

Lines changed: 15 additions & 82 deletions

File tree

google/auth/credentials.py

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def with_universe_domain(self, universe_domain):
294294

295295

296296
class CredentialsWithRegionalAccessBoundary(Credentials):
297-
"""Abstract base for credentials supporting ``with_regional_access_boundary`` factory"""
297+
"""Abstract base for credentials supporting regional access boundary configuration."""
298298

299299
def __init__(self, *args, **kwargs):
300300
super(CredentialsWithRegionalAccessBoundary, self).__init__(*args, **kwargs)
@@ -323,28 +323,16 @@ def _perform_refresh_token(self, request):
323323
"""
324324
raise NotImplementedError("_perform_refresh_token must be implemented")
325325

326-
def with_regional_access_boundary(self, regional_access_boundary):
326+
def _with_regional_access_boundary(self, regional_access_boundary):
327327
"""Returns a copy of these credentials with a modified Regional Access Boundary.
328-
329-
This method allows for manually providing the Regional Access Boundary
330-
information, which will be cached with a 6-hour lifetime. This bypasses
331-
the initial asynchronous lookup. After the cache expires, the library
332-
will trigger a background refresh on the next request.
333-
328+
This is an internal method used by credential factory methods (e.g., from_info)
329+
to seed the RAB cache. The provided value is cached with the default TTL.
334330
Args:
335-
regional_access_boundary (Mapping[str, str]): The Regional Access Boundary
336-
to use for the credential. This should be a map with an
337-
"encodedLocations" key that maps to a hex string. Optionally,
338-
it can also contain a "locations" key with a list of GCP regions.
339-
Example: `{"locations": ["us-central1"], "encodedLocations": "0xA30"}`
340-
331+
regional_access_boundary (dict): Must contain an "encodedLocations" key.
341332
Returns:
342-
google.auth.credentials.Credentials: A new credentials instance
343-
with the specified Regional Access Boundary.
344-
333+
google.auth.credentials.Credentials: A new credentials instance.
345334
Raises:
346-
google.auth.exceptions.InvalidValue: If `regional_access_boundary`
347-
is not a dictionary or does not contain the "encodedLocations" key.
335+
google.auth.exceptions.InvalidValue: If the input is malformed.
348336
"""
349337
if (
350338
not isinstance(regional_access_boundary, dict)
@@ -377,28 +365,6 @@ def _copy_regional_access_boundary_state(self, target):
377365
# Create a new lock for the target instance to ensure independent thread-safety.
378366
target._stale_boundary_lock = threading.Lock()
379367

380-
def handle_stale_regional_access_boundary(self, request):
381-
"""Handles a stale regional access boundary error.
382-
This method is thread-safe and will only initiate a single refresh
383-
even if called concurrently.
384-
Args:
385-
request (google.auth.transport.Request): The object used to make
386-
HTTP requests.
387-
"""
388-
with self._stale_boundary_lock:
389-
# Another thread might have already handled the stale boundary.
390-
if self._regional_access_boundary is None:
391-
return
392-
393-
_LOGGER.info("Stale regional access boundary detected. Refreshing.")
394-
395-
# Clear the cached boundary.
396-
self._regional_access_boundary = None
397-
self._regional_access_boundary_expiry = None
398-
399-
# Start the background refresh.
400-
self._regional_access_boundary_refresh_manager.start_refresh(self, request)
401-
402368
def _maybe_start_regional_access_boundary_refresh(self, request, url):
403369
"""
404370
Starts a background thread to refresh the Regional Access Boundary if needed.

google/auth/external_account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ def from_info(cls, info, **kwargs):
675675

676676
regional_access_boundary = info.get("regional_access_boundary")
677677
if regional_access_boundary:
678-
initial_creds = initial_creds.with_regional_access_boundary(
678+
initial_creds = initial_creds._with_regional_access_boundary(
679679
regional_access_boundary
680680
)
681681

google/auth/external_account_authorized_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def from_info(cls, info, **kwargs):
441441

442442
regional_access_boundary = info.get("regional_access_boundary")
443443
if regional_access_boundary:
444-
initial_creds = initial_creds.with_regional_access_boundary(
444+
initial_creds = initial_creds._with_regional_access_boundary(
445445
regional_access_boundary
446446
)
447447

google/auth/impersonated_credentials.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,10 @@ def _build_regional_access_boundary_lookup_url(self):
360360
"Service account email is required to build the Regional Access Boundary lookup URL for impersonated credentials."
361361
)
362362
return None
363-
return _constants._SERVICE_ACCOUNT_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENDPOINT.format(
364-
service_account_email=self.service_account_email
363+
return (
364+
_constants._SERVICE_ACCOUNT_REGIONAL_ACCESS_BOUNDARY_LOOKUP_ENDPOINT.format(
365+
service_account_email=self.service_account_email
366+
)
365367
)
366368

367369
def sign_bytes(self, message):
@@ -530,7 +532,7 @@ def from_impersonated_service_account_info(cls, info, scopes=None):
530532

531533
regional_access_boundary = info.get("regional_access_boundary")
532534
if regional_access_boundary:
533-
initial_creds = initial_creds.with_regional_access_boundary(
535+
initial_creds = initial_creds._with_regional_access_boundary(
534536
regional_access_boundary
535537
)
536538

google/auth/transport/requests.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,6 @@ def configure_mtls_channel(self, client_cert_callback=None):
476476
new_exc = exceptions.MutualTLSChannelError(caught_exc)
477477
raise new_exc from caught_exc
478478

479-
def _is_stale_regional_access_boundary_error(self, response):
480-
"""Checks if the response indicates a stale regional access boundary."""
481-
if response.status_code != 406:
482-
return False
483-
484-
try:
485-
# The response data is bytes, decode it to a string.
486-
response_text = response.content.decode("utf-8")
487-
return "stale regional access boundary" in response_text.lower()
488-
except (UnicodeDecodeError, AttributeError):
489-
return False
490-
491479
def request(
492480
self,
493481
method,
@@ -531,7 +519,6 @@ def request(
531519
# Use a kwarg for this instead of an attribute to maintain
532520
# thread-safety.
533521
_credential_refresh_attempt = kwargs.pop("_credential_refresh_attempt", 0)
534-
_stale_boundary_retried = kwargs.pop("_stale_boundary_retried", False)
535522

536523
# Make a copy of the headers. They will be modified by the credentials
537524
# and we want to pass the original headers if we recurse.
@@ -634,28 +621,6 @@ def request(
634621
**kwargs
635622
)
636623

637-
# If the response indicated a stale regional access boundary, clear the
638-
# cached boundary and re-attempt the request. This is only done once.
639-
if (
640-
self._is_stale_regional_access_boundary_error(response)
641-
and not _stale_boundary_retried
642-
):
643-
_LOGGER.info(
644-
"Stale regional access boundary detected, clearing and retrying."
645-
)
646-
self.credentials.handle_stale_regional_access_boundary(auth_request)
647-
# Recurse, passing in the original headers and marking that we have retried.
648-
return self.request(
649-
method,
650-
url,
651-
data=data,
652-
headers=headers,
653-
max_allowed_time=remaining_time,
654-
timeout=timeout,
655-
_stale_boundary_retried=True,
656-
**kwargs
657-
)
658-
659624
return response
660625

661626
@property

google/oauth2/service_account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def _from_signer_and_info(cls, signer, info, **kwargs):
227227
)
228228
regional_access_boundary = info.get("regional_access_boundary")
229229
if regional_access_boundary:
230-
initial_creds = initial_creds.with_regional_access_boundary(
230+
initial_creds = initial_creds._with_regional_access_boundary(
231231
regional_access_boundary
232232
)
233233
return initial_creds

0 commit comments

Comments
 (0)