From 7cf9b80fe603e9c9ee68658ad37dbeb0d903d50e Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 30 Jan 2025 22:24:58 +0800 Subject: [PATCH] :sparkles: WatchTower admin API --- pkg/internal/http/api/index.go | 6 ++++++ pkg/internal/http/api/watchtower.go | 15 +++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 pkg/internal/http/api/watchtower.go diff --git a/pkg/internal/http/api/index.go b/pkg/internal/http/api/index.go index 4262c39..9592cb5 100644 --- a/pkg/internal/http/api/index.go +++ b/pkg/internal/http/api/index.go @@ -41,6 +41,12 @@ func MapAPIs(app *fiber.App) { }) } + // WatchTower administration APIs + wt := app.Group("/watchtower").Name("WatchTower").Use(auth.ValidatorMiddleware) + { + wt.Post("/maintenance/database", wtRunDbMaintenance) + } + // Common websocket gateway app.Get("/ws", auth.ValidatorMiddleware, websocket.New(ws.Listen)) diff --git a/pkg/internal/http/api/watchtower.go b/pkg/internal/http/api/watchtower.go new file mode 100644 index 0000000..d4b6150 --- /dev/null +++ b/pkg/internal/http/api/watchtower.go @@ -0,0 +1,15 @@ +package api + +import ( + "git.solsynth.dev/hypernet/nexus/pkg/internal/watchtower" + "git.solsynth.dev/hypernet/nexus/pkg/nex/sec" + "github.com/gofiber/fiber/v2" +) + +func wtRunDbMaintenance(c *fiber.Ctx) error { + if err := sec.EnsureGrantedPerm(c, "AdminOperateWatchTower", true); err != nil { + return err + } + go watchtower.RunDbMaintenance() + return c.SendStatus(fiber.StatusOK) +}