Support no_auth mode in mistral client
Now it is impossible to send requests without authentication. This patch allows to disable it if user doesn't provide auth_url to the client. Change-Id: I3b964e349dd6843ceb022264abe451a1b407786b Closes-bug: #1730067
This commit is contained in:
@@ -51,8 +51,13 @@ class Client(object):
|
||||
if mistral_url and not isinstance(mistral_url, six.string_types):
|
||||
raise RuntimeError('Mistral url should be a string.')
|
||||
|
||||
auth_handler = auth.get_auth_handler(auth_type)
|
||||
auth_response = auth_handler.authenticate(req, session=session) or {}
|
||||
# If auth url was provided then we perform an authentication, otherwise
|
||||
# just ignore this step
|
||||
if req.get('auth_url'):
|
||||
auth_handler = auth.get_auth_handler(auth_type)
|
||||
auth_response = auth_handler.authenticate(req, session=session)
|
||||
else:
|
||||
auth_response = {}
|
||||
|
||||
# If the session was None and we're using keystone auth, it will be
|
||||
# created by the auth_handler.
|
||||
|
@@ -141,6 +141,7 @@ class BaseClientTests(base.BaseTestCase):
|
||||
auth.get_access = mock.Mock(return_value=mock_access)
|
||||
|
||||
client.client(
|
||||
auth_url=AUTH_HTTP_URL_v3,
|
||||
username='user',
|
||||
api_key='password',
|
||||
user_domain_name='Default',
|
||||
@@ -303,3 +304,16 @@ class BaseClientTests(base.BaseTestCase):
|
||||
profiler = osprofiler.profiler.get()
|
||||
|
||||
self.assertEqual(profiler.hmac_key, PROFILER_HMAC_KEY)
|
||||
|
||||
@mock.patch('mistralclient.auth.get_auth_handler')
|
||||
def test_mistral_no_auth(self, get_auth_handler_mock):
|
||||
# Test that we don't authenticate if auth url wasn't provided
|
||||
|
||||
client.client(
|
||||
username='mistral',
|
||||
project_name='mistral',
|
||||
api_key='password',
|
||||
service_type='workflowv2'
|
||||
)
|
||||
|
||||
self.assertEqual(0, get_auth_handler_mock.call_count)
|
||||
|
Reference in New Issue
Block a user