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'})
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)
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)
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)
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
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'})
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)
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')
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
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)
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)
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)
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'})
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'])
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)
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'))
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'])
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 _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'] ) )
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'])
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, )
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()
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)
def get_wazo_auth_port(): file_config = read_config_file_hierarchy(_DEFAULT_CONFIG) config = ChainMap(file_config, _DEFAULT_CONFIG) return config['rest_api']['port']
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)
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
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)
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)