#!/usr/bin/env python3 """Lit et valide le registre des domaines publics Set-OPS (instance/plan/domaines.yml).""" from __future__ import annotations import os import argparse import sys from pathlib import Path from inventory_rules import ( charger_applications, charger_domaines, expositions_des_applications, valider_domaines, ) RACINE = Path(__file__).resolve().parents[1] INSTANCE = Path(os.environ.get("SETOPS_INSTANCE") or (RACINE / "instance")) FICHIER = INSTANCE / "plan/domaines.yml" FICHIER_APPLICATIONS = INSTANCE / "plan/applications.yml" def lister(registre: dict, applications: dict) -> None: domaines = registre.get("domaines_publics", {}) if not domaines: print("Aucun domaine public declare.") return expos = expositions_des_applications(applications, registre) for nom_domaine, conf in domaines.items(): secondaires = conf.get("secondaires") or [] dnssec = "oui" if conf.get("dnssec") else "non" print(f"{nom_domaine} [autorite {conf.get('autorite', '?')}, edge {conf.get('edge', '-')}, dnssec {dnssec}]") print(f" secondaires: {', '.join(secondaires) if secondaires else '(aucun)'}") for e in [x for x in expos if x["domaine"] == nom_domaine]: print(f" exposition: {e['fqdn']} -> application {e['application']} (sur {e['hote']})") def main() -> int: parser = argparse.ArgumentParser(description="Registre des domaines publics Set-OPS.") sub = parser.add_subparsers(dest="commande", required=True) sub.add_parser("lister", help="Affiche domaines, autorite et expositions (depuis les applications).") sub.add_parser("verifier", help="Valide la coherence du registre.") args = parser.parse_args() try: registre = charger_domaines(FICHIER) if args.commande == "lister": lister(registre, charger_applications(FICHIER_APPLICATIONS)) elif args.commande == "verifier": valider_domaines(registre) print("Registre des domaines valide.") except Exception as exc: print(f"erreur: {exc}", file=sys.stderr) return 2 return 0 if __name__ == "__main__": raise SystemExit(main())