Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/api/server.py
Show All 11 Lines | |||||
import aiohttp.web | import aiohttp.web | ||||
from swh.core.api.asynchronous import RPCServerApp | from swh.core.api.asynchronous import RPCServerApp | ||||
from swh.core.config import config_basepath, merge_configs, read_raw_config | from swh.core.config import config_basepath, merge_configs, read_raw_config | ||||
from swh.vault import get_vault as get_swhvault | from swh.vault import get_vault as get_swhvault | ||||
from swh.vault.backend import NotFoundExc | from swh.vault.backend import NotFoundExc | ||||
from swh.vault.interface import VaultInterface | from swh.vault.interface import VaultInterface | ||||
from .serializers import DECODERS, ENCODERS | |||||
# do not define default services here | # do not define default services here | ||||
DEFAULT_CONFIG = { | DEFAULT_CONFIG = { | ||||
"client_max_size": 1024 ** 3, | "client_max_size": 1024 ** 3, | ||||
} | } | ||||
vault = None | vault = None | ||||
app = None | app = None | ||||
def get_vault(config: Optional[Dict[str, Any]] = None) -> VaultInterface: | def get_vault(config: Optional[Dict[str, Any]] = None) -> VaultInterface: | ||||
global vault | global vault | ||||
if not vault: | if not vault: | ||||
assert config is not None | assert config is not None | ||||
vault = get_swhvault(**config) | vault = get_swhvault(**config) | ||||
return vault | return vault | ||||
class VaultServerApp(RPCServerApp): | class VaultServerApp(RPCServerApp): | ||||
client_exception_classes = (NotFoundExc,) | client_exception_classes = (NotFoundExc,) | ||||
extra_type_decoders = DECODERS | |||||
extra_type_encoders = ENCODERS | |||||
@asyncio.coroutine | @asyncio.coroutine | ||||
def index(request): | def index(request): | ||||
return aiohttp.web.Response(body="SWH Vault API server") | return aiohttp.web.Response(body="SWH Vault API server") | ||||
def check_config(cfg: Dict[str, Any]) -> Dict[str, Any]: | def check_config(cfg: Dict[str, Any]) -> Dict[str, Any]: | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |