From 30e2ec04b7ab1d2f1ad3c7e9b2dd9d511604f32c Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Fri, 7 Oct 2022 07:16:05 -0400 Subject: [PATCH] app: add support for debug endpoints Signed-off-by: Eric Callahan --- moonraker/app.py | 18 ++++++++++++++++++ moonraker/moonraker.py | 1 + 2 files changed, 19 insertions(+) diff --git a/moonraker/app.py b/moonraker/app.py index 69374a6..d31d8ad 100644 --- a/moonraker/app.py +++ b/moonraker/app.py @@ -395,6 +395,24 @@ class MoonrakerApp: params['location_prefix'] = location_prefix self.mutable_router.add_handler(pattern, FileUploadHandler, params) + def register_debug_handler( + self, + uri: str, + request_methods: List[str], + callback: APICallback, + transports: List[str] = ALL_TRANSPORTS, + wrap_result: bool = True + ) -> None: + if not self.server.is_debug_enabled(): + return + if not uri.startswith("/debug"): + raise self.server.error( + "Debug Endpoints must be registerd in the '/debug' path" + ) + self.register_local_handler( + uri, request_methods, callback, transports, wrap_result + ) + def remove_handler(self, endpoint: str) -> None: api_def = self.api_cache.pop(endpoint, None) if api_def is not None: diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index f8bf680..e03e57b 100755 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -88,6 +88,7 @@ class Server: # Tornado Application/Server self.moonraker_app = app = MoonrakerApp(config) self.register_endpoint = app.register_local_handler + self.register_debug_endpoint = app.register_debug_handler self.register_static_file_handler = app.register_static_file_handler self.register_upload_handler = app.register_upload_handler self.register_api_transport = app.register_api_transport