perf: avoid re-authenticating if credentials have already been fetched#2058
perf: avoid re-authenticating if credentials have already been fetched#2058
Conversation
…nto b443753087-global-credentials
| ) | ||
|
|
||
| # Ensure an access token is available. | ||
| _cached_credentials.refresh(google.auth.transport.requests.Request()) |
There was a problem hiding this comment.
If the cached credentials is failed to refresh (e.g. expired), should we reload another new credentials?
There was a problem hiding this comment.
Reloading generally wouldn't help. Refreshing is just exchanging a refresh token (generally long lived) for an access token (short-lived, default 1 hour, I think).
There was a problem hiding this comment.
This step shouldn't actually be necessary. I think it was added for the sole reason of having tests that check if a credential is "valid", which I don't think is populated until after the first refresh.
| """ | ||
| return self._credentials | ||
| if self._credentials: | ||
| return self._credentials |
There was a problem hiding this comment.
I am not sure how the bigquery recycles the credentials. If it's recycled by the expired time, do we need to refresh the credentials whenever we are fetching them?
There was a problem hiding this comment.
google-auth will automatically refresh the credentials when they are expired.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes internal issue b/443753087 🦕