diff --git a/mistralclient/shell.py b/mistralclient/shell.py index 9abbda60..ee99e998 100644 --- a/mistralclient/shell.py +++ b/mistralclient/shell.py @@ -31,6 +31,7 @@ import mistralclient.commands.v2.services import mistralclient.commands.v2.tasks import mistralclient.commands.v2.workbooks import mistralclient.commands.v2.workflows +from mistralclient import exceptions as exe from mistralclient.openstack.common import cliutils as c from cliff import app @@ -237,7 +238,7 @@ class MistralShell(app.App): '--os-username', action='store', dest='username', - default=c.env('OS_USERNAME', default='admin'), + default=c.env('OS_USERNAME'), help='Authentication username (Env: OS_USERNAME)' ) @@ -376,6 +377,19 @@ class MistralShell(app.App): if do_help or ('bash-completion' in argv): self.options.auth_url = None + if self.options.auth_url and not self.options.token: + if not self.options.username: + raise exe.IllegalArgumentException( + ("You must provide a username " + "via --os-username env[OS_USERNAME]") + ) + + if not self.options.password: + raise exe.IllegalArgumentException( + ("You must provide a password " + "via --os-password env[OS_PASSWORD]") + ) + kwargs = { 'cert': self.options.os_cert, 'key': self.options.os_key diff --git a/mistralclient/tests/unit/test_shell.py b/mistralclient/tests/unit/test_shell.py index e6b07197..026eb52b 100644 --- a/mistralclient/tests/unit/test_shell.py +++ b/mistralclient/tests/unit/test_shell.py @@ -84,7 +84,12 @@ class TestShell(base.BaseShellTests): @mock.patch('mistralclient.api.client.client') def test_auth_url(self, mock): - self.shell('--os-auth-url=https://127.0.0.1:35357/v3 workbook-list') + self.shell( + '--os-auth-url=https://127.0.0.1:35357/v3 ' + '--os-username=admin ' + '--os-password=1234 ' + 'workbook-list' + ) self.assertTrue(mock.called) params = mock.call_args self.assertEqual('https://127.0.0.1:35357/v3', params[1]['auth_url']) @@ -105,7 +110,10 @@ class TestShell(base.BaseShellTests): @mock.patch('mistralclient.api.client.client') def test_default_auth_url_with_os_auth_token(self, mock): - self.shell('--os-auth-token=abcd1234 workbook-list') + self.shell( + '--os-auth-token=abcd1234 ' + 'workbook-list' + ) self.assertTrue(mock.called) params = mock.call_args self.assertEqual('http://localhost:35357/v3', params[1]['auth_url'])