Merge "Make none auth usable in CLI"

This commit is contained in:
Zuul 2017-12-07 23:41:54 +00:00 committed by Gerrit Code Review
commit 14dd37b34c
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'))