CFG-06: benachrichtigungs-einstellungen-dienst-starten

- cmd/notifyprefs-api: startet internal/notifyprefs.Handler (CFG-04),
  hinter auth.RequireAuth mit demselben JWT-Secret wie IAM-16
- reines Wiring, kein Diff an internal/notifyprefs/ (verifiziert)
- real deployed auf 131, cross-service-Session real bewiesen: Login
  gegen account-api, dasselbe Cookie gegen notifyprefs-api verwendet ->
  echtes Setzen und Lesen einer Praeferenz, ohne Cookie -> 401
- nutzt dieselbe nexarch_registry-DB wie CFG-05, Grants bereits
  vorhanden

Pruefungen siehe docs/CFG-06-PRUEFPROTOKOLL.md
This commit is contained in:
sysops
2026-08-30 21:48:09 +02:00
parent b1601c578a
commit 4be7853611
3 changed files with 125 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
// notifyprefs-api ist der Aufrufpunkt fuer CFG-06: startet den bereits
// fertigen CFG-04-Handler (internal/notifyprefs) als eigenstaendigen
// HTTP-Dienst, hinter derselben Session-Auth wie IAM-16 (account-api) —
// GLEICHER JWT-Secret. REINES WIRING — keine Aenderung an
// internal/notifyprefs/.
package main
import (
"context"
"log"
"net/http"
"os"
"github.com/jackc/pgx/v5/pgxpool"
"gitea.perlbach24.de/scripte/nexarch/internal/auth"
"gitea.perlbach24.de/scripte/nexarch/internal/notifyprefs"
)
func requireEnv(name string) string {
v := os.Getenv(name)
if v == "" {
log.Fatalf("%s muss gesetzt sein", name)
}
return v
}
func main() {
dsn := requireEnv("NEXARCH_NOTIFYPREFS_TENANT_DSN")
// MUSS identisch mit NEXARCH_ACCOUNT_JWT_SECRET (IAM-16) sein, sonst
// verwirft dieser Dienst gueltige account-api-Sessions.
jwtSecret := requireEnv("NEXARCH_NOTIFYPREFS_JWT_SECRET")
addr := os.Getenv("NEXARCH_NOTIFYPREFS_API_LISTEN_ADDR")
if addr == "" {
addr = "127.0.0.1:8101"
}
ctx := context.Background()
pool, err := pgxpool.New(ctx, dsn)
if err != nil {
log.Fatalf("datenbankverbindung: %v", err)
}
defer pool.Close()
tokenIssuer := auth.NewTokenIssuer(jwtSecret)
handler := notifyprefs.NewHandler(notifyprefs.NewStore(pool))
mux := http.NewServeMux()
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) })
mux.HandleFunc("GET /notifications/preferences", auth.RequireAuth(tokenIssuer, handler.ListMine))
mux.HandleFunc("POST /notifications/preferences", auth.RequireAuth(tokenIssuer, handler.SetPreference))
mux.HandleFunc("GET /notifications/preferences/tenant", auth.RequireAuth(tokenIssuer, handler.ListTenantOverview))
log.Printf("notifyprefs-api: listening on %s", addr)
if err := http.ListenAndServe(addr, mux); err != nil {
log.Fatalf("http server: %v", err)
}
}