fix: JWT_SECRET lazy-validiert statt beim Import

config.py: get_jwt_secret() wirft RuntimeError nur bei Nutzung,
nicht beim Import. Blog-Pipeline kann importieren ohne JWT_SECRET,
Monitor bleibt geschützt.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dieser Commit ist enthalten in:
Claude Dev
2026-03-29 13:53:17 +02:00
Ursprung 5bcaa4e8a1
Commit c53d441c69
2 geänderte Dateien mit 13 neuen und 4 gelöschten Zeilen

Datei anzeigen

@@ -4,7 +4,7 @@ from datetime import datetime, timedelta
from jose import jwt, JWTError from jose import jwt, JWTError
from fastapi import Depends, HTTPException, status from fastapi import Depends, HTTPException, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from config import JWT_SECRET, JWT_ALGORITHM, JWT_EXPIRE_HOURS, TIMEZONE from config import get_jwt_secret, JWT_ALGORITHM, JWT_EXPIRE_HOURS, TIMEZONE
security = HTTPBearer() security = HTTPBearer()
@@ -36,7 +36,7 @@ def create_token(
"iat": now, "iat": now,
"exp": expire, "exp": expire,
} }
return jwt.encode(payload, JWT_SECRET, algorithm=JWT_ALGORITHM) return jwt.encode(payload, get_jwt_secret(), algorithm=JWT_ALGORITHM)
def decode_token(token: str) -> dict: def decode_token(token: str) -> dict:
@@ -44,7 +44,7 @@ def decode_token(token: str) -> dict:
try: try:
payload = jwt.decode( payload = jwt.decode(
token, token,
JWT_SECRET, get_jwt_secret(),
algorithms=[JWT_ALGORITHM], algorithms=[JWT_ALGORITHM],
issuer=JWT_ISSUER, issuer=JWT_ISSUER,
audience=JWT_AUDIENCE, audience=JWT_AUDIENCE,

Datei anzeigen

@@ -13,7 +13,16 @@ STATIC_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "static")
DB_PATH = os.path.join(DATA_DIR, "osint.db") DB_PATH = os.path.join(DATA_DIR, "osint.db")
# JWT # JWT
JWT_SECRET = os.environ.get("JWT_SECRET", "") _JWT_SECRET = os.environ.get("JWT_SECRET", "")
def get_jwt_secret() -> str:
"""Gibt JWT_SECRET zurück. Wirft RuntimeError wenn nicht gesetzt."""
if not _JWT_SECRET:
raise RuntimeError("JWT_SECRET Umgebungsvariable muss gesetzt sein")
return _JWT_SECRET
# Rückwärtskompatibel für direkte Imports
JWT_SECRET = _JWT_SECRET
JWT_ALGORITHM = "HS256" JWT_ALGORITHM = "HS256"
JWT_EXPIRE_HOURS = 24 JWT_EXPIRE_HOURS = 24