in utils/fix-audio-encoding/convert_from_gcs.py [0:0]
def _GetClientCredentials(impersonated_service_account):
"""Gets client credentials for GCP requests.
If an account to impersonate is provided, then it will be used rather than the
default. Otherwise, default gcloud credentials will be used.
Args:
impersonated_service_account: The service account to impersonate.
Returns:
A credential for requests to GCP.
"""
creds, _ = google.auth.default(
scopes=['https://www.googleapis.com/auth/cloud-platform']
)
if not impersonated_service_account:
return creds
target_scopes = ['https://www.googleapis.com/auth/cloud-platform']
target_credentials = impersonated_credentials.Credentials(
source_credentials=creds,
target_principal=impersonated_service_account,
target_scopes=target_scopes,
lifetime=3600,
)
# Override the source credentials so refresh will work.
# See https://github.com/googleapis/google-auth-library-python/issues/416.
# pylint: disable=protected-access
target_credentials._source_credentials._scopes = creds.scopes
return target_credentials