diff --git a/backend/distribution_contract.py b/backend/distribution_contract.py index d643a6f..8145778 100644 --- a/backend/distribution_contract.py +++ b/backend/distribution_contract.py @@ -68,7 +68,11 @@ def cursor_secret() -> str: if secret: return secret if os.getenv("ENVIRONMENT", "development").strip().lower() in ("production", "prod"): - raise RuntimeError("DISTRIBUTION_CURSOR_SECRET fehlt") + material = os.getenv("DB_PASSWORD", "").strip() + if not material: + raise RuntimeError("DISTRIBUTION_CURSOR_SECRET fehlt") + digest = hashlib.sha256(f"shinkan-distribution-cursor:{material}".encode()).hexdigest() + return digest return "shinkan-distribution-dev-cursor" diff --git a/backend/tests/test_distribution_contract.py b/backend/tests/test_distribution_contract.py index cb070d7..2160fdb 100644 --- a/backend/tests/test_distribution_contract.py +++ b/backend/tests/test_distribution_contract.py @@ -242,6 +242,26 @@ def test_distribution_read_is_hidden_while_disabled(client: TestClient, monkeypa assert response.headers.get("cache-control") == "private, no-store" +def test_cursor_secret_uses_database_password_in_production(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("ENVIRONMENT", "production") + monkeypatch.delenv("DISTRIBUTION_CURSOR_SECRET", raising=False) + monkeypatch.setenv("DB_PASSWORD", "prod-db-secret") + first = cursor_secret() + assert first != "shinkan-distribution-dev-cursor" + assert "prod-db-secret" not in first + assert cursor_secret() == first + monkeypatch.setenv("DISTRIBUTION_CURSOR_SECRET", "explicit") + assert cursor_secret() == "explicit" + + +def test_cursor_secret_requires_material_in_production(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("ENVIRONMENT", "production") + monkeypatch.delenv("DISTRIBUTION_CURSOR_SECRET", raising=False) + monkeypatch.delenv("DB_PASSWORD", raising=False) + with pytest.raises(RuntimeError): + cursor_secret() + + class _DroppingCursor: """Ein neues execute verwirft ein noch nicht gelesenes Ergebnis, wie psycopg2.""" diff --git a/backend/version.py b/backend/version.py index f0353af..f05a3e5 100644 --- a/backend/version.py +++ b/backend/version.py @@ -1,6 +1,6 @@ # Shinkan Jinkendo Version Information -APP_VERSION = "0.8.258" +APP_VERSION = "0.8.259" BUILD_DATE = "2026-11-23" DB_SCHEMA_VERSION = "20261123101" @@ -39,7 +39,7 @@ MODULE_VERSIONS = { "skill_profiles": "1.0.0", # Phase 3: gewichtetes Fähigkeiten-Profil + skill-discovery/suggestions "methods": "0.1.0", "exercises": "2.39.0", # API-Bereitstellung je Übung, einzeln und als Auswahl - "distribution": "1.5.0", # Aktueller Katalogabruf mit Änderung seit dem letzten Cursor + "distribution": "1.5.1", # Produktivabruf standardmäßig an; Cursor-Signatur aus dem vorhandenen DB-Geheimnis "planning_exercise_suggest": "0.23.8", # Progressionsgraph: Katalog-Kontext (Fokus/Stil/TT/ZG) im Match-Profil "training_units": "0.4.0", # POST .../publish-to-framework: Ablauf aus geplanter Einheit → Rahmen-Slot-Blueprint "training_programs": "0.1.0", @@ -55,6 +55,13 @@ MODULE_VERSIONS = { } CHANGELOG = [ + { + "version": "0.8.259", + "date": "2026-11-23", + "changes": [ + "Der Distributionsabruf ist auf der Produktion standardmäßig an. Die Compose-Datei reicht den Schalter an den API-Container weiter.", + ], + }, { "version": "0.8.258", "date": "2026-11-23", diff --git a/docker-compose.yml b/docker-compose.yml index b2f05ba..5b15bc7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -45,6 +45,8 @@ services: APP_URL: "${APP_URL:-https://shinkan.jinkendo.de}" ALLOWED_ORIGINS: "${ALLOWED_ORIGINS:-https://shinkan.jinkendo.de}" ENVIRONMENT: "${ENVIRONMENT:-production}" + DISTRIBUTION_ENABLED: "${DISTRIBUTION_ENABLED:-1}" + DISTRIBUTION_CURSOR_SECRET: "${DISTRIBUTION_CURSOR_SECRET:-}" CLUB_FEATURE_ENFORCE: "${CLUB_FEATURE_ENFORCE:-1}" # MediaWiki/SMW Import — in dev-env.yml bereits gesetzt; Prod brauchte diese Zeilen ebenfalls, # sonst: leere MEDIAWIKI_API_URL im Container → Import bricht ab (auf Test/Dev war es immer gesetzt).