Skip to content

Commit

Permalink
Add support for the GCLOUD_PROJECT environment variable (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott authored Nov 8, 2016
1 parent cadec89 commit ce37cba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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(
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

0 comments on commit ce37cba

Please sign in to comment.