From 8724d5e9ed5851b957cacd2760f5057d1858fb8b Mon Sep 17 00:00:00 2001 From: Arksine <9563098+Arksine@users.noreply.github.com> Date: Tue, 30 Mar 2021 14:42:13 -0400 Subject: [PATCH] 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 --- moonraker/components/database.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/moonraker/components/database.py b/moonraker/components/database.py index 7205f36..7277caa 100644 --- a/moonraker/components/database.py +++ b/moonraker/components/database.py @@ -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")