Files
nexarch/cmd/notify-api/main.go
T
sysops 23a3cc1a62 CFG-05: modulübergreifender-http-endpunkt-für-benachrichtigungs-ereignisse
- internal/notifyapi.Mount (POST /notify/enqueue), reiner Wrapper um
  notifyprefs.EnqueueIfAllowed (CFG-04)
- Reuse von internal/policyapi.RequireServiceToken (RBAC-06), kein
  neues Provisorium, eigener Service-Token pro Endpunkt
- Tests: 401 ohne Token, Aequivalenz HTTP vs. direkter Aufruf
  (aktiviert/deaktiviert), realer Fremd-Modul-Client mit echter
  notification_jobs-Zeile
- real deployed auf 131 (notify-api, Port 8094), Grant-Nachverfolgung
  fuer nexarch_core auf notification_preferences/notification_jobs,
  end-zu-ende per curl nachgewiesen (401, job_id+skipped:false)

Pruefungen siehe docs/CFG-05-PRUEFPROTOKOLL.md
2026-08-30 09:04:31 +02:00

53 lines
1.4 KiB
Go

// notify-api ist der Aufrufpunkt fuer CFG-05: stellt Core CFG-04s
// EnqueueIfAllowed als HTTP-Endpunkt fuer andere, physisch getrennte
// Module (Archive, DMS, Mail) bereit. Getrennt von cmd/core aus
// demselben Grund wie policy-api (RBAC-06).
package main
import (
"context"
"log"
"net/http"
"os"
"github.com/jackc/pgx/v5/pgxpool"
"gitea.perlbach24.de/scripte/nexarch/internal/notify"
"gitea.perlbach24.de/scripte/nexarch/internal/notifyapi"
"gitea.perlbach24.de/scripte/nexarch/internal/notifyprefs"
)
func main() {
dsn := os.Getenv("NEXARCH_NOTIFY_ADMIN_DSN")
if dsn == "" {
log.Fatal("NEXARCH_NOTIFY_ADMIN_DSN muss gesetzt sein")
}
serviceToken := os.Getenv("NEXARCH_NOTIFY_SERVICE_TOKEN")
if serviceToken == "" {
log.Fatal("NEXARCH_NOTIFY_SERVICE_TOKEN muss gesetzt sein")
}
addr := os.Getenv("NEXARCH_NOTIFY_API_LISTEN_ADDR")
if addr == "" {
addr = "127.0.0.1:8094"
}
ctx := context.Background()
pool, err := pgxpool.New(ctx, dsn)
if err != nil {
log.Fatalf("datenbankverbindung: %v", err)
}
defer pool.Close()
prefs := notifyprefs.NewStore(pool)
dispatcher := notify.NewDispatcher(pool)
mux := http.NewServeMux()
notifyapi.Mount(mux, prefs, dispatcher, serviceToken)
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) })
log.Printf("notify-api: listening on %s", addr)
if err := http.ListenAndServe(addr, mux); err != nil {
log.Fatalf("http server: %v", err)
}
}