68 lines
2.3 KiB
Go
68 lines
2.3 KiB
Go
// tenantadmin-devserver stellt das TEN-05-Backend-API (internal/tenantadmin)
|
|
// fuer die Next.js-Tenant-Verwaltungsoberflaeche bereit. Getrennt von
|
|
// cmd/core aus demselben Grund wie cmd/licadmin-devserver (siehe LIC-04):
|
|
// echte Auth (IAM-01/IAM-02) ist noch nicht in die zentrale Server-Topologie
|
|
// verdrahtet, dieser Server dient Entwicklung/Betrieb der Oberflaeche gegen
|
|
// eine echte Datenbank, ohne cmd/core anzufassen.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"gitea.perlbach24.de/scripte/nexarch/internal/db"
|
|
"gitea.perlbach24.de/scripte/nexarch/internal/tenant"
|
|
"gitea.perlbach24.de/scripte/nexarch/internal/tenantadmin"
|
|
"gitea.perlbach24.de/scripte/nexarch/internal/tenantsettings"
|
|
"gitea.perlbach24.de/scripte/nexarch/internal/user"
|
|
)
|
|
|
|
func main() {
|
|
dsn := os.Getenv("NEXARCH_REGISTRY_DSN")
|
|
if dsn == "" {
|
|
log.Fatal("NEXARCH_REGISTRY_DSN nicht gesetzt")
|
|
}
|
|
addr := os.Getenv("NEXARCH_TENANTADMIN_LISTEN_ADDR")
|
|
if addr == "" {
|
|
addr = ":8082"
|
|
}
|
|
|
|
ctx := context.Background()
|
|
pool, err := db.Connect(ctx, dsn)
|
|
if err != nil {
|
|
log.Fatalf("db: %v", err)
|
|
}
|
|
defer pool.Close()
|
|
|
|
registry := tenant.NewRegistry(pool)
|
|
lifecycle := tenant.NewLifecycle(registry, pool)
|
|
settingsStore := tenantsettings.NewStore(pool)
|
|
superadmins := user.NewSuperadminStore(pool)
|
|
handler := tenantadmin.NewHandler(registry, lifecycle, settingsStore, superadmins)
|
|
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/admin/tenants", withCORS(handler.ListTenantsHandler))
|
|
mux.HandleFunc("/admin/tenants/detail", withCORS(handler.TenantDetailHandler))
|
|
mux.HandleFunc("/admin/tenants/settings", withCORS(handler.UpdateSettingsHandler))
|
|
mux.HandleFunc("/admin/tenants/lifecycle", withCORS(handler.LifecycleActionHandler))
|
|
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) })
|
|
|
|
log.Printf("tenantadmin-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, POST, OPTIONS")
|
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
|
if r.Method == http.MethodOptions {
|
|
w.WriteHeader(http.StatusOK)
|
|
return
|
|
}
|
|
next(w, r)
|
|
}
|
|
}
|