Use auth_type instead of auth_plugin by default

This was something that OSC has pushed for a long time now, and it's
better to be consistent than worry about wording.

Change --os-auth-plugin and auth_plugin= in CONF to be --os-auth-type
and auth_type= by default. We deprecated (but will probably keep for a
long time) the auth_plugin name.

Change-Id: I9748aeb4a490f88c73ef22ebe49e9b4ac6af78cd
This commit is contained in:
Jamie Lennox 2015-09-02 10:17:12 +10:00 committed by Monty Taylor
parent 4c65944c7b
commit a56ed4218a
4 changed files with 37 additions and 33 deletions

View File

@ -49,24 +49,26 @@ def register_argparse_arguments(parser, argv, default=None):
created.
"""
in_parser = argparse.ArgumentParser(add_help=False)
env_plugin = os.environ.get('OS_AUTH_PLUGIN', default)
env_plugin = os.environ.get('OS_AUTH_TYPE',
os.environ.get('OS_AUTH_PLUGIN', default))
for p in (in_parser, parser):
p.add_argument('--os-auth-plugin',
p.add_argument('--os-auth-type',
'--os-auth-plugin',
metavar='<name>',
default=env_plugin,
help='The auth plugin to load')
options, _args = in_parser.parse_known_args(argv)
if not options.os_auth_plugin:
if not options.os_auth_type:
return None
if isinstance(options.os_auth_plugin, base.BaseLoader):
if isinstance(options.os_auth_type, base.BaseLoader):
msg = 'Default Authentication options'
plugin = options.os_auth_plugin
plugin = options.os_auth_type
else:
msg = 'Options specific to the %s plugin.' % options.os_auth_plugin
plugin = base.get_plugin_loader(options.os_auth_plugin)
msg = 'Options specific to the %s plugin.' % options.os_auth_type
plugin = base.get_plugin_loader(options.os_auth_type)
group = parser.add_argument_group('Authentication Options', msg)
_register_plugin_argparse_arguments(group, plugin)
@ -87,13 +89,13 @@ def load_from_argparse_arguments(namespace, **kwargs):
:raises keystonauth.exceptions.NoMatchingPlugin: if a plugin cannot be
created.
"""
if not namespace.os_auth_plugin:
if not namespace.os_auth_type:
return None
if isinstance(namespace.os_auth_plugin, type):
plugin = namespace.os_auth_plugin
if isinstance(namespace.os_auth_type, type):
plugin = namespace.os_auth_type
else:
plugin = base.get_plugin_loader(namespace.os_auth_plugin)
plugin = base.get_plugin_loader(namespace.os_auth_type)
plugin_opts = plugin.get_options()

View File

@ -13,7 +13,9 @@
from keystoneauth1.loading import base
from keystoneauth1.loading import opts
_AUTH_PLUGIN_OPT = opts.Opt('auth_plugin', help='Name of the plugin to load')
_AUTH_TYPE_OPT = opts.Opt('auth_type',
deprecated=[opts.Opt('auth_plugin')],
help='Name of the plugin to load')
_section_help = 'Config Section from which to load plugin specific options'
_AUTH_SECTION_OPT = opts.Opt('auth_section', help=_section_help)
@ -32,12 +34,12 @@ def get_common_conf_options():
or to manipulate the options before registering them yourself.
The options that are set are:
:auth_plugin: The name of the pluign to load.
:auth_type: The name of the pluign to load.
:auth_section: The config file section to load options from.
:returns: A list of oslo_config options.
"""
return [_AUTH_PLUGIN_OPT._to_oslo_opt(), _AUTH_SECTION_OPT._to_oslo_opt()]
return [_AUTH_TYPE_OPT._to_oslo_opt(), _AUTH_SECTION_OPT._to_oslo_opt()]
def get_plugin_conf_options(name):
@ -59,7 +61,7 @@ def register_conf_options(conf, group):
The defined options are:
- auth_plugin: the name of the auth plugin that will be used for
- auth_type: the name of the auth plugin that will be used for
authentication.
- auth_section: the group from which further auth plugin options should be
taken. If section is not provided then the auth plugin options will be
@ -79,7 +81,7 @@ def register_conf_options(conf, group):
if conf[group].auth_section:
group = conf[group].auth_section
conf.register_opt(_AUTH_PLUGIN_OPT._to_oslo_opt(), group=group)
conf.register_opt(_AUTH_TYPE_OPT._to_oslo_opt(), group=group)
def load_from_conf_options(conf, group, **kwargs):
@ -107,7 +109,7 @@ def load_from_conf_options(conf, group, **kwargs):
if conf[group].auth_section:
group = conf[group].auth_section
name = conf[group].auth_plugin
name = conf[group].auth_type
if not name:
return None

View File

@ -46,7 +46,7 @@ class CliTests(utils.TestCase):
def test_creating_with_no_args(self):
ret = loading.register_auth_argparse_arguments(self.p, [])
self.assertIsNone(ret)
self.assertIn('--os-auth-plugin', self.p.format_usage())
self.assertIn('--os-auth-type', self.p.format_usage())
def test_load_with_nothing(self):
loading.register_auth_argparse_arguments(self.p, [])
@ -68,7 +68,7 @@ class CliTests(utils.TestCase):
@utils.mock_plugin()
def test_param_loading(self, m):
name = uuid.uuid4().hex
argv = ['--os-auth-plugin', name,
argv = ['--os-auth-type', name,
'--os-a-int', str(self.a_int),
'--os-a-float', str(self.a_float),
'--os-a-bool', str(self.a_bool)]
@ -77,12 +77,12 @@ class CliTests(utils.TestCase):
self.assertIsInstance(klass, utils.MockLoader)
opts = self.p.parse_args(argv)
self.assertEqual(name, opts.os_auth_plugin)
self.assertEqual(name, opts.os_auth_type)
a = loading.load_auth_from_argparse_arguments(opts)
self.assertTestVals(a)
self.assertEqual(name, opts.os_auth_plugin)
self.assertEqual(name, opts.os_auth_type)
self.assertEqual(str(self.a_int), opts.os_a_int)
self.assertEqual(str(self.a_float), opts.os_a_float)
self.assertEqual(str(self.a_bool), opts.os_a_bool)
@ -90,14 +90,14 @@ class CliTests(utils.TestCase):
@utils.mock_plugin()
def test_default_options(self, m):
name = uuid.uuid4().hex
argv = ['--os-auth-plugin', name,
argv = ['--os-auth-type', name,
'--os-a-float', str(self.a_float)]
klass = loading.register_auth_argparse_arguments(self.p, argv)
self.assertIsInstance(klass, utils.MockLoader)
opts = self.p.parse_args(argv)
self.assertEqual(name, opts.os_auth_plugin)
self.assertEqual(name, opts.os_auth_type)
a = loading.load_auth_from_argparse_arguments(opts)
@ -117,7 +117,7 @@ class CliTests(utils.TestCase):
def test_overrides_default_string_value(self, m):
name = uuid.uuid4().hex
default = uuid.uuid4().hex
argv = ['--os-auth-plugin', name]
argv = ['--os-auth-type', name]
klass = loading.register_auth_argparse_arguments(self.p,
argv,
default=default)
@ -140,7 +140,7 @@ class CliTests(utils.TestCase):
class TestLoader(object):
pass
name = uuid.uuid4().hex
argv = ['--os-auth-plugin', name]
argv = ['--os-auth-type', name]
klass = loading.register_auth_argparse_arguments(self.p,
argv,
default=TestLoader)

View File

@ -57,7 +57,7 @@ class ConfTests(utils.TestCase):
to_oslo_opts(v2.Password().get_options()),
group=section)
self.conf_fixture.config(auth_plugin=self.V2PASS,
self.conf_fixture.config(auth_type=self.V2PASS,
auth_url=auth_url,
username=username,
password=password,
@ -89,7 +89,7 @@ class ConfTests(utils.TestCase):
self.conf_fixture.register_opts(to_oslo_opts(v3.Token().get_options()),
group=section)
self.conf_fixture.config(auth_plugin=self.V3TOKEN,
self.conf_fixture.config(auth_type=self.V3TOKEN,
auth_url=auth_url,
token=token,
trust_id=trust_id,
@ -106,8 +106,8 @@ class ConfTests(utils.TestCase):
self.assertEqual(project_domain_name, a.project_domain_name)
def test_loading_invalid_plugin(self):
auth_plugin = uuid.uuid4().hex
self.conf_fixture.config(auth_plugin=auth_plugin,
auth_type = uuid.uuid4().hex
self.conf_fixture.config(auth_type=auth_type,
group=self.GROUP)
e = self.assertRaises(exceptions.NoMatchingPlugin,
@ -115,7 +115,7 @@ class ConfTests(utils.TestCase):
self.conf_fixture.conf,
self.GROUP)
self.assertEqual(auth_plugin, e.name)
self.assertEqual(auth_type, e.name)
def test_loading_with_no_data(self):
l = loading.load_auth_from_conf_options(self.conf_fixture.conf,
@ -130,7 +130,7 @@ class ConfTests(utils.TestCase):
self.conf_fixture.register_opts(
to_oslo_opts(utils.MockLoader().get_options()),
group=self.GROUP)
self.conf_fixture.config(auth_plugin=driver_name,
self.conf_fixture.config(auth_type=driver_name,
group=self.GROUP,
**self.TEST_VALS)
@ -150,7 +150,7 @@ class ConfTests(utils.TestCase):
loading.register_auth_conf_options(self.conf_fixture.conf,
group=self.GROUP)
self.conf_fixture.config(auth_plugin=uuid.uuid4().hex,
self.conf_fixture.config(auth_type=uuid.uuid4().hex,
group=self.GROUP,
**self.TEST_VALS)
@ -170,7 +170,7 @@ class ConfTests(utils.TestCase):
utils.MockLoader().get_options()),
group=section)
self.conf_fixture.config(group=section,
auth_plugin=uuid.uuid4().hex,
auth_type=uuid.uuid4().hex,
**self.TEST_VALS)
a = loading.load_auth_from_conf_options(self.conf_fixture.conf,