fix access key middleware

This commit is contained in:
Fran Jurmanović
2025-07-30 01:58:25 +02:00
parent 687b406727
commit 68a22e6d5d
2 changed files with 6 additions and 3 deletions

View File

@@ -28,7 +28,7 @@ func NewServiceControlController(as *service.ServiceControlService, routeGroups
errorHandler: error_handler.NewControllerErrorHandler(), errorHandler: error_handler.NewControllerErrorHandler(),
} }
serviceRoutes := routeGroups.Server.Group("/service") serviceRoutes := routeGroups.Server.Group("/:id/service")
serviceRoutes.Get("/:service", ac.getStatus) serviceRoutes.Get("/:service", ac.getStatus)
serviceRoutes.Post("/start", ac.startServer) serviceRoutes.Post("/start", ac.startServer)
serviceRoutes.Post("/stop", ac.stopServer) serviceRoutes.Post("/stop", ac.stopServer)

View File

@@ -1,6 +1,7 @@
package middleware package middleware
import ( import (
"acc-server-manager/local/model"
"acc-server-manager/local/utl/configs" "acc-server-manager/local/utl/configs"
"acc-server-manager/local/utl/logging" "acc-server-manager/local/utl/logging"
"time" "time"
@@ -17,7 +18,9 @@ type AccessKeyMiddleware struct {
// NewAccessKeyMiddleware creates a new AccessKeyMiddleware. // NewAccessKeyMiddleware creates a new AccessKeyMiddleware.
func NewAccessKeyMiddleware() *AccessKeyMiddleware { func NewAccessKeyMiddleware() *AccessKeyMiddleware {
auth := &AccessKeyMiddleware{ auth := &AccessKeyMiddleware{
userInfo: CachedUserInfo{UserID: uuid.New().String(), Username: "access_key", RoleName: "Admin", Permissions: make(map[string]bool), CachedAt: time.Now()}, userInfo: CachedUserInfo{UserID: uuid.New().String(), Username: "access_key", RoleName: "Admin", Permissions: map[string]bool{
model.ServerView: true,
}, CachedAt: time.Now()},
} }
return auth return auth
} }
@@ -51,7 +54,7 @@ func (m *AccessKeyMiddleware) Authenticate(ctx *fiber.Ctx) error {
} }
ctx.Locals("userID", m.userInfo.UserID) ctx.Locals("userID", m.userInfo.UserID)
ctx.Locals("userInfo", m.userInfo) ctx.Locals("userInfo", &m.userInfo)
ctx.Locals("authTime", time.Now()) ctx.Locals("authTime", time.Now())
logging.InfoWithContext("AUTH", "User %s authenticated successfully from IP %s", m.userInfo.UserID, ip) logging.InfoWithContext("AUTH", "User %s authenticated successfully from IP %s", m.userInfo.UserID, ip)