From feaafdc651bf967b6d181cc384bf583152246956 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Tue, 12 Aug 2014 07:38:16 +1000 Subject: [PATCH] Allow registering individual plugin CONF options Give plugins some more flexibility in registering there own CONF options. Change-Id: Id6d47e59e96b7b42c04cecdd53c13a887f60c75b --- keystoneclient/auth/base.py | 31 +++++++++++++++++++++++++++++++ keystoneclient/auth/conf.py | 12 ++---------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/keystoneclient/auth/base.py b/keystoneclient/auth/base.py index 147433ea0..74d4de533 100644 --- a/keystoneclient/auth/base.py +++ b/keystoneclient/auth/base.py @@ -171,3 +171,34 @@ class BaseAuthPlugin(object): kwargs.setdefault(opt.dest, val) return cls.load_from_options(**kwargs) + + @classmethod + def register_conf_options(cls, conf, group): + """Register the oslo.config options that are needed for a plugin. + + :param conf: An oslo.config conf object. + :param string group: The group name that options should be read from. + """ + plugin_opts = cls.get_options() + conf.register_opts(plugin_opts, group=group) + + @classmethod + def load_from_conf_options(cls, conf, group, **kwargs): + """Load the plugin from a CONF object. + + Convert the options already registered into a real plugin. + + :param conf: An oslo.config conf object. + :param string group: The group name that options should be read from. + + :returns plugin: An authentication Plugin. + """ + plugin_opts = cls.get_options() + + for opt in plugin_opts: + val = conf[group][opt.dest] + if val is not None: + val = opt.type(val) + kwargs.setdefault(opt.dest, val) + + return cls.load_from_options(**kwargs) diff --git a/keystoneclient/auth/conf.py b/keystoneclient/auth/conf.py index b14627e7c..c3d13dbc8 100644 --- a/keystoneclient/auth/conf.py +++ b/keystoneclient/auth/conf.py @@ -104,13 +104,5 @@ def load_from_conf_options(conf, group, **kwargs): raise exceptions.NoMatchingPlugin('No plugin name provided for config') plugin_class = base.get_plugin_class(name) - plugin_opts = plugin_class.get_options() - conf.register_opts(plugin_opts, group=group) - - for opt in plugin_opts: - val = conf[group][opt.dest] - if val is not None: - val = opt.type(val) - kwargs.setdefault(opt.dest, val) - - return plugin_class.load_from_options(**kwargs) + plugin_class.register_conf_options(conf, group) + return plugin_class.load_from_conf_options(conf, group, **kwargs)