From 2ad0efe16c3ddb148d2eef4e2c525f580c0ef7f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20BERSAC?= Date: Thu, 17 Oct 2024 15:04:58 +0200 Subject: [PATCH] pgconf: Don't confuse RESET and SET TO DEFAULT --- agent/temboardagent/plugins/pgconf/routes.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/agent/temboardagent/plugins/pgconf/routes.py b/agent/temboardagent/plugins/pgconf/routes.py index 794be278b..34c070a9f 100644 --- a/agent/temboardagent/plugins/pgconf/routes.py +++ b/agent/temboardagent/plugins/pgconf/routes.py @@ -52,8 +52,21 @@ def post_settings(pgconn, new=None): @bottle.delete("/settings/") def delete_settings(pgconn, name): - """Reset settings to default.""" - default_app().push_audit_notification(f"Reseting {name} to default.") + """Restore settings to default.""" + default_app().push_audit_notification(f"Restoring {name} to default.") + sql = psycopg2.sql.SQL("""ALTER SYSTEM SET {} TO DEFAULT;""") + try: + pgconn.execute(sql.format(psycopg2.sql.Identifier(name))) + except psycopg2.DatabaseError as e: + return HTTPError(406, e.pgerror) + + post_reload(pgconn) + + +@bottle.post("/settings//reset") +def post_settings_reset(pgconn, name): + """Reset settings to current value.""" + default_app().push_audit_notification(f"Reseting {name} to current.") sql = psycopg2.sql.SQL("""ALTER SYSTEM RESET {};""") try: pgconn.execute(sql.format(psycopg2.sql.Identifier(name))) @@ -95,7 +108,7 @@ def post_configuration(pgconn): raise HTTPError(406, "Parameter 'settings' not sent.") reset = {i["name"] for i in request.json["settings"] if not i["setting"]} for name in reset: - out = delete_settings(pgconn, name) + out = post_settings_reset(pgconn, name) if out: return out