Make none auth usable in CLI

Closes-Bug: #1724283
Change-Id: I3e477895ba0c989ffd0c91c45791e9f74173a3d6
This commit is contained in:
Vladyslav Drok 2017-10-27 17:44:56 +03:00
parent 44c8b50a55
commit 8e7cfabc27
3 changed files with 38 additions and 6 deletions

View File

@ -17,11 +17,12 @@ from keystoneauth1 import noauth
class NoAuth(loading.BaseLoader):
"""Use no tokens to perform requests.
This must be used together with adapter.Adapter.endpoint_override
to instantiate clients for services deployed in noauth/standalone mode.
This can be used to instantiate clients for services deployed in
noauth/standalone mode.
There is no fetching a service catalog or determining scope information
and so it cannot be used by clients that expect use this scope information.
and so it cannot be used by clients that expect to use this scope
information.
"""
@ -30,4 +31,11 @@ class NoAuth(loading.BaseLoader):
return noauth.NoAuth
def get_options(self):
return []
options = super(NoAuth, self).get_options()
options.extend([
loading.Opt('endpoint',
help='The endpoint that will always be used'),
])
return options

View File

@ -20,5 +20,18 @@ class NoAuth(plugin.BaseAuthPlugin):
that might be deployed in standalone/noauth mode.
"""
def get_token(self, session):
def __init__(self, endpoint=None):
super(NoAuth, self).__init__()
self.endpoint = endpoint
def get_token(self, session, **kwargs):
return 'notused'
def get_endpoint(self, session, **kwargs):
"""Return the supplied endpoint.
Using this plugin the same endpoint is returned regardless of the
parameters passed to the plugin. endpoint_override overrides the
endpoint specified when constructing the plugin.
"""
return kwargs.get('endpoint_override') or self.endpoint

View File

@ -34,4 +34,15 @@ class NoAuthTest(utils.TestCase):
self.assertIsNone(a.get_endpoint(s))
def test_noauth_options(self):
self.assertEqual([], loader.NoAuth().get_options())
opts = loader.NoAuth().get_options()
self.assertEqual(['endpoint'], [o.name for o in opts])
def test_get_endpoint(self):
a = noauth.NoAuth(endpoint=self.TEST_URL)
s = session.Session(auth=a)
self.assertEqual(self.TEST_URL, a.get_endpoint(s))
def test_get_endpoint_with_override(self):
a = noauth.NoAuth(endpoint=self.TEST_URL)
s = session.Session(auth=a)
self.assertEqual('foo', a.get_endpoint(s, endpoint_override='foo'))