Beispiel #1
0
    def _factory(auth_url, **kwargs):
        """Construct a plugin appropriate to your available arguments.

        This function should only be used for loading authentication from a
        config file or other source where you do not know the type of plugin
        that is required.

        If you know the style of authorization you require then you should
        construct that plugin directly.

        :raises NoMatchingPlugin: if a plugin cannot be constructed.

        return Auth: a plugin that can be passed to a session.
        """
        username = kwargs.pop('username', None)
        password = kwargs.pop('password', None)
        token = kwargs.pop('token', None)

        if token:
            return Token(auth_url, token, **kwargs)
        elif username and password:
            return Password(auth_url, username, password, **kwargs)

        msg = 'A username and password or token is required.'
        raise exceptions.NoMatchingPlugin(msg)
def get_plugin_class(name):
    """Retrieve a plugin class by its entrypoint name.

    :param str name: The name of the object to get.

    :returns: An auth plugin class.

    :raises exceptions.NoMatchingPlugin: if a plugin cannot be created.
    """
    try:
        mgr = stevedore.DriverManager(namespace=PLUGIN_NAMESPACE,
                                      name=name,
                                      invoke_on_load=False)
    except RuntimeError:
        msg = 'The plugin %s could not be found' % name
        raise exceptions.NoMatchingPlugin(msg)

    return mgr.driver
Beispiel #3
0
def get_plugin_class(name):
    """Retrieve a plugin class by its entrypoint name.

    :param str name: The name of the object to get.

    :returns: An auth plugin class.
    :rtype: :py:class:`keystoneclient.auth.BaseAuthPlugin`

    :raises keystoneclient.exceptions.NoMatchingPlugin: if a plugin cannot be
                                                        created.
    """
    try:
        mgr = stevedore.DriverManager(namespace=PLUGIN_NAMESPACE,
                                      name=name,
                                      invoke_on_load=False)
    except RuntimeError:
        raise exceptions.NoMatchingPlugin(name)

    return mgr.driver
def load_from_conf_options(conf, group, **kwargs):
    """Load a plugin from an oslo.config CONF object.

    Each plugin will register there own required options and so there is no
    standard list and the plugin should be consulted.

    The base options should have been registered with register_conf_options
    before this function is called.

    :param conf: An oslo.config conf object.
    :param string group: The group name that options should be read from.

    :returns plugin: An authentication Plugin.

    :raises exceptions.NoMatchingPlugin: if a plugin cannot be created.
    """
    # NOTE(jamielennox): plugins are allowed to specify a 'section' which is
    # the group that auth options should be taken from. If not present they
    # come from the same as the base options were registered in.
    if conf[group].auth_section:
        group = conf[group].auth_section

    name = conf[group].auth_plugin
    if not name:
        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)