machine: move default allowed services to an asset file

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-03-15 15:04:34 -04:00
parent 98bb40bd80
commit affe196ff6
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
2 changed files with 20 additions and 22 deletions

View File

@ -0,0 +1,10 @@
klipper_mcu
webcamd
MoonCord
KlipperScreen
moonraker-telegram-bot
moonraker-obico
sonar
crowsnest
octoeverywhere
ratos-configurator

View File

@ -56,18 +56,6 @@ if TYPE_CHECKING:
SudoReturn = Union[Awaitable[Tuple[str, bool]], Tuple[str, bool]]
SudoCallback = Callable[[], SudoReturn]
DEFAULT_ALLOWED_SERVICES = [
"klipper_mcu",
"webcamd",
"MoonCord",
"KlipperScreen",
"moonraker-telegram-bot",
"moonraker-obico",
"sonar",
"crowsnest",
"octoeverywhere",
"ratos-configurator"
]
CGROUP_PATH = "/proc/1/cgroup"
SCHED_PATH = "/proc/1/sched"
SYSTEMD_PATH = "/etc/systemd/system"
@ -198,20 +186,20 @@ class Machine:
fpath = pathlib.Path(data_path).joinpath("moonraker.asvc")
fm: FileManager = self.server.lookup_component("file_manager")
fm.add_reserved_path("allowed_services", fpath, False)
default_svcs = source_info.read_asset("default_allowed_services") or ""
try:
if not fpath.exists():
fpath.write_text("\n".join(DEFAULT_ALLOWED_SERVICES))
fpath.write_text(default_svcs)
data = fpath.read_text()
except Exception:
logging.exception("Failed to read allowed_services.txt")
self._allowed_services = DEFAULT_ALLOWED_SERVICES
else:
svcs = [svc.strip() for svc in data.split("\n") if svc.strip()]
for svc in svcs:
if svc.endswith(".service"):
svc = svc.rsplit(".", 1)[0]
if svc not in self._allowed_services:
self._allowed_services.append(svc)
logging.exception("Failed to read moonraker.asvc")
data = default_svcs
svcs = [svc.strip() for svc in data.split("\n") if svc.strip()]
for svc in svcs:
if svc.endswith(".service"):
svc = svc.rsplit(".", 1)[0]
if svc not in self._allowed_services:
self._allowed_services.append(svc)
def _update_log_rollover(self, log: bool = False) -> None:
sys_info_msg = "\nSystem Info:"