From e5dfc2378f812548fad9e909f392c3ebe02d78b5 Mon Sep 17 00:00:00 2001
From: "Antoine R. Dumont (@ardumont)" <ardumont@softwareheritage.org>
Date: Fri, 29 Jul 2022 09:53:34 +0200
Subject: [PATCH] api/server: Allow 'postgresql' configuration key entry

'local' has been deprecated for a while.
---
 swh/vault/api/server.py        | 11 ++++++-----
 swh/vault/tests/test_server.py |  9 ++++++---
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/swh/vault/api/server.py b/swh/vault/api/server.py
index 91584c8..5b58d61 100644
--- a/swh/vault/api/server.py
+++ b/swh/vault/api/server.py
@@ -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.
diff --git a/swh/vault/tests/test_server.py b/swh/vault/tests/test_server.py
index 184f426..1f67ccf 100644
--- a/swh/vault/tests/test_server.py
+++ b/swh/vault/tests/test_server.py
@@ -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
 
 
-- 
GitLab