Erster Stand des öffentlichen Ausschnitts aus dem Vault. Die .gitignore arbeitet als Positivliste: ausgeschlossen ist alles, eingeschlossen nur, was ausdrücklich wieder aufgenommen wird. Notizen, Projekte, Finanzen, das Sitzungsgedächtnis und settings.local.json bleiben damit außen vor. Der Kundenname in AI/Regelwerk/seo.md ist durch eine neutrale Bezeichnung ersetzt; die Regeln selbst sind unverändert. Co-Authored-By: Claude Opus 5 <[email protected]>
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
"""Liest die BookStack-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\Bookstack")
|
|
STANDARD_VAULT = Path(r"D:\Claude")
|
|
PFLICHTVARIABLEN = ("BOOKSTACK_URL", "BOOKSTACK_TOKEN_ID", "BOOKSTACK_TOKEN_SECRET")
|
|
|
|
|
|
class KonfigurationsFehler(Exception):
|
|
"""Zugangsdaten fehlen oder sind unbrauchbar."""
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Konfiguration:
|
|
basis_url: str
|
|
token_id: str
|
|
token_secret: str = field(repr=False)
|
|
quelle: Path
|
|
vault: Path
|
|
|
|
|
|
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 „Einrichtung“."
|
|
)
|
|
|
|
basis_url = werte["BOOKSTACK_URL"].strip().rstrip("/")
|
|
if not basis_url.startswith(("http://", "https://")):
|
|
raise KonfigurationsFehler(
|
|
f"BOOKSTACK_URL muss mit http:// oder https:// beginnen, ist aber „{basis_url}“."
|
|
)
|
|
|
|
quelle = werte.get("BOOKSTACK_QUELLE", "").strip()
|
|
vault = werte.get("BOOKSTACK_VAULT", "").strip()
|
|
return Konfiguration(
|
|
basis_url=basis_url,
|
|
token_id=werte["BOOKSTACK_TOKEN_ID"].strip(),
|
|
token_secret=werte["BOOKSTACK_TOKEN_SECRET"].strip(),
|
|
quelle=Path(quelle) if quelle else STANDARD_QUELLE,
|
|
vault=Path(vault) if vault else STANDARD_VAULT,
|
|
)
|