Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/server.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 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 | ||||
from typing import Any, Dict, Optional | from typing import Any, Dict, Optional | ||||
from swh.core import config | from swh.core import config | ||||
from swh.search import get_search as get_swh_search | from swh.search import get_search as get_swh_search | ||||
from swh.search.interface import SearchInterface | |||||
from swh.storage import get_storage as get_swh_storage | from swh.storage import get_storage as get_swh_storage | ||||
from swh.storage.interface import StorageInterface | |||||
graphql_cfg = None | graphql_cfg: Dict[str, Any] = {} | ||||
storage = None | storage: Optional[StorageInterface] = None | ||||
search = None | search: Optional[SearchInterface] = None | ||||
def get_storage(): | def get_storage() -> StorageInterface: | ||||
global storage | global storage | ||||
if not storage: | if not storage: | ||||
storage = get_swh_storage(**graphql_cfg["storage"]) | storage = get_swh_storage(**graphql_cfg["storage"]) | ||||
return storage | return storage | ||||
def get_search(): | def get_search() -> SearchInterface: | ||||
global search | global search | ||||
if not search: | if not search: | ||||
search = get_swh_search(**graphql_cfg["search"]) | search = get_swh_search(**graphql_cfg["search"]) | ||||
return search | return search | ||||
def load_and_check_config(config_path: Optional[str]) -> Dict[str, Any]: | def load_and_check_config(config_path: Optional[str]) -> Dict[str, Any]: | ||||
"""Check the minimal configuration is set to run the api or raise an | """Check the minimal configuration is set to run the api or raise an | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |