summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-09-19 00:44:11 +0300
committerMaxim Devaev <[email protected]>2022-09-19 00:44:11 +0300
commit6f4131c3f68fe22e4932425c67706a9c82e231bb (patch)
treee10f07d6c7d1e8f7b719c2b9f499068e69a9d895 /kvmd
parent0afc513de8931fc63565f766a7d1840f6f172f6d (diff)
option to disable log reader
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py4
-rw-r--r--kvmd/apps/kvmd/__init__.py2
-rw-r--r--kvmd/apps/kvmd/api/log.py11
-rw-r--r--kvmd/apps/kvmd/server.py2
4 files changed, 16 insertions, 3 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index ffd8daae..6bac90e2 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -381,6 +381,10 @@ def _get_config_scheme() -> dict:
},
},
+ "log_reader": {
+ "enabled": Option(True, type=valid_bool),
+ },
+
"hid": {
"type": Option("", type=valid_stripped_string_not_empty),
diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py
index 5249bdd7..dcc9efea 100644
--- a/kvmd/apps/kvmd/__init__.py
+++ b/kvmd/apps/kvmd/__init__.py
@@ -82,7 +82,7 @@ def main(argv: (list[str] | None)=None) -> None:
enabled=config.auth.enabled,
),
info_manager=InfoManager(global_config),
- log_reader=LogReader(),
+ log_reader=(LogReader() if config.log_reader.enabled else None),
user_gpio=UserGpio(config.gpio, global_config.otg),
ocr=TesseractOcr(**config.ocr._unpack()),
diff --git a/kvmd/apps/kvmd/api/log.py b/kvmd/apps/kvmd/api/log.py
index af80bee9..480fe1d4 100644
--- a/kvmd/apps/kvmd/api/log.py
+++ b/kvmd/apps/kvmd/api/log.py
@@ -23,6 +23,8 @@
from aiohttp.web import Request
from aiohttp.web import StreamResponse
+from ....errors import OperationError
+
from ....htserver import exposed_http
from ....htserver import start_streaming
@@ -33,14 +35,21 @@ from ..logreader import LogReader
# =====
+class LogReaderDisabledError(OperationError):
+ def __init__(self) -> None:
+ super().__init__("LogReader is disabled")
+
+
class LogApi:
- def __init__(self, log_reader: LogReader) -> None:
+ def __init__(self, log_reader: (LogReader | None)) -> None:
self.__log_reader = log_reader
# =====
@exposed_http("GET", "/log")
async def __log_handler(self, request: Request) -> StreamResponse:
+ if self.__log_reader is None:
+ raise LogReaderDisabledError()
seek = valid_log_seek(request.query.get("seek", 0))
follow = valid_bool(request.query.get("follow", False))
response = await start_streaming(request, "text/plain")
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index 84724407..c02999e4 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -128,7 +128,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
self,
auth_manager: AuthManager,
info_manager: InfoManager,
- log_reader: LogReader,
+ log_reader: (LogReader | None),
user_gpio: UserGpio,
ocr: TesseractOcr,