62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
package router
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
"net/http/pprof"
|
|
"vctp/db"
|
|
"vctp/dist"
|
|
"vctp/internal/secrets"
|
|
"vctp/internal/settings"
|
|
"vctp/internal/vcenter"
|
|
"vctp/server/handler"
|
|
"vctp/server/middleware"
|
|
)
|
|
|
|
func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver string, goVersion string, creds *vcenter.VcenterLogin, secret *secrets.Secrets, settings *settings.Settings) http.Handler {
|
|
h := &handler.Handler{
|
|
Logger: logger,
|
|
Database: database,
|
|
BuildTime: buildTime,
|
|
SHA1Ver: sha1ver,
|
|
GoVersion: goVersion,
|
|
VcCreds: creds,
|
|
Secret: secret,
|
|
Settings: settings,
|
|
}
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
mux.Handle("/assets/", middleware.CacheMiddleware(http.FileServer(http.FS(dist.AssetsDir))))
|
|
mux.HandleFunc("/", h.Home)
|
|
mux.HandleFunc("/api/event/vm/create", h.VmCreateEvent)
|
|
mux.HandleFunc("/api/event/vm/modify", h.VmModifyEvent)
|
|
mux.HandleFunc("/api/event/vm/move", h.VmMoveEvent)
|
|
mux.HandleFunc("/api/event/vm/delete", h.VmDeleteEvent)
|
|
mux.HandleFunc("/api/import/vm", h.VmImport)
|
|
// Use this when we need to manually remove a VM from the database to clean up
|
|
mux.HandleFunc("/api/inventory/vm/delete", h.VmCleanup)
|
|
|
|
// add missing data to VMs
|
|
mux.HandleFunc("/api/inventory/vm/update", h.VmUpdateDetails)
|
|
|
|
// temporary endpoint
|
|
//mux.HandleFunc("/api/cleanup/updates", h.UpdateCleanup)
|
|
//mux.HandleFunc("/api/cleanup/vcenter", h.VcCleanup)
|
|
|
|
mux.HandleFunc("/api/report/inventory", h.InventoryReportDownload)
|
|
mux.HandleFunc("/api/report/updates", h.UpdateReportDownload)
|
|
|
|
// endpoint for encrypting vcenter credential
|
|
mux.HandleFunc("/api/encrypt", h.EncryptData)
|
|
|
|
// Register pprof handlers
|
|
mux.HandleFunc("/debug/pprof/", pprof.Index)
|
|
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
|
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
|
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
|
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
|
|
|
return middleware.NewLoggingMiddleware(logger, mux)
|
|
}
|