summaryrefslogtreecommitdiff
path: root/keystoneclient/auth
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-04-08 06:47:31 +0000
committerGerrit Code Review <review@openstack.org>2015-04-08 06:47:31 +0000
commit045c9dab6dfd599de42a7a7ac4a677e1a793b67f (patch)
tree05edbf761de6fe1b49c1cee9865141d1788291a7 /keystoneclient/auth
parent53dc900025c34378854425f40e3dea82d0416254 (diff)
parente39eec0ff84185f476a1c4cd3014decd149ddf58 (diff)
downloadpython-keystoneclient-045c9dab6dfd599de42a7a7ac4a677e1a793b67f.tar.gz
Merge "Provide a generic auth plugin loader"
Diffstat (limited to 'keystoneclient/auth')
-rw-r--r--keystoneclient/auth/base.py36
1 files changed, 29 insertions, 7 deletions
diff --git a/keystoneclient/auth/base.py b/keystoneclient/auth/base.py
index a6c54f1..91cf86a 100644
--- a/keystoneclient/auth/base.py
+++ b/keystoneclient/auth/base.py
@@ -255,13 +255,11 @@ class BaseAuthPlugin(object):
:returns: An auth plugin, or None if a name is not provided.
:rtype: :py:class:`keystoneclient.auth.BaseAuthPlugin`
"""
- for opt in cls.get_options():
- val = getattr(namespace, 'os_%s' % opt.dest)
- if val is not None:
- val = opt.type(val)
- kwargs.setdefault(opt.dest, val)
- return cls.load_from_options(**kwargs)
+ def _getter(opt):
+ return getattr(namespace, 'os_%s' % opt.dest)
+
+ return cls.load_from_options_getter(_getter, **kwargs)
@classmethod
def register_conf_options(cls, conf, group):
@@ -287,10 +285,34 @@ class BaseAuthPlugin(object):
:returns: An authentication Plugin.
:rtype: :py:class:`keystoneclient.auth.BaseAuthPlugin`
"""
+
+ def _getter(opt):
+ return conf[group][opt.dest]
+
+ return cls.load_from_options_getter(_getter, **kwargs)
+
+ @classmethod
+ def load_from_options_getter(cls, getter, **kwargs):
+ """Load a plugin from a getter function that returns appropriate values
+
+ To handle cases other than the provided CONF and CLI loading you can
+ specify a custom loader function that will be queried for the option
+ value.
+
+ The getter is a function that takes one value, an
+ :py:class:`oslo_config.cfg.Opt` and returns a value to load with.
+
+ :param getter: A function that returns a value for the given opt.
+ :type getter: callable
+
+ :returns: An authentication Plugin.
+ :rtype: :py:class:`keystoneclient.auth.BaseAuthPlugin`
+ """
+
plugin_opts = cls.get_options()
for opt in plugin_opts:
- val = conf[group][opt.dest]
+ val = getter(opt)
if val is not None:
val = opt.type(val)
kwargs.setdefault(opt.dest, val)