database: add "enable_database_debug" option

This allows protected namespaces to be modified externally.  This is for dev use only, modifying protected namespaces can potentially corrupt the database.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-03-30 14:42:13 -04:00
parent da9401dd1a
commit 8724d5e9ed
1 changed files with 10 additions and 1 deletions

View File

@ -46,6 +46,7 @@ class MoonrakerDatabase:
def __init__(self, config):
self.server = config.get_server()
self.namespaces = {}
self.enable_debug = config.get("enable_database_debug", False)
self.database_path = os.path.expanduser(config.get(
'database_path', "~/.moonraker_database"))
if not os.path.isdir(self.database_path):
@ -69,6 +70,13 @@ class MoonrakerDatabase:
db=mrdb)
self.protected_namespaces = set(self.get_item(
"moonraker", "database.protected_namespaces", ["moonraker"]))
debug_counter = self.get_item("moonraker", "database.debug_counter", 0)
if self.enable_debug:
debug_counter += 1
self.insert_item("moonraker", "database.debug_counter",
debug_counter)
if debug_counter:
logging.info(f"Database Debug Count: {debug_counter}")
self.server.register_endpoint(
"/server/database/list", ['GET'], self._handle_list_request)
self.server.register_endpoint(
@ -273,7 +281,8 @@ class MoonrakerDatabase:
action = web_request.get_action()
namespace = web_request.get_str("namespace")
if action != "GET":
if namespace in self.protected_namespaces:
if namespace in self.protected_namespaces and \
not self.enable_debug:
raise self.server.error(
f"Namespace '{namespace}' is write protected")
key = web_request.get("key")