Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/api/server.py
# Copyright (C) 2016-2019 The Software Heritage developers | # Copyright (C) 2016-2019 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 os | import os | ||||
import aiohttp.web | import aiohttp.web | ||||
import asyncio | import asyncio | ||||
import collections | import collections | ||||
from swh.core import config | from swh.core import config | ||||
from swh.core.api.asynchronous import ( | from swh.core.api.asynchronous import ( | ||||
SWHRemoteAPI, | RPCServerApp, | ||||
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 import get_vault | from swh.vault import get_vault | ||||
from swh.vault.cookers import COOKER_TYPES | from swh.vault.cookers import COOKER_TYPES | ||||
from swh.vault.backend import NotFoundExc | from swh.vault.backend import NotFoundExc | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | res = {'bundles': bundles, 'total': len(bundles), | ||||
**{k: 0 for k in ('new', 'pending', 'done', 'failed')}, | **{k: 0 for k in ('new', 'pending', 'done', 'failed')}, | ||||
**dict(counter)} | **dict(counter)} | ||||
return encode_data(res) | return encode_data(res) | ||||
# Web server | # Web server | ||||
def make_app(backend, **kwargs): | def make_app(backend, **kwargs): | ||||
app = SWHRemoteAPI(**kwargs) | app = RPCServerApp(**kwargs) | ||||
app.router.add_route('GET', '/', index) | app.router.add_route('GET', '/', index) | ||||
# Endpoints used by the web API | # Endpoints used by the web API | ||||
app.router.add_route('GET', '/fetch/{type}/{id}', vault_fetch) | app.router.add_route('GET', '/fetch/{type}/{id}', vault_fetch) | ||||
app.router.add_route('POST', '/cook/{type}/{id}', vault_cook) | app.router.add_route('POST', '/cook/{type}/{id}', vault_cook) | ||||
app.router.add_route('GET', '/progress/{type}/{id}', vault_progress) | app.router.add_route('GET', '/progress/{type}/{id}', vault_progress) | ||||
# Endpoints used by the Cookers | # Endpoints used by the Cookers | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |