Example #1
0
def get_options_list():
    """Gather plugin options so the help action has them available"""

    global OPTIONS_LIST

    if not OPTIONS_LIST:
        for plugin_name in get_plugin_list():
            plugin_options = base.get_plugin_options(plugin_name)
            for o in plugin_options:
                os_name = o.name.lower().replace('_', '-')
                os_env_name = 'OS_' + os_name.upper().replace('-', '_')
                OPTIONS_LIST.setdefault(
                    os_name,
                    {
                        'env': os_env_name,
                        'help': ''
                    },
                )
                # TODO(mhu) simplistic approach, would be better to only add
                # help texts if they vary from one auth plugin to another
                # also the text rendering is ugly in the CLI ...
                OPTIONS_LIST[os_name]['help'] += 'With %s: %s\n' % (
                    plugin_name,
                    o.help,
                )
    return OPTIONS_LIST
Example #2
0
def check_valid_authentication_options(options, auth_plugin_name):
    """Validate authentication options, and provide helpful error messages."""

    # Get all the options defined within the plugin.
    plugin_opts = base.get_plugin_options(auth_plugin_name)
    plugin_opts = {opt.dest: opt for opt in plugin_opts}

    # NOTE(aloga): this is an horrible hack. We need a way to specify the
    # required options in the plugins. Using the "required" argument for
    # the oslo_config.cfg.Opt does not work, as it is not possible to load the
    # plugin if the option is not defined, so the error will simply be:
    # "NoMatchingPlugin: The plugin foobar could not be found"
    msgs = []
    if 'password' in plugin_opts and not options.auth.get('username'):
        msgs.append(_('Set a username with --os-username, OS_USERNAME,'
                      ' or auth.username'))
    if 'auth_url' in plugin_opts and not options.auth.get('auth_url'):
        msgs.append(_('Set a service AUTH_URL, with --os-auth-url, '
                      'OS_AUTH_URL or auth.auth_url'))
    if 'url' in plugin_opts and not options.auth.get('url'):
        msgs.append(_('Set a service URL, with --os-url, '
                      'OS_URL or auth.url'))
    if 'token' in plugin_opts and not options.auth.get('token'):
            msgs.append(_('Set a token with --os-token, '
                          'OS_TOKEN or auth.token'))
    if msgs:
        raise exc.CommandError(
            _('Missing parameter(s): \n%s') % '\n'.join(msgs))
Example #3
0
def build_auth_params(auth_plugin_name, cmd_options):

    if auth_plugin_name:
        LOG.debug('auth_type: %s', auth_plugin_name)
        auth_plugin_loader = base.get_plugin_loader(auth_plugin_name)
        auth_params = {opt.dest: opt.default
                       for opt in base.get_plugin_options(auth_plugin_name)}
        auth_params.update(dict(cmd_options.auth))
        # grab tenant from project for v2.0 API compatibility
        if auth_plugin_name.startswith("v2"):
            if 'project_id' in auth_params:
                auth_params['tenant_id'] = auth_params['project_id']
                del auth_params['project_id']
            if 'project_name' in auth_params:
                auth_params['tenant_name'] = auth_params['project_name']
                del auth_params['project_name']
    else:
        LOG.debug('no auth_type')
        # delay the plugin choice, grab every option
        auth_plugin_loader = None
        auth_params = dict(cmd_options.auth)
        plugin_options = set([o.replace('-', '_') for o in get_options_list()])
        for option in plugin_options:
            LOG.debug('fetching option %s', option)
            auth_params[option] = getattr(cmd_options.auth, option, None)
    return (auth_plugin_loader, auth_params)
Example #4
0
def get_plugin_conf_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 [o._to_oslo_opt() for o in base.get_plugin_options(name)]
Example #5
0
def get_plugin_conf_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 [o._to_oslo_opt() for o in base.get_plugin_options(name)]
    def take_action(self, parsed_args):

        auth_plg_name = self.app.client_manager.auth_plugin_name
        secret_opts = [o.dest for o in base.get_plugin_options(auth_plg_name) if o.secret]

        info = self.app.client_manager.get_configuration()
        for key, value in six.iteritems(info.pop("auth", {})):
            if parsed_args.mask and key.lower() in secret_opts:
                value = REDACTED
            info["auth." + key] = value
        return zip(*sorted(six.iteritems(info)))
    def take_action(self, parsed_args):

        auth_plg_name = self.app.client_manager.auth_plugin_name
        secret_opts = [o.dest for o in base.get_plugin_options(auth_plg_name)
                       if o.secret]

        info = self.app.client_manager.get_configuration()
        for key, value in six.iteritems(info.pop('auth', {})):
            if parsed_args.mask and key.lower() in secret_opts:
                    value = REDACTED
            info['auth.' + key] = value
        return zip(*sorted(six.iteritems(info)))
Example #8
0
def check_valid_authentication_options(options, auth_plugin_name):
    """Validate authentication options, and provide helpful error messages

    :param required_scope: indicate whether a scoped token is required

    """

    # Get all the options defined within the plugin.
    plugin_opts = base.get_plugin_options(auth_plugin_name)
    plugin_opts = {opt.dest: opt for opt in plugin_opts}

    # NOTE(aloga): this is an horrible hack. We need a way to specify the
    # required options in the plugins. Using the "required" argument for
    # the oslo_config.cfg.Opt does not work, as it is not possible to load the
    # plugin if the option is not defined, so the error will simply be:
    # "NoMatchingPlugin: The plugin foobar could not be found"
    msgs = []

    # when no auth params are passed in, user advised to use os-cloud
    if not options.auth:
        msgs.append(_(
            'Set a cloud-name with --os-cloud or OS_CLOUD'
        ))
    else:
        if ('password' in plugin_opts and not
                (options.auth.get('username') or options.auth.get('user_id'))):
            msgs.append(_(
                'Set a username with --os-username, OS_USERNAME,'
                ' or auth.username'
                ' or set a user-id with --os-user-id, OS_USER_ID,'
                ' or auth.user_id'
            ))
        if 'auth_url' in plugin_opts and not options.auth.get('auth_url'):
            msgs.append(_(
                'Set an authentication URL, with --os-auth-url,'
                ' OS_AUTH_URL or auth.auth_url'
            ))
        if 'url' in plugin_opts and not options.auth.get('url'):
            msgs.append(_(
                'Set a service URL, with --os-url, OS_URL or auth.url'
            ))
        if 'token' in plugin_opts and not options.auth.get('token'):
            msgs.append(_(
                'Set a token with --os-token, OS_TOKEN or auth.token'
            ))

    if msgs:
        raise exc.CommandError(
            _('Missing parameter(s): \n%s') % '\n'.join(msgs)
        )
def get_plugin_conf_options(plugin):
    """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.

    :param plugin: The name of the plugin loader or a plugin loader object
    :type plugin: str or keystoneauth1._loading.BaseLoader

    :returns: A list of oslo_config options.
    """
    try:
        getter = plugin.get_options
    except AttributeError:
        opts = base.get_plugin_options(plugin)
    else:
        opts = getter()

    return [o._to_oslo_opt() for o in opts]
Example #10
0
def get_plugin_conf_options(plugin):
    """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.

    :param plugin: The name of the plugin loader or a plugin loader object
    :type plugin: str or keystoneauth1._loading.BaseLoader

    :returns: A list of oslo_config options.
    """
    try:
        getter = plugin.get_options
    except AttributeError:
        opts = base.get_plugin_options(plugin)
    else:
        opts = getter()

    return [o._to_oslo_opt() for o in opts]
Example #11
0
    def take_action(self, parsed_args):

        info = self.app.client_manager.get_configuration()

        # Assume a default secret list in case we do not have an auth_plugin
        secret_opts = ["password", "token"]

        if getattr(self.app.client_manager, "auth_plugin_name", None):
            auth_plg_name = self.app.client_manager.auth_plugin_name
            secret_opts = [
                o.dest for o in base.get_plugin_options(auth_plg_name)
                if o.secret
            ]

        for key, value in info.pop('auth', {}).items():
            if parsed_args.mask and key.lower() in secret_opts:
                value = REDACTED
            info['auth.' + key] = value

        return zip(*sorted(info.items()))
Example #12
0
def get_options_list():
    """Gather plugin options so the help action has them available"""

    global OPTIONS_LIST

    if not OPTIONS_LIST:
        for plugin_name in get_plugin_list():
            plugin_options = base.get_plugin_options(plugin_name)
            for o in plugin_options:
                os_name = o.name.lower().replace('_', '-')
                os_env_name = 'OS_' + os_name.upper().replace('-', '_')
                OPTIONS_LIST.setdefault(
                    os_name, {'env': os_env_name, 'help': ''},
                )
                # TODO(mhu) simplistic approach, would be better to only add
                # help texts if they vary from one auth plugin to another
                # also the text rendering is ugly in the CLI ...
                OPTIONS_LIST[os_name]['help'] += 'With %s: %s\n' % (
                    plugin_name,
                    o.help,
                )
    return OPTIONS_LIST