Skip to content
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

Add support for the GCLOUD_PROJECT environment variable #73

Merged
merged 1 commit into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion google/auth/_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ def default(request=None):
If no credentials were found, or if the credentials found were
invalid.
"""
explicit_project_id = os.environ.get(environment_vars.PROJECT)
explicit_project_id = os.environ.get(

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

environment_vars.PROJECT,
os.environ.get(environment_vars.LEGACY_PROJECT))

checkers = (
_get_explicit_environ_credentials,
Expand Down
7 changes: 7 additions & 0 deletions google/auth/environment_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
environment variable is also used by the Google Cloud Python Library.
"""

LEGACY_PROJECT = 'GCLOUD_PROJECT'
"""Previously used environment variable defining the default project.

This environment variable is used instead of the current one in some
situations (such as Google App Engine).
"""

CREDENTIALS = 'GOOGLE_APPLICATION_CREDENTIALS'
"""Environment variable defining the location of Google application default
credentials."""
Expand Down
9 changes: 9 additions & 0 deletions tests/test__default.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ def test_default_explict_project_id(get_mock, monkeypatch):
mock.sentinel.credentials, 'explicit-env')


@mock.patch(
'google.auth._default._get_explicit_environ_credentials',
return_value=(mock.sentinel.credentials, mock.sentinel.project_id))
def test_default_explict_legacy_project_id(get_mock, monkeypatch):
monkeypatch.setenv(environment_vars.LEGACY_PROJECT, 'explicit-env')
assert _default.default() == (
mock.sentinel.credentials, 'explicit-env')


@mock.patch(
'google.auth._default._get_explicit_environ_credentials',
return_value=(None, None))
Expand Down