Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/api/server.py
Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | def make_app(config, **kwargs): | ||||
# Endpoints for batch requests | # Endpoints for batch requests | ||||
app.router.add_route('POST', '/batch_cook', batch_cook) | app.router.add_route('POST', '/batch_cook', batch_cook) | ||||
app.router.add_route('GET', '/batch_progress/{batch_id}', batch_progress) | app.router.add_route('GET', '/batch_progress/{batch_id}', batch_progress) | ||||
app['backend'] = VaultBackend(config) | app['backend'] = VaultBackend(config) | ||||
return app | return app | ||||
api_cfg = None | |||||
def make_app_from_configfile(config_path=DEFAULT_CONFIG_PATH, **kwargs): | def make_app_from_configfile(config_path=DEFAULT_CONFIG_PATH, **kwargs): | ||||
cfg = config.load_named_config(config_path, DEFAULT_CONFIG) | global api_cfg | ||||
return make_app(cfg, **kwargs) | if not api_cfg: | ||||
api_cfg = config.read(config_path, DEFAULT_CONFIG) | |||||
return make_app(api_cfg, **kwargs) | |||||
@click.command() | @click.command() | ||||
@click.argument('config-path', required=1) | @click.argument('config-path', required=1) | ||||
@click.option('--host', default='0.0.0.0', help="Host to run the server") | @click.option('--host', default='0.0.0.0', help="Host to run the server") | ||||
@click.option('--port', default=5005, type=click.INT, | @click.option('--port', default=5005, type=click.INT, | ||||
help="Binding port of the server") | help="Binding port of the server") | ||||
@click.option('--debug/--nodebug', default=True, | @click.option('--debug/--nodebug', default=True, | ||||
help="Indicates if the server should run in debug mode") | help="Indicates if the server should run in debug mode") | ||||
def launch(config_path, host, port, debug): | def launch(config_path, host, port, debug): | ||||
app = make_app(config.read(config_path, DEFAULT_CONFIG), debug=bool(debug)) | app = make_app(config.read(config_path, DEFAULT_CONFIG), debug=bool(debug)) | ||||
aiohttp.web.run_app(app, host=host, port=int(port)) | aiohttp.web.run_app(app, host=host, port=int(port)) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
launch() | launch() |