Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/api/server.py
# Copyright (C) 2016-2018 The Software Heritage developers | # Copyright (C) 2016-2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import aiohttp.web | import aiohttp.web | ||||
import asyncio | import asyncio | ||||
import click | |||||
import collections | import collections | ||||
from swh.core import config | from swh.core import config | ||||
from swh.core.api_async import (SWHRemoteAPI, | from swh.core.api_async import (SWHRemoteAPI, | ||||
encode_data_server as encode_data, | encode_data_server as encode_data, | ||||
decode_request) | decode_request) | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.vault.cookers import COOKER_TYPES | from swh.vault.cookers import COOKER_TYPES | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | |||||
def make_app_from_configfile(config_path=DEFAULT_CONFIG_PATH, **kwargs): | def make_app_from_configfile(config_path=DEFAULT_CONFIG_PATH, **kwargs): | ||||
global api_cfg | global api_cfg | ||||
if not api_cfg: | if not api_cfg: | ||||
api_cfg = config.read(config_path, DEFAULT_CONFIG) | api_cfg = config.read(config_path, DEFAULT_CONFIG) | ||||
return make_app(api_cfg, **kwargs) | return make_app(api_cfg, **kwargs) | ||||
@click.command() | |||||
@click.argument('config-path', required=1) | |||||
@click.option('--host', default='0.0.0.0', help="Host to run the server") | |||||
@click.option('--port', default=5005, type=click.INT, | |||||
help="Binding port of the server") | |||||
@click.option('--debug/--nodebug', default=True, | |||||
help="Indicates if the server should run in debug mode") | |||||
def launch(config_path, host, port, debug): | |||||
app = make_app(config.read(config_path, DEFAULT_CONFIG), debug=bool(debug)) | |||||
aiohttp.web.run_app(app, host=host, port=int(port)) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
launch() | print('Deprecated. Use swh-vault ') |