Skip to content
Snippets Groups Projects
Verified Commit e5dfc237 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

api/server: Allow 'postgresql' configuration key entry

'local' has been deprecated for a while.
parent ceb26750
No related branches found
No related tags found
1 merge request!159api/server: Allow 'postgresql' configuration key entry
......@@ -61,15 +61,16 @@ def index():
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:
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,
scheduler
Returns:
New configuration dict to instantiate a local vault server instance.
New configuration dict to instantiate a postgresql vault server instance.
"""
cfg = cfg.copy()
......@@ -78,9 +79,9 @@ def check_config(cfg: Dict[str, Any]) -> Dict[str, Any]:
raise ValueError("missing 'vault' configuration")
vcfg = cfg["vault"]
if vcfg["cls"] != "local":
if vcfg["cls"] not in ("local", "postgresql"):
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.
......
......@@ -22,7 +22,7 @@ def swh_vault_server_config(swh_vault_config: Dict[str, Any]) -> Dict[str, Any]:
"""Returns a vault server configuration, with ``storage``, ``scheduler`` and
``cache`` set at the toplevel"""
return {
"vault": {"cls": "local", "db": swh_vault_config["db"]},
"vault": {"cls": "postgresql", "db": swh_vault_config["db"]},
"client_max_size": 1024**3,
**{k: v for k, v in swh_vault_config.items() if k != "db"},
}
......@@ -160,14 +160,17 @@ def test_check_config_missing_vault_configuration() -> None:
def test_check_config_not_local() -> None:
"""Wrong configuration raises"""
expected_error = (
"The vault backend can only be started with a 'local' configuration"
"The vault backend can only be started with a 'postgresql' configuration"
)
with pytest.raises(EnvironmentError, match=expected_error):
check_config({"vault": {"cls": "remote"}})
def test_check_config_ok(swh_vault_server_config) -> None:
@pytest.mark.parametrize("clazz", ["local", "postgresql"])
def test_check_config_ok(swh_vault_server_config, clazz) -> None:
"""Check that the default config is accepted"""
config = swh_vault_server_config.copy()
config["vault"]["cls"] = clazz
assert check_config(swh_vault_server_config) is not None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment