Merge "Make none auth usable in CLI"
This commit is contained in:
@@ -17,11 +17,12 @@ from keystoneauth1 import noauth
|
|||||||
class NoAuth(loading.BaseLoader):
|
class NoAuth(loading.BaseLoader):
|
||||||
"""Use no tokens to perform requests.
|
"""Use no tokens to perform requests.
|
||||||
|
|
||||||
This must be used together with adapter.Adapter.endpoint_override
|
This can be used to instantiate clients for services deployed in
|
||||||
to instantiate clients for services deployed in noauth/standalone mode.
|
noauth/standalone mode.
|
||||||
|
|
||||||
There is no fetching a service catalog or determining scope information
|
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
|
return noauth.NoAuth
|
||||||
|
|
||||||
def get_options(self):
|
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
|
||||||
|
|||||||
@@ -20,5 +20,18 @@ class NoAuth(plugin.BaseAuthPlugin):
|
|||||||
that might be deployed in standalone/noauth mode.
|
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'
|
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
|
||||||
|
|||||||
@@ -34,4 +34,15 @@ class NoAuthTest(utils.TestCase):
|
|||||||
self.assertIsNone(a.get_endpoint(s))
|
self.assertIsNone(a.get_endpoint(s))
|
||||||
|
|
||||||
def test_noauth_options(self):
|
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'))
|
||||||
|
|||||||
Reference in New Issue
Block a user