From 8e7cfabc273f69c236ebf48c02fcf0b26592f490 Mon Sep 17 00:00:00 2001 From: Vladyslav Drok Date: Fri, 27 Oct 2017 17:44:56 +0300 Subject: [PATCH] Make none auth usable in CLI Closes-Bug: #1724283 Change-Id: I3e477895ba0c989ffd0c91c45791e9f74173a3d6 --- keystoneauth1/loading/_plugins/noauth.py | 16 ++++++++++++---- keystoneauth1/noauth.py | 15 ++++++++++++++- keystoneauth1/tests/unit/test_noauth.py | 13 ++++++++++++- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/keystoneauth1/loading/_plugins/noauth.py b/keystoneauth1/loading/_plugins/noauth.py index ea75f5b0..29a83a26 100644 --- a/keystoneauth1/loading/_plugins/noauth.py +++ b/keystoneauth1/loading/_plugins/noauth.py @@ -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 diff --git a/keystoneauth1/noauth.py b/keystoneauth1/noauth.py index 95037714..5d3b2cd9 100644 --- a/keystoneauth1/noauth.py +++ b/keystoneauth1/noauth.py @@ -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 diff --git a/keystoneauth1/tests/unit/test_noauth.py b/keystoneauth1/tests/unit/test_noauth.py index 8050b69f..08e4a51a 100644 --- a/keystoneauth1/tests/unit/test_noauth.py +++ b/keystoneauth1/tests/unit/test_noauth.py @@ -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'))