"""Config from .env next to ctf_status.py; environment variables override it.""" from __future__ import annotations import os import sys from pathlib import Path CFG_KEYS = ("GITLAB_GROUP_URL", "GITLAB_TOKEN") OPT_KEYS = ("HEDGEDOC_NOTE", "HEDGEDOC_TAGS", "TITLE", "CHALLS_REPO_URL", "CHALLS_PATH", "CHALLS_BRANCH") # the names a plain `.env` tends to use for the same thing ALIASES = {"GL_PAT": "GITLAB_TOKEN", "GITLAB_URL": "GITLAB_GROUP_URL"} DEFAULT_TAGS = "Logistics, h4tum CTF 2026" DEFAULT_TITLE = "CTF challenge tracking" DEFAULT_CHALLS_PATH = "2026/challs.txt" def load_env() -> dict: cfg = {} env_file = Path(__file__).parent.parent / ".env" # the repo, next to ctf_status.py if env_file.exists(): for line in env_file.read_text().splitlines(): line = line.strip() if not line or line.startswith("#") or "=" not in line: continue k, v = line.split("=", 1) k = k.strip().upper() cfg.setdefault(ALIASES.get(k, k), v.strip().strip("'\"")) for k in CFG_KEYS + OPT_KEYS + tuple(ALIASES): if os.environ.get(k): cfg[ALIASES.get(k, k)] = os.environ[k] missing = [k for k in CFG_KEYS if not cfg.get(k)] if missing: sys.exit(f"missing config: {', '.join(missing)} (see .env.example)") return cfg