Files
computer-playbook/utils/roles/validation/deploy_id.py
kevinveenbirkenbachandClaude Fable 5 40e553069d refactor(structure): nest prefix-grouped sibling files into subfolders
Move files that share a delimiter-bounded name prefix within a folder (threshold 2) into a subfolder named after the prefix, dropping the prefix from the filename. Covers plugins/filter (docker, generate, has, merge, get/all), env handler subpackages, utils/roles/entity, utils/tests/swarm/write, role SQL/scripts/templates, keycloak/mailu task-includes, shared tasks/utils/load, and CI scripts. Update every import, query_file/script/include_tasks/src/lookup target, compose bind mount, and python -m path to the new locations.

Extend the prefix-grouped-files lint to threshold 2 with dir-level .nocheck and file-head nocheck opt-outs, and skip groups whose shortest member's stem equals the shared prefix. Keep flat only where a loader forbids nesting: WordPress mu-plugins and the docs/requirements namespace. Ansible filter discovery is recursive, so nested filters stay Jinja-resolvable.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-14 20:00:03 +02:00

54 lines
1.5 KiB
Python

"""
Utility for validating deployment application IDs against defined roles and inventory.
"""
from __future__ import annotations
from plugins.filter.get.all.application_ids import get_all_application_ids
from utils.inventory.groups import inventory_has_group
from . import PROJECT_ROOT
class ValidDeployId:
def __init__(self) -> None:
"""
Always resolve roles/ from the repository root, independent of CWD.
"""
repo_root = PROJECT_ROOT
roles_dir = repo_root / "roles"
if not roles_dir.is_dir():
raise RuntimeError(
f"roles directory not found at expected location: {roles_dir}"
)
self.roles_dir = roles_dir
self.valid_ids = set(get_all_application_ids(str(roles_dir)))
def validate(
self, inventory_path: str, ids: list[str]
) -> dict[str, dict[str, bool]]:
"""
Validate a list of application IDs against both role definitions and inventory.
Returns:
{
"app1": {"in_roles": False, "in_inventory": True},
"app2": {"in_roles": True, "in_inventory": False},
}
"""
invalid: dict[str, dict[str, bool]] = {}
for app_id in ids:
in_roles = app_id in self.valid_ids
in_inventory = inventory_has_group(inventory_path, app_id)
if not (in_roles and in_inventory):
invalid[app_id] = {
"in_roles": in_roles,
"in_inventory": in_inventory,
}
return invalid