"""Liest die Plane-Zugangsdaten aus Umgebungsvariablen.""" from __future__ import annotations import os from collections.abc import Mapping from dataclasses import dataclass, field from pathlib import Path STANDARD_QUELLE = Path(r"D:\Claude\Code Projekte") PFLICHTVARIABLEN = ("PLANE_URL", "PLANE_API_KEY", "PLANE_WORKSPACE") class KonfigurationsFehler(Exception): """Zugangsdaten fehlen oder sind unbrauchbar.""" @dataclass(frozen=True) class Konfiguration: basis_url: str api_key: str = field(repr=False) workspace: str = "" quelle: Path = STANDARD_QUELLE def lade_konfiguration(umgebung: Mapping[str, str] | None = None) -> Konfiguration: """Baut die Konfiguration aus der Umgebung; meldet alle Lücken auf einmal.""" werte = os.environ if umgebung is None else umgebung fehlend = [name for name in PFLICHTVARIABLEN if not werte.get(name, "").strip()] if fehlend: raise KonfigurationsFehler( "Diese Umgebungsvariablen fehlen oder sind leer: " + ", ".join(fehlend) + ". Siehe README.md, Abschnitt \u201eEinrichtung\u201c." ) basis_url = werte["PLANE_URL"].strip().rstrip("/") if not basis_url.startswith(("http://", "https://")): raise KonfigurationsFehler( f"PLANE_URL muss mit http:// oder https:// beginnen, " f"ist aber \u201e{basis_url}\u201c." ) quelle = werte.get("PLANE_QUELLE", "").strip() return Konfiguration( basis_url=basis_url, api_key=werte["PLANE_API_KEY"].strip(), workspace=werte["PLANE_WORKSPACE"].strip(), quelle=Path(quelle) if quelle else STANDARD_QUELLE, )