def load_from_conf_options(conf, group, **kwargs):
    """Load a plugin from an oslo_config CONF object.

    Each plugin will register their 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: A conf object.
    :type conf: oslo_config.cfg.ConfigOpts
    :param string group: The group name that options should be read from.

    :returns: An authentication Plugin or None if a name is not provided
    :rtype: :py:class:`keystonauth.auth.BaseAuthPlugin`

    :raises keystonauth.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:
        return None

    plugin_class = base.get_plugin_class(name)
    plugin_class.register_conf_options(conf, group)
    return plugin_class.load_from_conf_options(conf, group, **kwargs)
def get_plugin_options(name):
    """Get the oslo_config options for a specific plugin.

    This will be the list of config options that is registered and loaded by
    the specified plugin.

    :returns: A list of oslo_config options.
    """
    return base.get_plugin_class(name).get_options()
def register_argparse_arguments(parser, argv, default=None):
    """Register CLI options needed to create a plugin.

    The function inspects the provided arguments so that it can also register
    the options required for that specific plugin if available.

    :param argparse.ArgumentParser: the parser to attach argparse options to.
    :param list argv: the arguments provided to the appliation.
    :param str/class default: a default plugin name or a plugin object to use
                              if one isn't specified by the CLI. default: None.

    :returns: The plugin class that will be loaded or None if not provided.
    :rtype: :py:class:`keystonauth.auth.BaseAuthPlugin`

    :raises keystonauth.exceptions.NoMatchingPlugin: if a plugin cannot be
                                                        created.
    """
    in_parser = argparse.ArgumentParser(add_help=False)
    env_plugin = os.environ.get('OS_AUTH_PLUGIN', default)
    for p in (in_parser, parser):
        p.add_argument('--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:
        return None

    if isinstance(options.os_auth_plugin, type):
        msg = 'Default Authentication options'
        plugin = options.os_auth_plugin
    else:
        msg = 'Options specific to the %s plugin.' % options.os_auth_plugin
        plugin = base.get_plugin_class(options.os_auth_plugin)

    group = parser.add_argument_group('Authentication Options', msg)
    plugin.register_argparse_arguments(group)
    return plugin
def load_from_argparse_arguments(namespace, **kwargs):
    """Retrieve the created plugin from the completed argparse results.

    Loads and creates the auth plugin from the information parsed from the
    command line by argparse.

    :param Namespace namespace: The result from CLI parsing.

    :returns: An auth plugin, or None if a name is not provided.
    :rtype: :py:class:`keystonauth.auth.BaseAuthPlugin`

    :raises keystonauth.exceptions.NoMatchingPlugin: if a plugin cannot be
                                                        created.
    """
    if not namespace.os_auth_plugin:
        return None

    if isinstance(namespace.os_auth_plugin, type):
        plugin = namespace.os_auth_plugin
    else:
        plugin = base.get_plugin_class(namespace.os_auth_plugin)

    return plugin.load_from_argparse_arguments(namespace, **kwargs)