mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 19:56:53 +00:00
The same failure class as 3dee332350, in the places that only became
visible once the louder messages were gone. Nine of them are class
docstrings, which the detector used to find the first round skipped
because it walked modules and functions only.
restart_condition carried a section title inside its docstring, where
docutils allows none, and the indented block below it held a second.
cert_utils indented the closing brace of its example shallower than the
body it closes.
Two are regressions of my own first round: filters lacked the blank line
between its new literal block and the paragraph after it, and
fediwall_active had the wrong one of its two colons corrected.
make i18n-extract domain=docs now finishes with zero warnings under -W.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
55 lines
1.6 KiB
Python
55 lines
1.6 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
|