fix(translate-v2): Ensure access token is fetched with recent googleauth versions in the non-api-key case #28096
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This may address googleapis/google-auth-library-ruby#504. It also addresses some integration test failures related to the translate-v2 client.
Older versions of googleauth (prior to 0.11 or 0.12) eagerly fetched access tokens for some credential types. This could cause issues in environments where the service providing the tokens were slow to initialize. It also did extra work by fetching a token prematurely if the credential was never used or was delayed in its use, and would cause confusion when troubleshooting auth via logs use because the token fetch would be significantly separated from its use.
This eager pre-fetching was removed in more recent versions of googleauth, but it looks like the translate-v2 client was depending on the old behavior: its logic failed ever to fetch a token if no previous token (and thus no expiration date) was already present. This PR updates the translate-v2 client logic to ensure a token is fetched if not present at all.