Merge branch 'feature/aud-04-audit-log-ansicht' into feature/qa-09-barrierefreiheits-audit
# Conflicts: # DEVLOG.md # go.mod # go.sum # scripts/reset-test-env.sh
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
// auditlog-devserver stellt AUD-03s ExportHandler (internal/audit) fuer die
|
||||
// Next.js-Audit-Log-Ansicht (AUD-04) bereit. Getrennt von cmd/core aus
|
||||
// demselben Grund wie die anderen *-devserver (siehe LIC-04/TEN-05): echte
|
||||
// Auth/RBAC ist noch nicht in die zentrale Server-Topologie verdrahtet.
|
||||
//
|
||||
// Authorize wird hier mit einem geteilten Admin-Token ueber
|
||||
// crypto/subtle.ConstantTimeCompare umgesetzt — demselben Timing-safe-Muster
|
||||
// wie internal/audit.timingsafe (AUD-02), NICHT ueber eine neue
|
||||
// Rollen-/Rechteschicht, da diese Kachel ausdruecklich nur von AUD-03
|
||||
// abhaengt und keine Rechteverwaltung duplizieren soll.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"gitea.perlbach24.de/scripte/nexarch/internal/audit"
|
||||
"gitea.perlbach24.de/scripte/nexarch/internal/auditadmin"
|
||||
"gitea.perlbach24.de/scripte/nexarch/internal/db"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dsn := os.Getenv("NEXARCH_REGISTRY_DSN")
|
||||
if dsn == "" {
|
||||
log.Fatal("NEXARCH_REGISTRY_DSN nicht gesetzt")
|
||||
}
|
||||
adminToken := os.Getenv("NEXARCH_AUDIT_ADMIN_TOKEN")
|
||||
if adminToken == "" {
|
||||
log.Fatal("NEXARCH_AUDIT_ADMIN_TOKEN nicht gesetzt")
|
||||
}
|
||||
addr := os.Getenv("NEXARCH_AUDITLOG_LISTEN_ADDR")
|
||||
if addr == "" {
|
||||
addr = ":8083"
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
pool, err := db.Connect(ctx, dsn)
|
||||
if err != nil {
|
||||
log.Fatalf("db: %v", err)
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
auditLog := audit.NewLog(pool)
|
||||
tokenAuthorize := auditadmin.NewTokenAuthorizer(adminToken)
|
||||
authorize := func(_ context.Context, caller string) bool { return tokenAuthorize(caller) }
|
||||
handler := audit.NewExportHandler(auditLog, authorize)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/audit/export", withCORS(handler.Export))
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) })
|
||||
|
||||
log.Printf("auditlog-devserver listening on %s", addr)
|
||||
log.Fatal(http.ListenAndServe(addr, mux))
|
||||
}
|
||||
|
||||
func withCORS(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
next(w, r)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user