Files
computer-playbook/utils/tests/swarm/write/hosts_entries.py
T
kevinveenbirkenbachandClaude Opus 5 eda9474e37 test(lint): refuse a default in os.environ.get, and resolve the 25 sites
The deploy decides what ADAPTER_PORT or OPENWEBUI_ADMIN_NAME is and
writes it into the environment. A default in the reader is a second place
that value lives, and it is the one nobody greps for. os.environ["X"]
fails loudly on a missing key, which is the behaviour a misconfiguration
deserves.

Empty values stay free, because they add no second source and only say
absent: "", None, False, 0, the empty containers, and the "[]"/"{}" a
json.loads reader hands an absent variable. A default that is itself an
environ.get is free too, since it reads the one source again under
another key; a literal ending such a chain is still reported. Detection
runs on the parsed tree, so a call split across lines reads the same.

Five sites were real duplication and lost their default: the adapter
port, openwebui's admin name (a role that runs as a bot user), odoo's
OIDC uid field, seaweedfs' public-primary flag, and the swarm hosts
entry IP. Nineteen carry a nocheck naming why the value is not the
deploy's: contributor tooling whose default is the only source, test
scaffolding that writes the file it names, and two readers of
CA_TRUST_CERT_EXTRA_HOST, which nothing in the repo sets.

utils/diagnostics/container.py resolves without a marker: RESCUE_DEPTH is
a recursion base case, and the integer 0 says what the string "0" said.
The file sits exactly at the 500-line cap, so a comment line was not
available.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-14 00:26:55 +02:00

69 lines
2.0 KiB
Python
Executable File

#!/usr/bin/env python3
"""Print ``<ip> <domain>`` lines for every canonical domain
(plus ``www.`` redirects and the primary itself) owned by ``APP_ID``
or its transitive deps.
Inputs (env): ``APP_ID``, ``INFINITO_DOMAIN`` (the SPOT for the
deployment domain; defined in ``default.env`` and exported by
``scripts/meta/env/load.sh``; the development inventory reads the
same env var for the play's ``DOMAIN_PRIMARY``),
``HOSTS_ENTRY_IP`` (address the domains map to; the swarm play
sets it from ``INFINITO_SWARM_MGR_IP``).
"""
from __future__ import annotations
import os
import sys
from plugins.filter.canonical_domains_map import (
FilterModule as _CanonicalDomainsFilter,
)
from plugins.filter.generate.all_domains import (
FilterModule as _AllDomainsFilter,
)
from utils import PROJECT_ROOT
from utils.cache.applications import get_merged_applications
from utils.roles.applications.in_group_deps import applications_if_group_and_all_deps
_ROLES_DIR = PROJECT_ROOT / "roles"
def _derived_domains(app_id: str, domain_primary: str) -> list[str]:
applications = get_merged_applications(roles_dir=str(_ROLES_DIR))
transitive = applications_if_group_and_all_deps(
applications,
[app_id],
project_root=str(PROJECT_ROOT),
roles_dir=str(_ROLES_DIR),
)
canonical = _CanonicalDomainsFilter().canonical_domains_map(
applications,
domain_primary,
recursive=True,
roles_base_dir=str(_ROLES_DIR),
seed=list(transitive),
)
derived = _AllDomainsFilter().generate_all_domains(canonical, include_www=True)
return sorted(
{
*derived,
domain_primary,
f"www.{domain_primary}",
f"test.{domain_primary}",
}
)
def main() -> int:
app_id = os.environ["APP_ID"]
domain_primary = os.environ["INFINITO_DOMAIN"]
ip = os.environ["HOSTS_ENTRY_IP"]
for domain in _derived_domains(app_id, domain_primary):
print(f"{ip} {domain}")
return 0
if __name__ == "__main__":
sys.exit(main())