Files
computer-playbook/utils/env/handlers/infinito/ca/cert_host.py
kevinveenbirkenbach 9b78933153 refactor(env): group the CA handlers into their own subpackage
The two ca_* handlers sat flat in utils/env/handlers/infinito, which the
prefix-grouping lint rejects, and the bundle-candidates comment exceeded
the .env comment length limit.
2026-08-22 20:24:53 +02:00

37 lines
1.3 KiB
Python

"""INFINITO_CA_CERT_HOST: host path of the self-signed root CA cert.
Derived from the ca_trust_paths SPOT plus SOFTWARE_NAME (group_vars); consumed
by scripts/system/tls/trust/*.sh so the path never lives in shell literals.
SOFTWARE_NAME is line-parsed instead of yaml-loaded: the env generator runs on
the bare bootstrap python before any dependency (PyYAML) is installed.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from plugins.filter.ca_trust_paths import ca_cert_host
from utils import PROJECT_ROOT
from utils.cache.files import read_text
if TYPE_CHECKING:
from utils.env.builder import BuildContext, EnvBuilder
KEY = "INFINITO_CA_CERT_HOST"
COMMENT = "Host path of the self-signed root CA cert (ca_trust_paths SPOT)."
_GENERAL_VARS = "group_vars/all/00_general.yml"
def _software_domain() -> str:
for line in read_text(str(PROJECT_ROOT / _GENERAL_VARS)).splitlines():
if not line.startswith("SOFTWARE_NAME:"):
continue
value = line.split(":", 1)[1].split("#", 1)[0].strip()
return value.strip("\"'").lower()
raise RuntimeError(f"SOFTWARE_NAME not found in {_GENERAL_VARS}")
def apply(eb: EnvBuilder, ctx: BuildContext) -> None:
eb.set(KEY, ca_cert_host(_software_domain()), comment=COMMENT)