From afea6f8f916d8eaebbf97f238c17e63c794d43ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Armando=20Garc=C3=ADa=20Sancio?= Date: Thu, 28 May 2015 04:12:24 -0700 Subject: [PATCH] DCOS-1521 Fix OAuth wording --- cli/tests/integrations/cli/test_auth.py | 24 +++++++++++------- dcos/auth.py | 33 ++++++++++++++----------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/cli/tests/integrations/cli/test_auth.py b/cli/tests/integrations/cli/test_auth.py index 2493cc8f1..64813b51a 100644 --- a/cli/tests/integrations/cli/test_auth.py +++ b/cli/tests/integrations/cli/test_auth.py @@ -22,9 +22,8 @@ def test_when_authenticated(): def test_anonymous_login(): - with patch('six.moves.input', - return_value=''), patch('uuid.uuid1', - return_value='anonymous@email'): + with patch('sys.stdin.readline', return_value='\n'), \ + patch('uuid.uuid1', return_value='anonymous@email'): assert _mock_dcos_run([util.which('dcos'), 'help'], False) == 0 @@ -35,17 +34,24 @@ def test_anonymous_login(): def _mock_dcos_run(args, authenticated=True): - env = _config_with_credentials() if authenticated else \ - _config_without_credentials() + if authenticated: + env = _config_with_credentials() + else: + env = _config_without_credentials() + with patch('sys.argv', args), patch.dict(os.environ, env): return main() def _config_with_credentials(): - return {constants.DCOS_CONFIG_ENV: os.path.join( - 'tests', 'data', 'auth', 'dcos_with_credentials.toml')} + return { + constants.DCOS_CONFIG_ENV: os.path.join( + 'tests', 'data', 'auth', 'dcos_with_credentials.toml') + } def _config_without_credentials(): - return {constants.DCOS_CONFIG_ENV: os.path.join( - 'tests', 'data', 'auth', 'dcos_without_credentials.toml')} + return { + constants.DCOS_CONFIG_ENV: os.path.join( + 'tests', 'data', 'auth', 'dcos_without_credentials.toml') + } diff --git a/dcos/auth.py b/dcos/auth.py index e2714a352..6a29c41ef 100644 --- a/dcos/auth.py +++ b/dcos/auth.py @@ -1,12 +1,13 @@ import json import os +import sys import uuid import pkg_resources import toml from dcos import config, constants, emitting, errors, http, jsonitem, util from dcos.errors import DCOSException -from six import iteritems, moves +from six import iteritems from oauth2client import client @@ -69,29 +70,31 @@ def _run(flow): :rtype: dict """ - auth_url = flow.step1_get_authorize_url() - message = """Thank you for installing the Mesosphere DCOS CLI. -Please log in with your Mesosphere Account by pasting -the following URL into your browser to continue.""" - emitter.publish(errors.DefaultError( - '{message}\n\n {url}\n\n'.format(message=message, - url=auth_url,))) + emitter.publish( + errors.DefaultError( + '\n\n\n{}\n\n {}\n\n'.format( + 'Go to the following link in your browser:', + flow.step1_get_authorize_url()))) - code = moves.input('Please enter Mesosphere verification code: ').strip() + sys.stderr.write('Enter verification code: ') + code = sys.stdin.readline().strip() if not code: - email = moves.input('Skipping authentication.' - ' Please enter email address:').strip() + sys.stderr.write('Skipping authentication.\nEnter email address: ') + + email = sys.stdin.readline().strip() if not email: - emitter.publish(errors.DefaultError('Skipping email input,' - ' using anonymous id:')) + emitter.publish( + errors.DefaultError( + 'Skipping email input.')) email = str(uuid.uuid1()) + return {CORE_EMAIL_KEY: email} return make_oauth_request(code, flow) def check_if_user_authenticated(): - """ check if user is authenticated already + """Check if user is authenticated already :returns user auth status :rtype: boolean @@ -102,7 +105,7 @@ def check_if_user_authenticated(): def force_auth(): - """ Make user authentication process + """Make user authentication process :returns authentication process status :rtype: boolean