-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infer project from credentials if not passed explicitly #27
Comments
In the case where credentials are discovered for us, $ unset GOOGLE_CLOUD_PROJECT GCLOUD_PROJECT
$ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
$ grep project_id /path/to/service_account.json
"project_id": "some-project-123"
$ python
>>> from google.auth import default
>>> credentials, project = default()
>>> project
'some-project-123'
>>> from google.cloud.client import ClientWithProject
>>> client = ClientWithProject()
>>> client.project
'some-project-123' So, the case we need to cover for this feature is when the user has passed in explicit service account credentials, but not an explicit project ID, e.g. (this won't currently work): $ unset GOOGLE_CLOUD_PROJECT GCLOUD_PROJECT GOOGLE_APPLICATION_CREDENTIALS
$ python
>>> from google.oauth2.service_account import Credentials
>>> credentials = Credentials.from_service_account_file("/path/to/service_account.json")
>>> from google.cloud.client import ClientWithProject
>>> client = ClientWithProject(credentials=credentials) # currently raises |
Closes #27 Co-authored-by: Christopher Wilcox <crwilcox@google.com>
python-cloud-core/google/cloud/client/__init__.py Lines 252 to 260 in e5fb3ea
Update: I just did some testing and confirmed it is supported. Not sure what sort of heisenbug I was observing! |
Split off from #17
See also: googleapis/python-datastore#74
See also: googleapis/python-storage#177
In a "blank slate" design, I would argue that the credentials' project should supersede the one present in the environment. However, for backward compatibility, we need to use the credentials' project only if the environment variable is not set. So the order should follow the pattern from
google.auth.default
when inferring project ID:GOOGLE_CLOUD_PROJECT
envvarThe text was updated successfully, but these errors were encountered: