def _GetApplicationDefaultCredentials(scopes):
# There's a complication here: if the application default
# credential returned to us is the token from the cloud SDK,
# we need to ensure that our scopes are a subset of those
# requested. In principle, we're a bit too strict here: eg if
# a user requests just "bigquery", then the cloud-platform
# scope suffices, but there's no programmatic way to check
# this -- so we instead fail here.
try:
credentials = client.GoogleCredentials.get_application_default()
except client.ApplicationDefaultCredentialsError:
return None
if credentials is not None:
if not credentials.create_scoped_required():
return credentials
if set(scopes) <= _GCLOUD_SCOPES:
return credentials.create_scoped(scopes)
评论列表
文章目录