Skip to content

Commit

Permalink
database: remove debug option
Browse files Browse the repository at this point in the history
This option was intended for Moonraker developers to live test
changes to write protected namespaces.   This can be accomplished
locally with other methods, thus this option has been removed to
prevent users from compromising sections of the database.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
  • Loading branch information
Arksine committed Feb 25, 2022
1 parent 0a2c190 commit 79f867b
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions moonraker/components/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def __init__(self, config: ConfigHelper) -> None:
self.eventloop = self.server.get_event_loop()
self.namespaces: Dict[str, object] = {}
self.thread_lock = ThreadLock()
self.enable_debug = config.getboolean("enable_database_debug", False)
self.database_path = os.path.expanduser(config.get(
'database_path', "~/.moonraker_database"))
if not os.path.isdir(self.database_path):
Expand Down Expand Up @@ -137,18 +136,16 @@ def __init__(self, config: ConfigHelper) -> None:
self.forbidden_namespaces = set(self.get_item(
"moonraker", "database.forbidden_namespaces",
[]).result())
# Track debug access and unsafe shutdowns
debug_counter: int = self.get_item(
"moonraker", "database.debug_counter", 0).result()
if self.enable_debug:
debug_counter += 1
self.insert_item("moonraker", "database.debug_counter",
debug_counter)
# Remove stale debug counter
config.getboolean("enable_database_debug", False, deprecate=True)
try:
self.delete_item("moonraker", "database.debug_counter")
except Exception:
pass
# Track unsafe shutdowns
unsafe_shutdowns: int = self.get_item(
"moonraker", "database.unsafe_shutdowns", 0).result()
msg = f"Unsafe Shutdown Count: {unsafe_shutdowns}"
if debug_counter:
msg += f"; Database Debug Count: {debug_counter}"
self.server.add_log_rollover_item("database", msg)

# Increment unsafe shutdown counter. This will be reset if
Expand Down Expand Up @@ -714,10 +711,7 @@ async def _handle_item_request(self,
key: Any
valid_types: Tuple[type, ...]
if action != "GET":
if (
namespace in self.protected_namespaces and
not self.enable_debug
):
if namespace in self.protected_namespaces:
raise self.server.error(
f"Write access to namespace '{namespace}'"
" is forbidden", 403)
Expand Down

0 comments on commit 79f867b

Please sign in to comment.