示例#1
0
def load_config(argv):
    cli_config = _parse_cli_args(argv)
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    intermediate_config = ChainMap(cli_config, file_config, _DEFAULT_CONFIG)
    reinterpreted_config = _get_reinterpreted_raw_values(intermediate_config)
    return ChainMap(reinterpreted_config, intermediate_config)
示例#2
0
def load_config(config_dir=None):
    config_dir = config_dir or DEFAULT_CONFIG_DIR
    config_dir = os.path.abspath(config_dir)
    logger.debug('Reading config from %s...', config_dir)
    file_configs = parse_config_dir(config_dir)
    config = ChainMap(*file_configs, DEFAULT_GLOBAL_CONFIG)
    instances = config['instances']

    if not instances:
        raise Exception(
            'At least one instance should be defined. See the README for the format.'
        )

    # set default config for each instance
    instances = {
        instance: ChainMap(instances[instance],
                           deepcopy(DEFAULT_INSTANCE_CONFIG))
        for instance in instances
    }

    for instance_config in instances.values():
        _config_update_host(instance_config)
        _config_post_processor(instance_config)

    config['instances'] = instances
    return config
示例#3
0
def load_config():
    cli_config = _get_cli_config()
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    service_key = _load_key_file(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    return ChainMap(cli_config, service_key, file_config, _DEFAULT_CONFIG)
示例#4
0
def main():
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    service_key = _load_key_file(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    config = ChainMap(cli_config, service_key, file_config, _DEFAULT_CONFIG)

    user = config.get('user')
    if user:
        change_user(user)

    xivo_dao.init_db_from_config(config)

    setup_logging(config['logfile'], config['foreground'], config['debug'])
    silence_loggers(['Flask-Cors'], logging.WARNING)
    set_xivo_uuid(config, logger)

    with pidfile_context(config['pidfile'], config['foreground']):
        logger.info('Starting xivo-agentd')
        try:
            _run(config)
        except Exception:
            logger.exception('Unexpected error:')
        except KeyboardInterrupt:
            pass
        finally:
            logger.info('Stopping xivo-agentd')
示例#5
0
def load(argv):
    cli_config = _parse_cli_args(argv)
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    key_config = _load_key_file(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    return ChainMap(cli_config, key_config, file_config, _DEFAULT_CONFIG)
示例#6
0
def build(parsed_args):
    user_file_config = _read_user_config(parsed_args)
    system_file_config = read_config_file_hierarchy(
        ChainMap(user_file_config, _DEFAULT_CONFIG))
    final_config = ChainMap(user_file_config, system_file_config,
                            _DEFAULT_CONFIG)
    return final_config
示例#7
0
def load(logger, argv):
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    service_key = _load_key_file(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    return ChainMap(cli_config, service_key, file_config, _DEFAULT_CONFIG)
示例#8
0
def get_config(argv):
    cli_config = _parse_cli_args(argv)
    file_config = read_config_file_hierarchy_accumulating_list(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    reinterpreted_config = _get_reinterpreted_raw_values(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    return ChainMap(reinterpreted_config, cli_config, file_config,
                    _DEFAULT_CONFIG)
示例#9
0
def load(argv):
    cli_config = _parse_cli_args(argv)
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, DEFAULT_CONFIG))
    reinterpreted_config = _get_reinterpreted_raw_values(
        ChainMap(cli_config, file_config, DEFAULT_CONFIG))
    return ChainMap(reinterpreted_config, cli_config, file_config,
                    DEFAULT_CONFIG)
示例#10
0
def load_config(args):
    cli_config = _parse_cli_args(args)
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    reinterpreted_config = _get_reinterpreted_raw_values(
        cli_config, file_config, _DEFAULT_CONFIG)
    service_key = _load_key_file(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    return ChainMap(reinterpreted_config, cli_config, service_key, file_config,
                    _DEFAULT_CONFIG)
示例#11
0
def _generate_call_logs():
    parser = argparse.ArgumentParser(description='Call logs generator')
    options = parse_args(parser)

    file_config = {
        key: value
        for key, value in read_config_file_hierarchy(DEFAULT_CONFIG).items()
        if key in ('confd', 'bus', 'auth', 'db_uri', 'cel_db_uri')
    }
    key_config = {}
    auth_username = file_config['auth'].get('username')
    auth_password = file_config['auth'].get('password')
    if not (auth_username and auth_password):
        key_config = load_key_file(ChainMap(file_config, DEFAULT_CONFIG))
    config = ChainMap(key_config, file_config, DEFAULT_CONFIG)
    set_xivo_uuid(config, logger)
    init_db_from_config({'db_uri': config['cel_db_uri']})
    DBSession = new_db_session(config['db_uri'])
    CELDBSession = new_db_session(config['cel_db_uri'])
    dao = DAO(DBSession, CELDBSession)

    auth_client = AuthClient(**config['auth'])
    confd_client = ConfdClient(**config['confd'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(confd_client.set_token)

    generator = CallLogsGenerator(
        confd_client,
        [
            LocalOriginateCELInterpretor(),
            DispatchCELInterpretor(CallerCELInterpretor(),
                                   CalleeCELInterpretor()),
        ],
    )
    token_renewer.subscribe_to_next_token_details_change(
        generator.set_default_tenant_uuid)
    writer = CallLogsWriter(dao)
    publisher = BusPublisher(service_uuid=config['uuid'], **config['bus'])
    manager = CallLogsManager(dao, generator, writer, publisher)

    options = vars(options)
    with token_renewer:
        if options.get('action') == 'delete':
            if options.get('all'):
                manager.delete_all()
            elif options.get('days'):
                manager.delete_from_days(options['days'])
        else:
            if options.get('days'):
                manager.generate_from_days(days=options['days'])
            else:
                manager.generate_from_count(cel_count=options['cel_count'])
示例#12
0
def main():
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(ChainMap(cli_config, _DEFAULT_CONFIG))
    config = ChainMap(cli_config, file_config, _DEFAULT_CONFIG)

    setup_logging(config['log_file'], debug=config['debug'])

    xivo_dao.init_db_from_config(config)

    with pidfile_context(config['pid_file']):
        if 'archives' in config.get('enabled_plugins', {}):
            _load_plugins(config)
        _purge_tables(config)
示例#13
0
    def get(self):
        specs = []
        for module in iter_entry_points(group=self.api_entry_point):
            try:
                plugin_package = module.module_name.rsplit('.', 1)[0]
                spec = yaml.safe_load(
                    resource_string(plugin_package, self.api_filename))
                if not spec:
                    logger.debug('plugin has no API spec: %s', plugin_package)
                else:
                    specs.append(spec)
            except ImportError:
                logger.debug('failed to import %s', plugin_package)
            except IOError:
                logger.debug('API spec for module "%s" does not exist',
                             module.module_name)
            except IndexError:
                logger.debug('Could not find API spec from module "%s"',
                             module.module_name)
            except NotImplementedError:
                logger.debug(
                    'Are you sure you have an __init__ file in your module "%s"?',
                    module.module_name)
        api_spec = ChainMap(*specs)

        if not api_spec.get('info'):
            return {'error': "API spec does not exist"}, 404

        return make_response(yaml.dump(dict(api_spec)), 200,
                             {'Content-Type': 'application/x-yaml'})
示例#14
0
def _generate_call_logs():
    parser = argparse.ArgumentParser(description='Call logs generator')
    options = parse_args(parser)
    key_config = load_key_file(DEFAULT_CONFIG)
    config = ChainMap(key_config, DEFAULT_CONFIG)

    auth_client = AuthClient(**config['auth'])
    confd_client = ConfdClient(**config['confd'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(confd_client.set_token)

    cel_fetcher = CELFetcher()
    generator = CallLogsGenerator([
        LocalOriginateCELInterpretor(confd_client),
        DispatchCELInterpretor(CallerCELInterpretor(confd_client),
                               CalleeCELInterpretor(confd_client))
    ])
    writer = CallLogsWriter()
    publisher = BusPublisher(config)
    manager = CallLogsManager(cel_fetcher, generator, writer, publisher)

    options = vars(options)
    with token_renewer:
        if options.get('action') == 'delete':
            if options.get('all'):
                manager.delete_all()
            elif options.get('days'):
                manager.delete_from_days(options['days'])
        else:
            if options.get('days'):
                manager.generate_from_days(days=options['days'])
            else:
                manager.generate_from_count(cel_count=options['cel_count'])
示例#15
0
    def get(self):
        api_spec = ChainMap(*load_all_api_specs('wazo_calld.plugins', self.api_filename))

        if not api_spec.get('info'):
            return {'error': "API spec does not exist"}, 404

        return make_response(yaml.dump(dict(api_spec)), 200, {'Content-Type': 'application/x-yaml'})
示例#16
0
文件: config.py 项目: pc-m/wazo-dird
def load(logger, argv):
    cli_config = _parse_cli_args(argv)
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    reinterpreted_config = _get_reinterpreted_raw_values(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    key_file = _load_key_file(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))

    return ChainMap(
        reinterpreted_config,
        key_file,
        cli_config,
        file_config,
        _DEFAULT_CONFIG,
    )
def main():
    parser = argparse.ArgumentParser(description='Call logs database migrator')
    options = parse_args(parser)

    file_config = {
        key: value
        for key, value in read_config_file_hierarchy(DEFAULT_CONFIG).items()
        if key in ('db_uri', 'cel_db_uri')
    }
    config = ChainMap(file_config, DEFAULT_CONFIG)

    if config['user']:
        change_user(config['user'])

    setup_logging(
        config['logfile'],
        debug=config['debug'] or options.debug,
        log_level=get_log_level_by_name(config['log_level']),
    )
    options = vars(options)
    if options.get('action') == 'call-log':
        if options.get('index'):
            migrate_call_log_index(config)
        else:
            migrate_call_log_tables(config, options.get('max_entries'))
示例#18
0
def _get_reinterpreted_raw_values(*configs):
    config = ChainMap(*configs)
    return dict(
        log_level=get_log_level_by_name(
            'debug' if config['debug'] else config['log_level']
        )
    )
示例#19
0
def _generate_call_logs():
    parser = argparse.ArgumentParser(description='Call logs generator')
    options = parse_args(parser)

    file_config = {
        key: value
        for key, value in read_config_file_hierarchy(DEFAULT_CONFIG).items()
        if key in ('confd', 'bus', 'auth', 'db_uri')
    }
    key_config = load_key_file(ChainMap(file_config, DEFAULT_CONFIG))
    config = ChainMap(key_config, file_config, DEFAULT_CONFIG)
    init_db_from_config(config)

    auth_client = AuthClient(**config['auth'])
    confd_client = ConfdClient(**config['confd'])
    token_renewer = TokenRenewer(auth_client)
    token_renewer.subscribe_to_token_change(confd_client.set_token)

    cel_fetcher = CELFetcher()
    generator = CallLogsGenerator(
        confd_client,
        [
            LocalOriginateCELInterpretor(confd_client),
            DispatchCELInterpretor(
                CallerCELInterpretor(confd_client), CalleeCELInterpretor(confd_client)
            ),
        ],
    )
    token_renewer.subscribe_to_next_token_details_change(
        generator.set_default_tenant_uuid
    )
    writer = CallLogsWriter()
    publisher = BusPublisher(config)
    manager = CallLogsManager(cel_fetcher, generator, writer, publisher)

    options = vars(options)
    with token_renewer:
        if options.get('action') == 'delete':
            if options.get('all'):
                manager.delete_all()
            elif options.get('days'):
                manager.delete_from_days(options['days'])
        else:
            if options.get('days'):
                manager.generate_from_days(days=options['days'])
            else:
                manager.generate_from_count(cel_count=options['cel_count'])
示例#20
0
    def get(self):
        http_specs = load_all_api_specs('wazo_auth.http', self.api_filename)
        external_auth_specs = load_all_api_specs('wazo_auth.external_auth',
                                                 self.api_filename)
        specs = chain(http_specs, external_auth_specs)

        api_spec = ChainMap(*specs)
        if not api_spec.get('info'):
            return {'error': "API spec does not exist"}, 404

        return make_response(yaml.dump(dict(api_spec)), 200,
                             {'Content-Type': 'application/x-yaml'})
示例#21
0
def load(argv):
    try:
        with open(WIZARD_KEY_FILE, 'r') as f:
            key_config = {'wizard': yaml.safe_load(f)}
    except IOError:
        key_config = {}

    cli_config = _parse_cli_args(argv)
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, DEFAULT_CONFIG))
    reinterpreted_config = _get_reinterpreted_raw_values(
        ChainMap(cli_config, file_config, DEFAULT_CONFIG))
    service_key = _load_key_file(
        ChainMap(cli_config, file_config, DEFAULT_CONFIG))
    return ChainMap(
        reinterpreted_config,
        key_config,
        cli_config,
        service_key,
        file_config,
        DEFAULT_CONFIG,
    )
示例#22
0
def main():
    cli_config = _parse_args()
    file_config = read_config_file_hierarchy(
        ChainMap(cli_config, _DEFAULT_CONFIG))
    key_config = _load_key_file(
        ChainMap(cli_config, file_config, _DEFAULT_CONFIG))
    config = ChainMap(cli_config, key_config, file_config, _DEFAULT_CONFIG)

    setup_logging(config['logfile'], debug=config['debug'])
    silence_loggers(['urllib3'], logging.WARNING)

    user = config.get('user')
    if user:
        change_user(user)

    xivo_dao.init_db_from_config(config)

    token_renewer = TokenRenewer(AuthClient(**config['auth']))
    config['agentd']['client'] = AgentdClient(**config['agentd'])
    config['calld']['client'] = CalldClient(**config['calld'])
    config['confd']['client'] = ConfdClient(**config['confd'])
    config['dird']['client'] = DirdClient(**config['dird'])
    config['auth']['client'] = AuthClient(**config['auth'])

    def on_token_change(token_id):
        config['agentd']['client'].set_token(token_id)
        config['calld']['client'].set_token(token_id)
        config['confd']['client'].set_token(token_id)
        config['dird']['client'].set_token(token_id)
        config['auth']['client'].set_token(token_id)

    token_renewer.subscribe_to_token_change(on_token_change)

    agid.init(config)
    with token_renewer:
        agid.run()
示例#23
0
class TestMain(TestCase):
    def setUp(self):
        self.log_patch = patch('wazo_amid.bin.daemon.setup_logging')
        self.user_patch = patch('wazo_amid.bin.daemon.change_user')
        self.set_xivo_uuid = patch('wazo_amid.bin.daemon.set_xivo_uuid')

        self.log = self.log_patch.start()
        self.change_user = self.user_patch.start()
        self.set_xivo_uuid = self.set_xivo_uuid.start()

    def tearDown(self):
        self.user_patch.stop()
        self.log_patch.stop()
        self.set_xivo_uuid.stop()

    @patch(
        'wazo_amid.bin.daemon.load_config',
        Mock(return_value=ChainMap({'user': '******'}, default_config)),
    )
    @patch('wazo_amid.bin.daemon.Controller', Mock())
    def test_when_arg_user_is_given_then_change_user(self):
        main()

        self.change_user.assert_called_once_with('foobar')
def _load_config():
    file_config = read_config_file_hierarchy(_DEFAULT_CONFIG)
    key_config = _load_key_file(ChainMap(file_config, _DEFAULT_CONFIG))
    return ChainMap(key_config, file_config, _DEFAULT_CONFIG)
示例#25
0
def get_wazo_auth_port():
    file_config = read_config_file_hierarchy(_DEFAULT_CONFIG)
    config = ChainMap(file_config, _DEFAULT_CONFIG)

    return config['rest_api']['port']
示例#26
0
def _read_user_config(parsed_args):
    if not parsed_args.wazo_auth_cli_config:
        return {}
    configs = parse_config_dir(parsed_args.wazo_auth_cli_config)
    return ChainMap(*configs)
示例#27
0
def load():
    file_config = read_config_file_hierarchy(_DEFAULT_CONFIG)
    reinterpreted_config = _get_reinterpreted_raw_values(
        ChainMap(file_config, _DEFAULT_CONFIG))
    config = ChainMap(reinterpreted_config, file_config, _DEFAULT_CONFIG)
    return config
示例#28
0
def load_config():
    file_config = read_config_file_hierarchy(ChainMap(DEFAULT_CONFIG))
    service_key = _load_key_file(ChainMap(file_config, DEFAULT_CONFIG))
    return ChainMap(service_key, file_config, DEFAULT_CONFIG)
示例#29
0
def _update_config():
    xivo_cti.config.data = ChainMap(_cli_config, _file_config, _db_config, _default_config)
def _load_config():
    file_config = read_config_file_hierarchy(_DEFAULT_CONFIG)
    return ChainMap(file_config, _DEFAULT_CONFIG)