From e879bd1490866e4f2a06d5295a74bbf94f4ad76c Mon Sep 17 00:00:00 2001
From: David Douard <david.douard@sdfa3.org>
Date: Mon, 10 Jul 2023 15:46:45 +0200
Subject: [PATCH] Rename the 'scrubber_db' config section as 'scrubber'

This is needed to make it compatible with swh.core's db upgrade tooling:
the name of the configuration section is exptected to be the swh module.
---
 swh/scrubber/cli.py            | 19 ++++++++++++++-----
 swh/scrubber/tests/test_cli.py |  4 ++--
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/swh/scrubber/cli.py b/swh/scrubber/cli.py
index 57f9b56..f6efe69 100644
--- a/swh/scrubber/cli.py
+++ b/swh/scrubber/cli.py
@@ -5,6 +5,7 @@
 
 import os
 from typing import Optional
+import warnings
 
 import click
 
@@ -30,8 +31,8 @@ def scrubber_cli_group(ctx, config_file: Optional[str]) -> None:
 
     Expected config format::
 
-        scrubber_db:
-            cls: local
+        scrubber:
+            cls: postgresql
             db: "service=..."    # libpq DSN
 
         # for storage checkers + origin locator only:
@@ -78,12 +79,20 @@ def scrubber_cli_group(ctx, config_file: Optional[str]) -> None:
 
     ctx.ensure_object(dict)
     ctx.obj["config"] = conf
-    if "scrubber_db" not in conf:
+    if "scrubber_db" in conf:
+        warnings.warn(
+            "the 'scrubber_db' configuration section has been renamed to 'scrubber'; "
+            f"please update your configuration file {config_file}",
+            DeprecationWarning,
+        )
+        conf["scrubber"] = conf.pop("scrubber_db")
+
+    if "scrubber" not in conf:
         click.echo(
-            "WARNING: You must have a scrubber_db configured in your config file.\n"
+            "WARNING: You must have a scrubber configured in your config file.\n"
         )
     else:
-        ctx.obj["db"] = get_scrubber_db(**conf["scrubber_db"])
+        ctx.obj["db"] = get_scrubber_db(**conf["scrubber"])
 
 
 @scrubber_cli_group.group(name="check")
diff --git a/swh/scrubber/tests/test_cli.py b/swh/scrubber/tests/test_cli.py
index 302b72f..63c9e0a 100644
--- a/swh/scrubber/tests/test_cli.py
+++ b/swh/scrubber/tests/test_cli.py
@@ -25,7 +25,7 @@ def invoke(
     runner = CliRunner()
 
     config = {
-        "scrubber_db": {"cls": "postgresql", "db": scrubber_db.conn.dsn},
+        "scrubber": {"cls": "postgresql", "db": scrubber_db.conn.dsn},
         "graph": {"url": "http://graph.example.org:5009/"},
     }
     if storage:
@@ -95,7 +95,7 @@ def test_help_check(mocker, scrubber_db, swh_storage):
         scrubber_cli_group, ["check", "--help"], catch_exceptions=False
     )
     output = result.output.splitlines(keepends=False)
-    msg = "WARNING: You must have a scrubber_db configured in your config file."
+    msg = "WARNING: You must have a scrubber configured in your config file."
     assert output[0] == msg
     msg = "Usage: scrubber check [OPTIONS] COMMAND [ARGS]..."
     assert output[2] == msg
-- 
GitLab