Fix support of dev use case with no auth
If --os-auth-url is not provided, then assume auth is not enabled. However, if --os-password or --os-auth-token is provided, then use default auth URL if it is not provided. Change-Id: Iaba14949e1b507f440b1609eb2d58eb6b6399f1d Closes-Bug: #1503915
This commit is contained in:
parent
a87923d92f
commit
e9b8e75b72
@ -224,7 +224,7 @@ class MistralShell(app.App):
|
||||
'--os-password',
|
||||
action='store',
|
||||
dest='password',
|
||||
default=c.env('OS_PASSWORD', default='openstack'),
|
||||
default=c.env('OS_PASSWORD'),
|
||||
help='Authentication password (Env: OS_PASSWORD)'
|
||||
)
|
||||
parser.add_argument(
|
||||
@ -252,7 +252,7 @@ class MistralShell(app.App):
|
||||
'--os-auth-url',
|
||||
action='store',
|
||||
dest='auth_url',
|
||||
default=c.env('OS_AUTH_URL', default='http://localhost:35357/v3'),
|
||||
default=c.env('OS_AUTH_URL'),
|
||||
help='Authentication URL (Env: OS_AUTH_URL)'
|
||||
)
|
||||
parser.add_argument(
|
||||
@ -273,6 +273,13 @@ class MistralShell(app.App):
|
||||
|
||||
do_help = ('help' in argv) or ('-h' in argv) or not argv
|
||||
|
||||
# Set default for auth_url if not supplied. The default is not
|
||||
# set at the parser to support use cases where auth is not enabled.
|
||||
# An example use case would be a developer's environment.
|
||||
if not self.options.auth_url:
|
||||
if self.options.password or self.options.token:
|
||||
self.options.auth_url = 'http://localhost:35357/v3'
|
||||
|
||||
# bash-completion should not require authentification.
|
||||
if do_help or ('bash-completion' in argv):
|
||||
self.options.auth_url = None
|
||||
|
@ -81,3 +81,31 @@ class TestShell(base.BaseShellTests):
|
||||
self.assertTrue(mock.called)
|
||||
params = mock.call_args
|
||||
self.assertEqual('publicURL', params[1]['endpoint_type'])
|
||||
|
||||
@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.assertTrue(mock.called)
|
||||
params = mock.call_args
|
||||
self.assertEqual('https://127.0.0.1:35357/v3', params[1]['auth_url'])
|
||||
|
||||
@mock.patch('mistralclient.api.client.client')
|
||||
def test_no_auth_url(self, mock):
|
||||
self.shell('workbook-list')
|
||||
self.assertTrue(mock.called)
|
||||
params = mock.call_args
|
||||
self.assertEqual('', params[1]['auth_url'])
|
||||
|
||||
@mock.patch('mistralclient.api.client.client')
|
||||
def test_default_auth_url_with_os_password(self, mock):
|
||||
self.shell('--os-username=admin --os-password=1234 workbook-list')
|
||||
self.assertTrue(mock.called)
|
||||
params = mock.call_args
|
||||
self.assertEqual('http://localhost:35357/v3', params[1]['auth_url'])
|
||||
|
||||
@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.assertTrue(mock.called)
|
||||
params = mock.call_args
|
||||
self.assertEqual('http://localhost:35357/v3', params[1]['auth_url'])
|
||||
|
Loading…
Reference in New Issue
Block a user