diff --git a/PKG-INFO b/PKG-INFO index bc3f006..79689b9 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,31 +1,31 @@ Metadata-Version: 2.1 Name: swh.vault -Version: 0.4.0 +Version: 0.5.0 Summary: Software Heritage vault Home-page: https://forge.softwareheritage.org/diffusion/DVAU/ Author: Software Heritage developers Author-email: swh-devel@inria.fr License: UNKNOWN Project-URL: Bug Reports, https://forge.softwareheritage.org/maniphest Project-URL: Funding, https://www.softwareheritage.org/donate Project-URL: Source, https://forge.softwareheritage.org/source/swh-vault Project-URL: Documentation, https://docs.softwareheritage.org/devel/swh-vault/ Description: swh-vault ========= User-facing service that allows to retrieve parts of the archive as self-contained bundles. See the [documentation](https://docs.softwareheritage.org/devel/swh-vault/index.html) for more details. Platform: UNKNOWN Classifier: Programming Language :: Python :: 3 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) Classifier: Operating System :: OS Independent Classifier: Development Status :: 5 - Production/Stable Requires-Python: >=3.7 Description-Content-Type: text/markdown Provides-Extra: testing diff --git a/swh.vault.egg-info/PKG-INFO b/swh.vault.egg-info/PKG-INFO index bc3f006..79689b9 100644 --- a/swh.vault.egg-info/PKG-INFO +++ b/swh.vault.egg-info/PKG-INFO @@ -1,31 +1,31 @@ Metadata-Version: 2.1 Name: swh.vault -Version: 0.4.0 +Version: 0.5.0 Summary: Software Heritage vault Home-page: https://forge.softwareheritage.org/diffusion/DVAU/ Author: Software Heritage developers Author-email: swh-devel@inria.fr License: UNKNOWN Project-URL: Bug Reports, https://forge.softwareheritage.org/maniphest Project-URL: Funding, https://www.softwareheritage.org/donate Project-URL: Source, https://forge.softwareheritage.org/source/swh-vault Project-URL: Documentation, https://docs.softwareheritage.org/devel/swh-vault/ Description: swh-vault ========= User-facing service that allows to retrieve parts of the archive as self-contained bundles. See the [documentation](https://docs.softwareheritage.org/devel/swh-vault/index.html) for more details. Platform: UNKNOWN Classifier: Programming Language :: Python :: 3 Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3) Classifier: Operating System :: OS Independent Classifier: Development Status :: 5 - Production/Stable Requires-Python: >=3.7 Description-Content-Type: text/markdown Provides-Extra: testing diff --git a/swh/vault/api/server.py b/swh/vault/api/server.py index cbe0329..baa565f 100644 --- a/swh/vault/api/server.py +++ b/swh/vault/api/server.py @@ -1,135 +1,128 @@ # Copyright (C) 2016-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information from __future__ import annotations import asyncio import os from typing import Any, Dict, Optional import aiohttp.web from swh.core.api.asynchronous import RPCServerApp from swh.core.config import config_basepath, merge_configs, read_raw_config from swh.vault import get_vault as get_swhvault from swh.vault.backend import NotFoundExc from swh.vault.interface import VaultInterface +# do not define default services here DEFAULT_CONFIG = { - "storage": {"cls": "remote", "url": "http://localhost:5002/"}, - "cache": { - "cls": "pathslicing", - "root": "/srv/softwareheritage/vault", - "slicing": "0:1/1:5", - }, "client_max_size": 1024 ** 3, - "vault": {"cls": "local", "db": "dbname=softwareheritage-vault-dev",}, - "scheduler": {"cls": "remote", "url": "http://localhost:5008/"}, } vault = None app = None def get_vault(config: Optional[Dict[str, Any]] = None) -> VaultInterface: global vault if not vault: assert config is not None vault = get_swhvault(**config) return vault class VaultServerApp(RPCServerApp): client_exception_classes = (NotFoundExc,) @asyncio.coroutine def index(request): return aiohttp.web.Response(body="SWH Vault API server") def check_config(cfg: Dict[str, Any]) -> Dict[str, Any]: """Ensure the configuration is ok to run a local vault server, and propagate defaults. Raises: EnvironmentError if the configuration is not for local instance ValueError if one of the following keys is missing: vault, cache, storage, scheduler Returns: New configuration dict to instantiate a local vault server instance. """ cfg = cfg.copy() if "vault" not in cfg: raise ValueError("missing 'vault' configuration") vcfg = cfg["vault"] if vcfg["cls"] != "local": raise EnvironmentError( "The vault backend can only be started with a 'local' configuration", ) # TODO: Soft-deprecation of args key. Remove when ready. vcfg.update(vcfg.get("args", {})) # Default to top-level value if any if "cache" not in vcfg: vcfg["cache"] = cfg.get("cache") if "storage" not in vcfg: vcfg["storage"] = cfg.get("storage") if "scheduler" not in vcfg: vcfg["scheduler"] = cfg.get("scheduler") if "client_max_size" not in vcfg: vcfg["client_max_size"] = cfg.get("client_max_size") for key in ("cache", "storage", "scheduler"): if not vcfg.get(key): raise ValueError(f"invalid configuration: missing {key} config entry.") return vcfg def make_app(config: Dict[str, Any]) -> VaultServerApp: """Ensure the configuration is ok, then instantiate the server application """ config = check_config(config) app = VaultServerApp( __name__, backend_class=VaultInterface, backend_factory=lambda: get_vault(config), client_max_size=config["client_max_size"], ) app.router.add_route("GET", "/", index) return app def make_app_from_configfile( config_path: Optional[str] = None, **kwargs ) -> VaultServerApp: """Load and check configuration if ok, then instantiate (once) a vault server application. """ global app if not app: config_path = os.environ.get("SWH_CONFIG_FILENAME", config_path) if not config_path: raise ValueError("Missing configuration path.") if not os.path.isfile(config_path): raise ValueError(f"Configuration path {config_path} should exist.") app_config = read_raw_config(config_basepath(config_path)) app_config = merge_configs(DEFAULT_CONFIG, app_config) app = make_app(app_config) return app if __name__ == "__main__": print("Deprecated. Use swh-vault ") diff --git a/swh/vault/cli.py b/swh/vault/cli.py index f3e1279..e99322b 100644 --- a/swh/vault/cli.py +++ b/swh/vault/cli.py @@ -1,86 +1,76 @@ # Copyright (C) 2015-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information # WARNING: do not import unnecessary things here to keep cli startup time under # control import logging import click from swh.core.cli import CONTEXT_SETTINGS, AliasedGroup from swh.core.cli import swh as swh_cli_group CFG_HELP = """Software Heritage Vault RPC server.""" @swh_cli_group.group(name="vault", context_settings=CONTEXT_SETTINGS, cls=AliasedGroup) @click.pass_context def vault(ctx): """Software Heritage Vault tools.""" pass @vault.command(name="rpc-serve", help=CFG_HELP) @click.option( "--config-file", "-C", default=None, metavar="CONFIGFILE", type=click.Path(exists=True, dir_okay=False,), help="Configuration file.", ) -@click.option( - "--no-stdout", is_flag=True, default=False, help="Do NOT output logs on the console" -) @click.option( "--host", default="0.0.0.0", metavar="IP", show_default=True, help="Host ip address to bind the server on", ) @click.option( "--port", default=5005, type=click.INT, metavar="PORT", help="Binding port of the server", ) @click.option( "--debug/--no-debug", default=True, help="Indicates if the server should run in debug mode", ) @click.pass_context -def serve(ctx, config_file, no_stdout, host, port, debug): +def serve(ctx, config_file, host, port, debug): import aiohttp - from swh.scheduler.celery_backend.config import setup_log_handler from swh.vault.api.server import make_app_from_configfile ctx.ensure_object(dict) - setup_log_handler( - loglevel=ctx.obj.get("log_level", logging.INFO), - colorize=False, - format="[%(levelname)s] %(name)s -- %(message)s", - log_console=not no_stdout, - ) try: app = make_app_from_configfile(config_file, debug=debug) except EnvironmentError as e: click.echo(e.msg, err=True) ctx.exit(1) aiohttp.web.run_app(app, host=host, port=int(port)) def main(): logging.basicConfig() return serve(auto_envvar_prefix="SWH_VAULT") if __name__ == "__main__": main()