Skip to content

Commit 9101a32

Browse files
committed
Adding more user-friendly error when filename missing for user creds.
1 parent ca14078 commit 9101a32

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

gcloud/credentials.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ def get_credentials_from_user_flow(scope, client_secrets_file=None):
137137
138138
:rtype: :class:`oauth2client.client.OAuth2Credentials`
139139
:returns: A new credentials instance.
140-
:raises: ``EnvironmentError`` if stdout is not a TTY or
140+
:raises: ``EnvironmentError`` if stdout is not a TTY,
141+
``ValueError`` if ``client_secrets_file`` is not passed in as an
142+
argument or set as an environment variable, or
141143
``ValueError`` if the client secrets file is not for an installed
142-
application
144+
application.
143145
"""
144146
if not sys.stdout.isatty():
145147
raise EnvironmentError('Cannot initiate user flow unless user can '
@@ -148,6 +150,9 @@ def get_credentials_from_user_flow(scope, client_secrets_file=None):
148150
if client_secrets_file is None:
149151
client_secrets_file = os.getenv('GCLOUD_CLIENT_SECRETS')
150152

153+
if client_secrets_file is None:
154+
raise ValueError('Client secrets file not specified.')
155+
151156
client_type, client_info = client.clientsecrets.loadfile(
152157
client_secrets_file)
153158
if client_type != client.clientsecrets.TYPE_INSTALLED:

gcloud/test_credentials.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ def test_no_tty(self):
147147
with self.assertRaises(EnvironmentError):
148148
self._callFUT(None)
149149

150+
def test_no_filename(self):
151+
import sys
152+
153+
from gcloud._testing import _Monkey
154+
from oauth2client import client
155+
156+
STDOUT = _MockStdout(isatty=True)
157+
with _Monkey(sys, stdout=STDOUT):
158+
with self.assertRaises(ValueError):
159+
self._callFUT(None)
160+
150161
def test_filename_from_environ(self):
151162
import os
152163
import sys

0 commit comments

Comments
 (0)