GoogleCloudPlatform / alloydb-python-connector

A Python library for connecting securely to your AlloyDB instances.
Apache License 2.0
28 stars 7 forks source link

Replace`credentials.valid` check for `credentials.token_state` #286

Closed jackwotherspoon closed 4 months ago

jackwotherspoon commented 6 months ago

New best practice for checking validity of credentials is no longer credentials.valid which is now deprecated (as of google-auth v2.24.0). Instead the google-auth folks recommend using credentials.token_state

All instances of the following: https://github.com/GoogleCloudPlatform/alloydb-python-connector/blob/473f4abbe8e7524c56bd530f13294283a6b4cbcf/google/cloud/alloydb/connector/client.py#L164-L166

Should be replaced to:

from google.auth.credentials import TokenState

# ...
if not self._credentials.token_state == TokenState.FRESH:
    self._credentials.refresh(google.auth.transport.requests.Request())
jackwotherspoon commented 4 months ago

see https://github.com/GoogleCloudPlatform/cloud-sql-python-connector/pull/1089