Exemplo n.º 1
0
def add_parsed_conf(conf, normalized):
    """Add a normalized values container to a config manager.

    :param conf: A cfg.ConfigOpts object.
    :param normalized: A normalized values container, as introduced by oslo
        cfg._Namespace.
    """
    if conf:
        # pylint: disable=protected-access
        conf._namespace = cfg._Namespace(conf)

        # oslo.config version 6.0.1 added extra arg to _add_parsed_config_file
        # we determine the number of args required to use appropriately
        if six.PY2:
            _add_parsed_config_file_args_len = len(inspect.getargspec(
                conf._namespace._add_parsed_config_file).args) - 1
            # - 1 to not count the first param self
        else:
            _add_parsed_config_file_args_len = len(inspect.signature(
                conf._namespace._add_parsed_config_file).parameters)
        if _add_parsed_config_file_args_len == 3:  # oslo.config>=6.0.1
            conf._namespace._add_parsed_config_file(
                '<memory>', [], normalized[0])
        else:
            conf._namespace._add_parsed_config_file([], normalized[0])
Exemplo n.º 2
0
def add_parsed_conf(conf, normalized):
    """Add a normalized values container to a config manager.

    :param conf: A cfg.ConfigOpts object.
    :param normalized: A normalized values container, as introduced by oslo
        cfg._Namespace.
    """
    if conf:
        # pylint: disable=protected-access
        conf._namespace = cfg._Namespace(conf)

        # oslo.config version 6.0.1 added extra arg to _add_parsed_config_file
        # we determine the number of args required to use appropriately
        if six.PY2:
            _add_parsed_config_file_args_len = len(inspect.getargspec(
                conf._namespace._add_parsed_config_file).args) - 1
            # - 1 to not count the first param self
        else:
            _add_parsed_config_file_args_len = len(inspect.signature(
                conf._namespace._add_parsed_config_file).parameters)
        if _add_parsed_config_file_args_len == 3:  # oslo.config>=6.0.1
            conf._namespace._add_parsed_config_file(
                '<memory>', [], normalized[0])
        else:
            conf._namespace._add_parsed_config_file([], normalized[0])
Exemplo n.º 3
0
    def __init__(self, uri, ca_path=None, client_cert=None, client_key=None):
        self._uri = uri
        self._namespace = cfg._Namespace(cfg.ConfigOpts())

        data = self._fetch_uri(uri, ca_path, client_cert, client_key)

        with tempfile.NamedTemporaryFile() as tmpfile:
            tmpfile.write(data.encode("utf-8"))
            tmpfile.flush()

            cfg.ConfigParser._parse_file(tmpfile.name, self._namespace)
Exemplo n.º 4
0
def add_parsed_conf(conf, normalized):
    """Add a normalized values container to a config manager.

    :param conf: A cfg.ConfigOpts object.
    :param normalized: A normalized values container, as introduced by oslo
        cfg._Namespace.
    """
    if conf:
        # pylint: disable=protected-access
        conf._namespace = cfg._Namespace(conf)
        conf._namespace._add_parsed_config_file(None, normalized[0])
Exemplo n.º 5
0
    def __init__(self, uri, ca_path=None, client_cert=None, client_key=None):
        self._uri = uri
        self._namespace = cfg._Namespace(cfg.ConfigOpts())

        data = self._fetch_uri(uri, ca_path, client_cert, client_key)

        with tempfile.NamedTemporaryFile() as tmpfile:
            tmpfile.write(data.encode("utf-8"))
            tmpfile.flush()

            cfg.ConfigParser._parse_file(tmpfile.name, self._namespace)
Exemplo n.º 6
0
def parse_config_file(namespaces, path):
    """Parse a config file from its pre-loaded namespaces.

    :param namespaces: A list of dict, containing namespaces data.
    :param path: Path to the configuration file to parse.
    :return:
    """
    conf = construct_conf_manager(namespaces)
    # pylint: disable=protected-access
    conf._namespace = cfg._Namespace(conf)
    cfg.ConfigParser._parse_file(path, conf._namespace)

    return conf
Exemplo n.º 7
0
def parse_config_file(namespaces, path):
    """Parse a config file from its pre-loaded namespaces.

    :param namespaces: A list of dict, containing namespaces data.
    :param path: Path to the configuration file to parse.
    :return:
    """
    conf = construct_conf_manager(namespaces)
    # pylint: disable=protected-access
    conf._namespace = cfg._Namespace(conf)
    cfg.ConfigParser._parse_file(path, conf._namespace)

    return conf
Exemplo n.º 8
0
    def test_template_conf(self, parse_mock):
        """Test the parsing of template"""
        ns_mock = cfg._Namespace(None)
        ns_mock._normalized.append({
            'DEFAULT': {
                'output_file': ['etc/congress.conf.sample'],
                'wrap_width': ['79'],
                'namespace': ['congress', 'oslo.log'],
            }
        })

        parse_mock.return_value = ns_mock

        namespace, out_file = agent.Template._parse_template_conf('somewhere')

        self.assertEqual(out_file, 'etc/congress.conf.sample')
        self.assertIn('congress', namespace)
        self.assertIn('oslo.log', namespace)
Exemplo n.º 9
0
    def test_sanitize(self):
        "test config sanitization"
        conf = cfg.ConfigOpts()
        conf._namespace = cfg._Namespace(conf)
        conf._namespace._normalized = []

        opt_1 = cfg.StrOpt(name='lorem', secret=True)
        opt_2 = cfg.StrOpt(name='ipsum', secret=False)
        conf.register_opts([opt_1, opt_2])

        parsed = {'DEFAULT': {'lorem': ['mysecret'], 'ipsum': ['notsecret']}}
        conf._namespace._normalized.append(parsed)

        agent.Config.sanitize_config(conf)

        self.assertFalse('mysecret' in json.dumps(conf._namespace._normalized))
        self.assertTrue('notsecret' in json.dumps(conf._namespace._normalized))

        self.assertEqual(conf.lorem, '****')
        self.assertEqual(conf.ipsum, 'notsecret')