Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/api/server.py
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
@app.route("/") | @app.route("/") | ||||
def index(): | def index(): | ||||
return "SWH Vault API server" | return "SWH Vault API server" | ||||
def check_config(cfg: Dict[str, Any]) -> Dict[str, Any]: | def check_config(cfg: Dict[str, Any]) -> Dict[str, Any]: | ||||
"""Ensure the configuration is ok to run a local vault server, and propagate defaults. | """Ensure the configuration is ok to run a postgresql vault server, and propagate | ||||
defaults. | |||||
Raises: | Raises: | ||||
EnvironmentError if the configuration is not for local instance | EnvironmentError if the configuration is not for postgresql instance | ||||
ValueError if one of the following keys is missing: vault, cache, storage, | ValueError if one of the following keys is missing: vault, cache, storage, | ||||
scheduler | scheduler | ||||
Returns: | Returns: | ||||
New configuration dict to instantiate a local vault server instance. | New configuration dict to instantiate a postgresql vault server instance. | ||||
""" | """ | ||||
cfg = cfg.copy() | cfg = cfg.copy() | ||||
if "vault" not in cfg: | if "vault" not in cfg: | ||||
raise ValueError("missing 'vault' configuration") | raise ValueError("missing 'vault' configuration") | ||||
vcfg = cfg["vault"] | vcfg = cfg["vault"] | ||||
if vcfg["cls"] != "local": | if vcfg["cls"] not in ("local", "postgresql"): | ||||
raise EnvironmentError( | raise EnvironmentError( | ||||
"The vault backend can only be started with a 'local' configuration", | "The vault backend can only be started with a 'postgresql' configuration", | ||||
) | ) | ||||
# TODO: Soft-deprecation of args key. Remove when ready. | # TODO: Soft-deprecation of args key. Remove when ready. | ||||
vcfg.update(vcfg.get("args", {})) | vcfg.update(vcfg.get("args", {})) | ||||
# Default to top-level value if any | # Default to top-level value if any | ||||
vcfg = {**cfg, **vcfg} | vcfg = {**cfg, **vcfg} | ||||
Show All 29 Lines |