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(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 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 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 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 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 load_config(): return read_config_file_hierarchy({ 'config_file': '/etc/wazo-webhookd/config.yml', 'extra_config_files': '/etc/wazo-webhookd/conf.d', })
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(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 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 _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['logfile'], config['foreground'], config['debug']) silence_loggers(['urllib3'], logging.WARNING) xivo_dao.init_db_from_config(config) with pidfile_context(config['pidfile'], config['foreground']): agid.init(config) agid.run()
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 complete(): if not os.path.exists(KEY_FILENAME): return with open(KEY_FILENAME, 'r') as f: for line in f: key = line.strip() break password = random_string(28) body = { 'key': key, 'username': USERNAME, 'password': password, 'purpose': PURPOSE, } wazo_auth_config = read_config_file_hierarchy( {'config_file': DEFAULT_WAZO_AUTH_CONFIG_FILE}) port = wazo_auth_config['rest_api']['https']['port'] url = URL.format(port) for _ in range(40): try: response = requests.post(url, data=json.dumps(body), headers=HEADERS, verify=False) break except requests.exceptions.ConnectionError: time.sleep(0.25) else: raise Exception('failed to connect to wazo-auth') response.raise_for_status() for d in [USER_CONFIG_DIR, CLI_CONFIG_DIR]: try: os.mkdir(d) except OSError: pass # Directory already exists cli_config = CLI_CONFIG.format(**body) write_private_file(CLI_CONFIG_FILENAME, USER, cli_config) try: os.remove(INIT_CONFIG_FILENAME) except OSError: pass # Already deleted
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 _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()
def init_config_file(): global _file_config _file_config = read_config_file_hierarchy(xivo_cti.config) _update_config()
def _read_config(): cli_config = _read_config_from_commandline() 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)) 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(): 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 get_wazo_auth_port(): file_config = read_config_file_hierarchy(_DEFAULT_CONFIG) config = ChainMap(file_config, _DEFAULT_CONFIG) return config['rest_api']['port']
def _load_config(): file_config = read_config_file_hierarchy(_DEFAULT_CONFIG) return ChainMap(file_config, _DEFAULT_CONFIG)
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_database_uri_from_config(): wazo_auth_config = read_config_file_hierarchy( {'config_file': DEFAULT_WAZO_AUTH_CONFIG_FILE} ) return wazo_auth_config["db_uri"]