From b0099d9d719ccdc396e198130610f6d9cf7f3ae2 Mon Sep 17 00:00:00 2001 From: Linus Vogel Date: Thu, 14 May 2026 19:50:05 +0200 Subject: [PATCH] refactor of hostgroup router --- pillar_tool/routers/hostgroup.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pillar_tool/routers/hostgroup.py b/pillar_tool/routers/hostgroup.py index bc39e8d..81beee2 100644 --- a/pillar_tool/routers/hostgroup.py +++ b/pillar_tool/routers/hostgroup.py @@ -43,7 +43,7 @@ def hostgroups_get(req: Request): ancestors = [host] while ancestors[-1].parent_id is not None: ancestors.append(all_hostgroups[ancestors[-1].parent_id]) - all_hostgroup_names.append('/'.join(map(lambda x: x.name, reversed(ancestors)))) + all_hostgroup_names.append('/'.join(map(lambda x: x.name, reversed(ancestors)))) # type: ignore print("[DEBUG] hostgroups_get: resolved hierarchical names for {} host group(s): {}".format(len(all_hostgroup_names), all_hostgroup_names)) @@ -73,9 +73,9 @@ def hostgroup_get(req: Request, name: str, params: HostgroupParams): # decode the path last = None ancestors = [] - path = [] + path: list[str] = [] if params: - path = split_and_validate_path(params.path) if params.path else [] + path = (split_and_validate_path(params.path) or []) if params.path else [] if len(path) > 0: print("[DEBUG] hostgroup_get: resolving parent path with {} segment(s): {}".format(len(path), path)) @@ -184,7 +184,7 @@ def hostgroup_delete(req: Request, name: str, params: HostgroupParams = Depends( """ db = req.state.db - labels = split_and_validate_path(params.path) or [] + labels = (split_and_validate_path(params.path) or []) if params.path is not None else [] labels.append(name) last = None @@ -208,10 +208,10 @@ def hostgroup_delete(req: Request, name: str, params: HostgroupParams = Depends( children_stmt = select(Host).where(Host.parent_id == last) children: list[Host] = list(map(lambda x: x[0], db.execute(children_stmt).fetchall())) if len(children) != 0: - print("[DEBUG] hostgroup_delete: ERROR - Cannot delete hostgroup '{}' because it has {} child(ren): {}. All children must be deleted first.".format(labels[-1], len(children), [ '/'.join(labels + [x.name]) for x in children ])) + print("[DEBUG] hostgroup_delete: ERROR - Cannot delete hostgroup '{}' because it has {} child(ren): {}. All children must be deleted first.".format(labels[-1], len(children), [ '/'.join(labels + [x.name]) for x in children ])) # type: ignore return JSONResponse(status_code=400, content={ 'message': "Cannot delete a hostgroup that still has children", - 'children': [ '/'.join(labels + [x.name]) for x in children ] + 'children': [ '/'.join(labels + [x.name]) for x in children ] # type: ignore }) print("[DEBUG] hostgroup_delete: deleting hostgroup '{}' (id={}) with no remaining children".format(labels[-1], last))