Skip to content

Commit

Permalink
Merge pull request #1522 from bersace/pgconf
Browse files Browse the repository at this point in the history
pgconf: Don't confuse RESET and SET TO DEFAULT
  • Loading branch information
bersace authored Oct 17, 2024
2 parents f17b3bc + 2ad0efe commit a293436
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions agent/temboardagent/plugins/pgconf/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,21 @@ def post_settings(pgconn, new=None):

@bottle.delete("/settings/<name>")
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/<name>/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)))
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a293436

Please sign in to comment.