78 lines
2.1 KiB
Python
78 lines
2.1 KiB
Python
from db_logging import log_change
|
|
|
|
|
|
def set_name(cursor, name):
|
|
cursor.execute("DELETE FROM metadata")
|
|
cursor.execute(
|
|
"INSERT INTO metadata (name) VALUES (%s)",
|
|
(name,)
|
|
)
|
|
log_change(cursor, f"Updated metadata name to {name}")
|
|
|
|
|
|
def get_name(cursor):
|
|
cursor.execute("SELECT name FROM metadata LIMIT 1")
|
|
row = cursor.fetchone()
|
|
return row["name"] if row else None
|
|
|
|
|
|
def set_comment(cursor, comment):
|
|
cursor.execute("DELETE FROM metadata")
|
|
cursor.execute(
|
|
"INSERT INTO metadata (comment) VALUES (%s)",
|
|
(comment,)
|
|
)
|
|
log_change(cursor, f"Updated metadata comment to {comment}")
|
|
|
|
|
|
def get_comment(cursor):
|
|
cursor.execute("SELECT comment FROM metadata LIMIT 1")
|
|
row = cursor.fetchone()
|
|
return row["comment"] if row else None
|
|
|
|
|
|
def set_keys(cursor, public_key, private_key):
|
|
cursor.execute("DELETE FROM metadata")
|
|
cursor.execute(
|
|
"""
|
|
INSERT INTO metadata (public_key, private_key)
|
|
VALUES (%s, %s)
|
|
""",
|
|
(public_key, private_key)
|
|
)
|
|
log_change(cursor, "Updated metadata keys")
|
|
|
|
|
|
def get_public_key(cursor):
|
|
cursor.execute("SELECT public_key FROM metadata LIMIT 1")
|
|
row = cursor.fetchone()
|
|
return row["public_key"] if row else None
|
|
|
|
|
|
def get_private_key(cursor):
|
|
cursor.execute("SELECT private_key FROM metadata LIMIT 1")
|
|
row = cursor.fetchone()
|
|
return row["private_key"] if row else None
|
|
|
|
|
|
def set_defense_p(cursor, defense_p: bool):
|
|
"""Set the metadata defense_p flag.
|
|
|
|
This table is treated as a singleton row at the application level.
|
|
Current convention in this codebase is to wipe and re-insert.
|
|
"""
|
|
cursor.execute("DELETE FROM metadata")
|
|
cursor.execute(
|
|
"INSERT INTO metadata (defense_p) VALUES (%s)",
|
|
(defense_p,)
|
|
)
|
|
log_change(cursor, f"Updated metadata defense_p to {defense_p}")
|
|
|
|
|
|
def get_defense_p(cursor) -> bool:
|
|
cursor.execute("SELECT defense_p FROM metadata LIMIT 1")
|
|
row = cursor.fetchone()
|
|
if not row or row["defense_p"] is None:
|
|
return False
|
|
return bool(row["defense_p"])
|