Skip to content

Commit

Permalink
add logs to refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-sunder-s committed Sep 20, 2022
1 parent d65e7b5 commit 0d2611d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions google/auth/compute_engine/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""

import datetime
import logging

import six

Expand All @@ -31,6 +32,8 @@
from google.auth.compute_engine import _metadata
from google.oauth2 import _client

_LOGGER = logging.getLogger(__name__)


class Credentials(credentials.Scoped, credentials.CredentialsWithQuotaProject):
"""Compute Engine Credentials.
Expand Down Expand Up @@ -107,12 +110,19 @@ def refresh(self, request):
credentials.
"""
scopes = self._scopes if self._scopes is not None else self._default_scopes
_LOGGER.info(
"Refreshing access token."
)

try:
self._retrieve_info(request)
self.token, self.expiry = _metadata.get_service_account_token(
request, service_account=self._service_account_email, scopes=scopes
)
except exceptions.TransportError as caught_exc:
_LOGGER.error(
f"Caught exception when refreshing access token. {caught_exc}"
)
new_exc = exceptions.RefreshError(caught_exc)
six.raise_from(new_exc, caught_exc)

Expand Down
2 changes: 1 addition & 1 deletion google/auth/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def apply(self, headers, token=None):
_helpers.from_bytes(token or self.token)
)

close_to_expiry = self.expiry - datetime.timedelta(seconds=3000)
close_to_expiry = self.expiry - datetime.timedelta(seconds=600)
if _helpers.utcnow() >= close_to_expiry:
_LOGGER.debug("Attached token with expiry:{} at {}".format(self.expiry, _helpers.utcnow()))

Expand Down

0 comments on commit 0d2611d

Please sign in to comment.