Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
refactor: refactor api route structure, update auth middleware to actually pass if a user is an admin or not
Kyle Mendell4b0868e1ba88
diff --git a/backend/internal/api/auth_handler.go b/backend/internal/api/auth_handler.goindex d33c6282e..48691c7a0 100644--- a/backend/internal/api/auth_handler.go+++ b/backend/internal/api/auth_handler.go@@ -17,11 +17,16 @@ type AuthHandler struct {oidcService *services.OidcService}-func NewAuthHandler(userService *services.UserService, authService *services.AuthService, oidcService *services.OidcService) *AuthHandler {- return &AuthHandler{- userService: userService,- authService: authService,- oidcService: oidcService,+func NewAuthHandler(group *gin.RouterGroup, userService *services.UserService, authService *services.AuthService, oidcService *services.OidcService, authMiddleware *middleware.AuthMiddleware) {+ ah := &AuthHandler{userService: userService, authService: authService, oidcService: oidcService}++ authApiGroup := group.Group("/auth")+ {+ authApiGroup.POST("/login", ah.Login)+ authApiGroup.POST("/logout", ah.Logout)+ authApiGroup.GET("/me", authMiddleware.WithAdminNotRequired().Add(), ah.GetCurrentUser)+ authApiGroup.POST("/refresh", ah.RefreshToken)+ authApiGroup.POST("/password", authMiddleware.WithAdminNotRequired().Add(), ah.ChangePassword)}}diff --git a/backend/internal/api/container_handler.go b/backend/internal/api/container_handler.goindex a205c6d97..9f36c4023 100644--- a/backend/internal/api/container_handler.go+++ b/backend/internal/api/container_handler.go@@ -20,10 +20,23 @@ type ContainerHandler struct {imageService *services.ImageService}-func NewContainerHandler(containerService *services.ContainerService, imageService *services.ImageService) *ContainerHandler {- return &ContainerHandler{- containerService: containerService,- imageService: imageService,+func NewContainerHandler(group *gin.RouterGroup, containerService *services.ContainerService, imageService *services.ImageService, authMiddleware *middleware.AuthMiddleware) {+ handler := &ContainerHandler{containerService: containerService, imageService: imageService}++ apiGroup := group.Group("/containers")+ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.GET("", handler.List)+ apiGroup.POST("", handler.Create)+ apiGroup.GET("/:id", handler.GetByID)+ apiGroup.GET("/:id/stats", handler.GetStats)+ apiGroup.GET("/:id/stats/stream", handler.GetStatsStream)+ apiGroup.POST("/:id/start", handler.Start)+ apiGroup.POST("/:id/stop", handler.Stop)+ apiGroup.POST("/:id/restart", handler.Restart)+ apiGroup.GET("/:id/logs", handler.GetLogs)+ apiGroup.GET("/:id/logs/stream", handler.GetLogsStream)+ apiGroup.DELETE("/:id", handler.Delete)}}diff --git a/backend/internal/api/container_registry_handler.go b/backend/internal/api/container_registry_handler.goindex 305b69669..83a7f409a 100644--- a/backend/internal/api/container_registry_handler.go+++ b/backend/internal/api/container_registry_handler.go@@ -8,6 +8,7 @@ import ("github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/dto"+ "github.com/ofkm/arcane-backend/internal/middleware""github.com/ofkm/arcane-backend/internal/models""github.com/ofkm/arcane-backend/internal/services""github.com/ofkm/arcane-backend/internal/utils"@@ -17,9 +18,19 @@ type ContainerRegistryHandler struct {registryService *services.ContainerRegistryService}-func NewContainerRegistryHandler(registryService *services.ContainerRegistryService) *ContainerRegistryHandler {- return &ContainerRegistryHandler{- registryService: registryService,+func NewContainerRegistryHandler(group *gin.RouterGroup, registryService *services.ContainerRegistryService, authMiddleware *middleware.AuthMiddleware) {+ handler := &ContainerRegistryHandler{registryService: registryService}++ apiGroup := group.Group("/container-registries")++ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.GET("", handler.GetRegistries)+ apiGroup.POST("", handler.CreateRegistry)+ apiGroup.GET("/:id", handler.GetRegistry)+ apiGroup.PUT("/:id", handler.UpdateRegistry)+ apiGroup.DELETE("/:id", handler.DeleteRegistry)+ apiGroup.POST("/:id/test", handler.TestRegistry)}}diff --git a/backend/internal/api/converter_handler.go b/backend/internal/api/converter_handler.goindex 49e780204..16d3efdbd 100644--- a/backend/internal/api/converter_handler.go+++ b/backend/internal/api/converter_handler.go@@ -4,6 +4,7 @@ import ("net/http""github.com/gin-gonic/gin"+ "github.com/ofkm/arcane-backend/internal/middleware""github.com/ofkm/arcane-backend/internal/models""github.com/ofkm/arcane-backend/internal/services")@@ -12,9 +13,13 @@ type ConverterHandler struct {converterService *services.ConverterService}-func NewConverterHandler(converterService *services.ConverterService) *ConverterHandler {- return &ConverterHandler{- converterService: converterService,+func NewConverterHandler(group *gin.RouterGroup, converterService *services.ConverterService, authMiddleware *middleware.AuthMiddleware) {+ handler := &ConverterHandler{converterService: converterService}++ apiGroup := group.Group("/convert")+ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.POST("", handler.ConvertDockerRun)}}diff --git a/backend/internal/api/environment_handler.go b/backend/internal/api/environment_handler.goindex 8fc245eec..83186c0a4 100644--- a/backend/internal/api/environment_handler.go+++ b/backend/internal/api/environment_handler.go@@ -10,6 +10,7 @@ import ("github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/dto"+ "github.com/ofkm/arcane-backend/internal/middleware""github.com/ofkm/arcane-backend/internal/models""github.com/ofkm/arcane-backend/internal/services""github.com/ofkm/arcane-backend/internal/utils"@@ -26,21 +27,69 @@ type EnvironmentHandler struct {stackService *services.StackService}-func NewEnvironmentHandler(- environmentService *services.EnvironmentService,- containerService *services.ContainerService,- imageService *services.ImageService,- networkService *services.NetworkService,- volumeService *services.VolumeService,- stackService *services.StackService,-) *EnvironmentHandler {- return &EnvironmentHandler{- environmentService: environmentService,- containerService: containerService,- imageService: imageService,- networkService: networkService,- volumeService: volumeService,- stackService: stackService,+func NewEnvironmentHandler(group *gin.RouterGroup, environmentService *services.EnvironmentService, containerService *services.ContainerService, imageService *services.ImageService, networkService *services.NetworkService, volumeService *services.VolumeService, stackService *services.StackService, authMiddleware *middleware.AuthMiddleware) {++ handler := &EnvironmentHandler{environmentService: environmentService, containerService: containerService, imageService: imageService, networkService: networkService, volumeService: volumeService, stackService: stackService}++ apiGroup := group.Group("/environments")+ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.GET("", handler.ListEnvironments)+ apiGroup.POST("", handler.CreateEnvironment)+ apiGroup.GET("/:id", handler.GetEnvironment)+ apiGroup.PUT("/:id", handler.UpdateEnvironment)+ apiGroup.DELETE("/:id", handler.DeleteEnvironment)+ apiGroup.POST("/:id/test", handler.TestConnection)+ apiGroup.POST("/:id/heartbeat", handler.UpdateHeartbeat)++ apiGroup.POST("/:id/containers", handler.CreateContainer)+ apiGroup.GET("/:id/containers", handler.GetContainers)+ apiGroup.GET("/:id/containers/:containerId", handler.GetContainer)+ apiGroup.POST("/:id/containers/:containerId/pull", handler.PullContainerImage)+ apiGroup.POST("/:id/containers/:containerId/start", handler.StartContainer)+ apiGroup.POST("/:id/containers/:containerId/stop", handler.StopContainer)+ apiGroup.POST("/:id/containers/:containerId/restart", handler.RestartContainer)+ apiGroup.DELETE("/:id/containers/:containerId", handler.RemoveContainer)+ apiGroup.GET("/:id/containers/:containerId/logs", handler.GetContainerLogs)+ apiGroup.GET("/:id/containers/:containerId/logs/stream", handler.GetContainerLogsStream)+ apiGroup.GET("/:id/containers/:containerId/stats", handler.GetContainerStats)+ apiGroup.GET("/:id/containers/:containerId/stats/stream", handler.GetContainerStatsStream)++ apiGroup.GET("/:id/images", handler.GetImages)+ apiGroup.GET("/:id/images/:imageId", handler.GetImage)+ apiGroup.DELETE("/:id/images/:imageId", handler.RemoveImage)+ apiGroup.POST("/:id/images/pull", handler.PullImage)+ apiGroup.POST("/:id/images/prune", handler.PruneImages)+ apiGroup.GET("/:id/images/total-size", handler.GetTotalImageSize)++ apiGroup.GET("/:id/networks", handler.GetNetworks)+ apiGroup.POST("/:id/networks", handler.CreateNetwork)+ apiGroup.GET("/:id/networks/:networkId", handler.GetNetwork)+ apiGroup.DELETE("/:id/networks/:networkId", handler.RemoveNetwork)++ apiGroup.GET("/:id/volumes", handler.GetVolumes)+ apiGroup.POST("/:id/volumes", handler.CreateVolume)+ apiGroup.GET("/:id/volumes/:volumeName", handler.GetVolume)+ apiGroup.DELETE("/:id/volumes/:volumeName", handler.RemoveVolume)+ apiGroup.GET("/:id/volumes/:volumeName/usage", handler.GetVolumeUsage)+ apiGroup.POST("/:id/volumes/prune", handler.PruneVolumes)++ apiGroup.GET("/:id/stacks", handler.GetStacks)+ apiGroup.POST("/:id/stacks", handler.CreateStack)+ apiGroup.GET("/:id/stacks/:stackId", handler.GetStack)+ apiGroup.PUT("/:id/stacks/:stackId", handler.UpdateStack)+ apiGroup.DELETE("/:id/stacks/:stackId", handler.DeleteStack)+ apiGroup.POST("/:id/stacks/:stackId/start", handler.StartStack)+ apiGroup.POST("/:id/stacks/:stackId/deploy", handler.DeployStack)+ apiGroup.POST("/:id/stacks/:stackId/stop", handler.StopStack)+ apiGroup.POST("/:id/stacks/:stackId/restart", handler.RestartStack)+ apiGroup.GET("/:id/stacks/:stackId/services", handler.GetStackServices)+ apiGroup.POST("/:id/stacks/:stackId/pull", handler.PullStackImages)+ apiGroup.POST("/:id/stacks/:stackId/redeploy", handler.RedeployStack)+ apiGroup.POST("/:id/stacks/:stackId/down", handler.DownStack)+ apiGroup.DELETE("/:id/stacks/:stackId/destroy", handler.DestroyStack)+ apiGroup.GET("/:id/stacks/:stackId/logs/stream", handler.GetStackLogsStream)+ apiGroup.POST("/:id/stacks/convert", handler.ConvertDockerRun)}}@@ -79,7 +128,10 @@ func (h *EnvironmentHandler) handleLocalRequest(c *gin.Context, endpoint string)}func (h *EnvironmentHandler) handleContainerEndpoints(c *gin.Context, endpoint string) bool {- containerHandler := NewContainerHandler(h.containerService, h.imageService)+ containerHandler := &ContainerHandler{+ containerService: h.containerService,+ imageService: h.imageService,+ }switch {case endpoint == "/containers" && c.Request.Method == http.MethodGet:@@ -123,7 +175,10 @@ func (h *EnvironmentHandler) handleContainerEndpoints(c *gin.Context, endpoint s}func (h *EnvironmentHandler) handleImageEndpoints(c *gin.Context, endpoint string) bool {- imageHandler := NewImageHandler(h.imageService, nil)+ imageHandler := &ImageHandler{+ imageService: h.imageService,+ imageUpdateService: nil,+ }switch {case endpoint == "/images" && c.Request.Method == http.MethodGet:@@ -149,7 +204,9 @@ func (h *EnvironmentHandler) handleImageEndpoints(c *gin.Context, endpoint strin}func (h *EnvironmentHandler) handleNetworkEndpoints(c *gin.Context, endpoint string) bool {- networkHandler := NewNetworkHandler(h.networkService)+ networkHandler := &NetworkHandler{+ networkService: h.networkService,+ }switch {case endpoint == "/networks" && c.Request.Method == http.MethodGet:@@ -169,7 +226,9 @@ func (h *EnvironmentHandler) handleNetworkEndpoints(c *gin.Context, endpoint str}func (h *EnvironmentHandler) handleVolumeEndpoints(c *gin.Context, endpoint string) bool {- volumeHandler := NewVolumeHandler(h.volumeService)+ volumeHandler := &VolumeHandler{+ volumeService: h.volumeService,+ }switch {case endpoint == "/volumes" && c.Request.Method == http.MethodGet:@@ -195,7 +254,9 @@ func (h *EnvironmentHandler) handleVolumeEndpoints(c *gin.Context, endpoint stri}func (h *EnvironmentHandler) handleStackEndpoints(c *gin.Context, endpoint string) bool {- stackHandler := NewStackHandler(h.stackService)+ stackHandler := &StackHandler{+ stackService: h.stackService,+ }switch {case endpoint == "/stacks" && c.Request.Method == http.MethodGet:diff --git a/backend/internal/api/event_handler.go b/backend/internal/api/event_handler.goindex d5f4757e9..94058852d 100644--- a/backend/internal/api/event_handler.go+++ b/backend/internal/api/event_handler.go@@ -7,6 +7,7 @@ import ("github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/dto"+ "github.com/ofkm/arcane-backend/internal/middleware""github.com/ofkm/arcane-backend/internal/services""github.com/ofkm/arcane-backend/internal/utils")@@ -15,9 +16,16 @@ type EventHandler struct {eventService *services.EventService}-func NewEventHandler(eventService *services.EventService) *EventHandler {- return &EventHandler{- eventService: eventService,+func NewEventHandler(group *gin.RouterGroup, eventService *services.EventService, authMiddleware *middleware.AuthMiddleware) {+ handler := &EventHandler{eventService: eventService}++ apiGroup := group.Group("/events")+ apiGroup.Use(authMiddleware.WithAdminRequired().Add())+ {+ apiGroup.GET("", handler.ListEvents)+ apiGroup.POST("", handler.CreateEvent)+ apiGroup.DELETE("/:eventId", handler.DeleteEvent)+ apiGroup.GET("/environment/:environmentId", handler.GetEventsByEnvironment)}}diff --git a/backend/internal/api/image_handler.go b/backend/internal/api/image_handler.goindex 79c46a21c..4898ea64d 100644--- a/backend/internal/api/image_handler.go+++ b/backend/internal/api/image_handler.go@@ -18,10 +18,19 @@ type ImageHandler struct {imageUpdateService *services.ImageUpdateService}-func NewImageHandler(imageService *services.ImageService, imageUpdateService *services.ImageUpdateService) *ImageHandler {- return &ImageHandler{- imageService: imageService,- imageUpdateService: imageUpdateService,+func NewImageHandler(group *gin.RouterGroup, imageService *services.ImageService, imageUpdateService *services.ImageUpdateService, authMiddleware *middleware.AuthMiddleware) {+ handler := &ImageHandler{imageService: imageService, imageUpdateService: imageUpdateService}++ apiGroup := group.Group("/images")+ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.GET("", handler.List)+ apiGroup.GET("/:id", handler.GetByID)+ apiGroup.DELETE("/:id", handler.Remove)+ apiGroup.POST("/pull", handler.Pull)+ apiGroup.POST("/prune", handler.Prune)+ apiGroup.GET("/:id/history", handler.GetHistory)+ apiGroup.GET("/total-size", handler.GetTotalSize)}}diff --git a/backend/internal/api/image_update_handler.go b/backend/internal/api/image_update_handler.goindex f734aad19..23e32d506 100644--- a/backend/internal/api/image_update_handler.go+++ b/backend/internal/api/image_update_handler.go@@ -6,6 +6,7 @@ import ("github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/dto"+ "github.com/ofkm/arcane-backend/internal/middleware""github.com/ofkm/arcane-backend/internal/services")@@ -13,9 +14,20 @@ type ImageUpdateHandler struct {imageUpdateService *services.ImageUpdateService}-func NewImageUpdateHandler(imageUpdateService *services.ImageUpdateService) *ImageUpdateHandler {- return &ImageUpdateHandler{- imageUpdateService: imageUpdateService,+func NewImageUpdateHandler(group *gin.RouterGroup, imageUpdateService *services.ImageUpdateService, authMiddleware *middleware.AuthMiddleware) {+ handler := &ImageUpdateHandler{imageUpdateService: imageUpdateService}++ apiGroup := group.Group("/image-updates")++ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.GET("/check", handler.CheckImageUpdate)+ apiGroup.GET("/check/:imageId", handler.CheckImageUpdateByID)+ apiGroup.POST("/check-batch", handler.CheckMultipleImages)+ apiGroup.GET("/check-all", handler.CheckAllImages)+ apiGroup.GET("/summary", handler.GetUpdateSummary)+ apiGroup.GET("/versions", handler.GetImageVersions)+ apiGroup.POST("/compare", handler.CompareVersions)}}diff --git a/backend/internal/api/network_handler.go b/backend/internal/api/network_handler.goindex e2d158511..e2dac56b7 100644--- a/backend/internal/api/network_handler.go+++ b/backend/internal/api/network_handler.go@@ -15,9 +15,19 @@ type NetworkHandler struct {networkService *services.NetworkService}-func NewNetworkHandler(networkService *services.NetworkService) *NetworkHandler {- return &NetworkHandler{- networkService: networkService,+func NewNetworkHandler(group *gin.RouterGroup, networkService *services.NetworkService, authMiddleware *middleware.AuthMiddleware) {+ handler := &NetworkHandler{networkService: networkService}++ apiGroup := group.Group("/networks")+ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.GET("", handler.List)+ apiGroup.GET("/:id", handler.GetByID)+ apiGroup.POST("", handler.Create)+ apiGroup.DELETE("/:id", handler.Remove)+ apiGroup.POST("/:id/connect", handler.ConnectContainer)+ apiGroup.POST("/:id/disconnect", handler.DisconnectContainer)+ apiGroup.POST("/prune", handler.Prune)}}diff --git a/backend/internal/api/oidc_handler.go b/backend/internal/api/oidc_handler.goindex 1c45a2f8b..25456ad51 100644--- a/backend/internal/api/oidc_handler.go+++ b/backend/internal/api/oidc_handler.go@@ -16,11 +16,16 @@ type OidcHandler struct {appConfig *config.Config}-func NewOidcHandler(authService *services.AuthService, oidcService *services.OidcService, appConfig *config.Config) *OidcHandler {- return &OidcHandler{- authService: authService,- oidcService: oidcService,- appConfig: appConfig,+func NewOidcHandler(group *gin.RouterGroup, authService *services.AuthService, oidcService *services.OidcService, appConfig *config.Config) {++ handler := &OidcHandler{authService: authService, oidcService: oidcService, appConfig: appConfig}++ apiGroup := group.Group("/oidc")+ {+ apiGroup.POST("/url", handler.GetOidcAuthUrl)+ apiGroup.POST("/callback", handler.HandleOidcCallback)+ apiGroup.GET("/config", handler.GetOidcConfig)+ apiGroup.GET("/status", handler.GetOidcStatus)}}diff --git a/backend/internal/api/routes.go b/backend/internal/api/routes.godeleted file mode 100644index 0dd307eee..000000000--- a/backend/internal/api/routes.go+++ /dev/null@@ -1,367 +0,0 @@-package api--import (- "github.com/gin-gonic/gin"- "github.com/ofkm/arcane-backend/internal/config"- "github.com/ofkm/arcane-backend/internal/middleware"- "github.com/ofkm/arcane-backend/internal/services"-)--type Services struct {- User *services.UserService- Stack *services.StackService- Environment *services.EnvironmentService- Settings *services.SettingsService- Container *services.ContainerService- Image *services.ImageService- Volume *services.VolumeService- Network *services.NetworkService- ImageUpdate *services.ImageUpdateService- Auth *services.AuthService- Oidc *services.OidcService- Docker *services.DockerClientService- Converter *services.ConverterService- Template *services.TemplateService- ContainerRegistry *services.ContainerRegistryService- System *services.SystemService- Updater *services.UpdaterService- Event *services.EventService-}--func SetupRoutes(r *gin.Engine, services *Services, appConfig *config.Config) {- api := r.Group("/api")-- setupAuthRoutes(api, services)- setupOidcRoutes(api, services, appConfig)- setupUserRoutes(api, services)- setupStackRoutes(api, services)- setupEnvironmentRoutes(api, services)- setupSettingsRoutes(api, services, appConfig)- setupSystemRoutes(api, services.Docker, services)- setupContainerRoutes(api, services)- setupImageRoutes(api, services)- setupVolumeRoutes(api, services)- setupNetworkRoutes(api, services)- setupTemplateRoutes(api, services)- setupContainerRegistryRoutes(api, services)- setupConverterRoutes(api, services)- setupImageUpdateRoutes(api, services)- setupEventRoutes(api, services)- setupUpdaterRoutes(api, services)-}--func setupContainerRegistryRoutes(api *gin.RouterGroup, services *Services) {- registries := api.Group("/container-registries")- registries.Use(middleware.AuthMiddleware(services.Auth))-- registryHandler := NewContainerRegistryHandler(services.ContainerRegistry)-- registries.GET("", registryHandler.GetRegistries)- registries.POST("", registryHandler.CreateRegistry)- registries.GET("/:id", registryHandler.GetRegistry)- registries.PUT("/:id", registryHandler.UpdateRegistry)- registries.DELETE("/:id", registryHandler.DeleteRegistry)-- registries.POST("/:id/test", registryHandler.TestRegistry)-}--func setupImageUpdateRoutes(api *gin.RouterGroup, services *Services) {- imageUpdates := api.Group("/image-updates")- imageUpdates.Use(middleware.AuthMiddleware(services.Auth))- imageUpdateHandler := NewImageUpdateHandler(services.ImageUpdate)-- imageUpdates.GET("/check", imageUpdateHandler.CheckImageUpdate)- imageUpdates.GET("/check/:imageId", imageUpdateHandler.CheckImageUpdateByID)- imageUpdates.POST("/check-batch", imageUpdateHandler.CheckMultipleImages)- imageUpdates.GET("/check-all", imageUpdateHandler.CheckAllImages)- imageUpdates.GET("/summary", imageUpdateHandler.GetUpdateSummary)- imageUpdates.GET("/versions", imageUpdateHandler.GetImageVersions)- imageUpdates.POST("/compare", imageUpdateHandler.CompareVersions)--}--func setupOidcRoutes(api *gin.RouterGroup, services *Services, appConfig *config.Config) {- oidcHandler := NewOidcHandler(services.Auth, services.Oidc, appConfig)- oidc := api.Group("/oidc")- {- oidc.POST("/url", oidcHandler.GetOidcAuthUrl)- oidc.POST("/callback", oidcHandler.HandleOidcCallback)- oidc.GET("/config", oidcHandler.GetOidcConfig)- oidc.GET("/status", oidcHandler.GetOidcStatus)- }-}--func setupAuthRoutes(api *gin.RouterGroup, services *Services) {- auth := api.Group("/auth")-- authHandler := NewAuthHandler(services.User, services.Auth, services.Oidc)-- auth.POST("/login", authHandler.Login)- auth.POST("/logout", authHandler.Logout)- auth.GET("/me", middleware.AuthMiddleware(services.Auth), authHandler.GetCurrentUser)- auth.POST("/refresh", authHandler.RefreshToken)- auth.POST("/password", middleware.AuthMiddleware(services.Auth), authHandler.ChangePassword)--}--func setupUserRoutes(api *gin.RouterGroup, services *Services) {- users := api.Group("/users")- users.Use(middleware.AuthMiddleware(services.Auth))-- userHandler := NewUserHandler(services.User)-- users.GET("", userHandler.ListUsers)- users.POST("", userHandler.CreateUser)- users.GET("/:id", userHandler.GetUser)- users.PUT("/:id", userHandler.UpdateUser)- users.DELETE("/:id", userHandler.DeleteUser)-}--func setupStackRoutes(router *gin.RouterGroup, services *Services) {- stacks := router.Group("/stacks")- stacks.Use(middleware.AuthMiddleware(services.Auth))-- stackHandler := NewStackHandler(services.Stack)-- stacks.GET("", stackHandler.ListStacks)- stacks.POST("", stackHandler.CreateStack)- stacks.GET("/:id", stackHandler.GetStack)- stacks.PUT("/:id", stackHandler.UpdateStack)- stacks.DELETE("/:id", stackHandler.DeleteStack)- stacks.POST("/:id/deploy", stackHandler.DeployStack)- stacks.POST("/:id/stop", stackHandler.StopStack)- stacks.POST("/:id/restart", stackHandler.RestartStack)- stacks.GET("/:id/services", stackHandler.GetStackServices)- stacks.POST("/:id/pull", stackHandler.PullImages)- stacks.POST("/:id/redeploy", stackHandler.RedeployStack)- stacks.POST("/:id/down", stackHandler.DownStack)- stacks.DELETE("/:id/destroy", stackHandler.DestroyStack)- stacks.GET("/:id/logs/stream", stackHandler.GetStackLogsStream)-}--func setupConverterRoutes(api *gin.RouterGroup, services *Services) {- convert := api.Group("/convert")- convert.Use(middleware.AuthMiddleware(services.Auth))-- convertHandler := NewConverterHandler(services.Converter)-- convert.POST("", convertHandler.ConvertDockerRun)-}--func setupEnvironmentRoutes(api *gin.RouterGroup, services *Services) {- environments := api.Group("/environments")- environments.Use(middleware.AuthMiddleware(services.Auth))-- environmentHandler := NewEnvironmentHandler(- services.Environment,- services.Container,- services.Image,- services.Network,- services.Volume,- services.Stack,- )-- environments.GET("", environmentHandler.ListEnvironments)- environments.POST("", environmentHandler.CreateEnvironment)- environments.GET("/:id", environmentHandler.GetEnvironment)- environments.PUT("/:id", environmentHandler.UpdateEnvironment)- environments.DELETE("/:id", environmentHandler.DeleteEnvironment)- environments.POST("/:id/test", environmentHandler.TestConnection)- environments.POST("/:id/heartbeat", environmentHandler.UpdateHeartbeat)-- environments.POST("/:id/containers", environmentHandler.CreateContainer)- environments.GET("/:id/containers", environmentHandler.GetContainers)- environments.GET("/:id/containers/:containerId", environmentHandler.GetContainer)- environments.POST("/:id/containers/:containerId/pull", environmentHandler.PullContainerImage)- environments.POST("/:id/containers/:containerId/start", environmentHandler.StartContainer)- environments.POST("/:id/containers/:containerId/stop", environmentHandler.StopContainer)- environments.POST("/:id/containers/:containerId/restart", environmentHandler.RestartContainer)- environments.DELETE("/:id/containers/:containerId", environmentHandler.RemoveContainer)- environments.GET("/:id/containers/:containerId/logs", environmentHandler.GetContainerLogs)- environments.GET("/:id/containers/:containerId/logs/stream", environmentHandler.GetContainerLogsStream)- environments.GET("/:id/containers/:containerId/stats", environmentHandler.GetContainerStats)- environments.GET("/:id/containers/:containerId/stats/stream", environmentHandler.GetContainerStatsStream)-- environments.GET("/:id/images", environmentHandler.GetImages)- environments.GET("/:id/images/:imageId", environmentHandler.GetImage)- environments.DELETE("/:id/images/:imageId", environmentHandler.RemoveImage)- environments.POST("/:id/images/pull", environmentHandler.PullImage)- environments.POST("/:id/images/prune", environmentHandler.PruneImages)- environments.GET("/:id/images/total-size", environmentHandler.GetTotalImageSize)-- environments.GET("/:id/networks", environmentHandler.GetNetworks)- environments.POST("/:id/networks", environmentHandler.CreateNetwork)- environments.GET("/:id/networks/:networkId", environmentHandler.GetNetwork)- environments.DELETE("/:id/networks/:networkId", environmentHandler.RemoveNetwork)-- environments.GET("/:id/volumes", environmentHandler.GetVolumes)- environments.POST("/:id/volumes", environmentHandler.CreateVolume)- environments.GET("/:id/volumes/:volumeName", environmentHandler.GetVolume)- environments.DELETE("/:id/volumes/:volumeName", environmentHandler.RemoveVolume)- environments.GET("/:id/volumes/:volumeName/usage", environmentHandler.GetVolumeUsage)-- environments.POST("/:id/volumes/prune", environmentHandler.PruneVolumes)-- environments.GET("/:id/stacks", environmentHandler.GetStacks)- environments.POST("/:id/stacks", environmentHandler.CreateStack)- environments.GET("/:id/stacks/:stackId", environmentHandler.GetStack)- environments.PUT("/:id/stacks/:stackId", environmentHandler.UpdateStack)- environments.DELETE("/:id/stacks/:stackId", environmentHandler.DeleteStack)- environments.POST("/:id/stacks/:stackId/start", environmentHandler.StartStack)- environments.POST("/:id/stacks/:stackId/deploy", environmentHandler.DeployStack)- environments.POST("/:id/stacks/:stackId/stop", environmentHandler.StopStack)- environments.POST("/:id/stacks/:stackId/restart", environmentHandler.RestartStack)- environments.GET("/:id/stacks/:stackId/services", environmentHandler.GetStackServices)- environments.POST("/:id/stacks/:stackId/pull", environmentHandler.PullStackImages)- environments.POST("/:id/stacks/:stackId/redeploy", environmentHandler.RedeployStack)- environments.POST("/:id/stacks/:stackId/down", environmentHandler.DownStack)- environments.DELETE("/:id/stacks/:stackId/destroy", environmentHandler.DestroyStack)- environments.GET("/:id/stacks/:stackId/logs/stream", environmentHandler.GetStackLogsStream)- environments.POST("/:id/stacks/convert", environmentHandler.ConvertDockerRun)--}--func setupSettingsRoutes(api *gin.RouterGroup, services *Services, appConfig *config.Config) {- settings := api.Group("/settings")-- settingsHandler := NewSettingsHandler(services.Settings)- settings.GET("/public", settingsHandler.GetPublicSettings)- settings.GET("", settingsHandler.GetSettings)- settings.PUT("", settingsHandler.UpdateSettings)- // settings.PUT("/auth", settingsHandler.UpdateAuth)- // settings.PUT("/onboarding", settingsHandler.UpdateOnboarding)- // settings.POST("/registry-credentials", settingsHandler.AddRegistryCredential)- oidcHandler := NewOidcHandler(services.Auth, services.Oidc, appConfig)- settings.GET("/oidc/status", oidcHandler.GetOidcStatus)- settings.GET("/oidc/config", oidcHandler.GetOidcConfig)- settings.POST("/oidc/url", oidcHandler.GetOidcAuthUrl)- settings.POST("/oidc/callback", oidcHandler.HandleOidcCallback)-}--func setupSystemRoutes(api *gin.RouterGroup, dockerService *services.DockerClientService, services *Services) {- system := api.Group("/system")- system.Use(middleware.AuthMiddleware(services.Auth))-- systemHandler := NewSystemHandler(dockerService, services.System)-- system.GET("/stats", systemHandler.GetStats)- system.GET("/docker/info", systemHandler.GetDockerInfo)-- system.POST("/prune", systemHandler.PruneAll)- system.POST("/containers/start-all", systemHandler.StartAllContainers)- system.POST("/containers/start-stopped", systemHandler.StartAllStoppedContainers)- system.POST("/containers/stop-all", systemHandler.StopAllContainers)-}--func setupUpdaterRoutes(api *gin.RouterGroup, services *Services) {- autoUpdate := api.Group("/updater")- autoUpdate.Use(middleware.AuthMiddleware(services.Auth))-- updaterHandler := NewUpdaterHandler(services.Updater)-- autoUpdate.POST("/run", updaterHandler.Run)- autoUpdate.GET("/history", updaterHandler.History)- autoUpdate.GET("/status", updaterHandler.Status)-}--func setupContainerRoutes(api *gin.RouterGroup, services *Services) {- containers := api.Group("/containers")- containers.Use(middleware.AuthMiddleware(services.Auth))-- containerHandler := NewContainerHandler(services.Container, services.Image)-- containers.GET("", containerHandler.List)- containers.POST("", containerHandler.Create)- containers.GET("/:id", containerHandler.GetByID)- containers.GET("/:id/stats", containerHandler.GetStats)- containers.GET("/:id/stats/stream", containerHandler.GetStatsStream)- containers.POST("/:id/start", containerHandler.Start)- containers.POST("/:id/stop", containerHandler.Stop)- containers.POST("/:id/restart", containerHandler.Restart)- containers.GET("/:id/logs", containerHandler.GetLogs)- containers.GET("/:id/logs/stream", containerHandler.GetLogsStream)- containers.DELETE("/:id", containerHandler.Delete)-}--func setupImageRoutes(api *gin.RouterGroup, services *Services) {- images := api.Group("/images")- images.Use(middleware.AuthMiddleware(services.Auth))-- imageHandler := NewImageHandler(services.Image, services.ImageUpdate)-- images.GET("", imageHandler.List)- images.GET("/:id", imageHandler.GetByID)- images.DELETE("/:id", imageHandler.Remove)- images.POST("/pull", imageHandler.Pull)- images.POST("/prune", imageHandler.Prune)- images.GET("/:id/history", imageHandler.GetHistory)- images.GET("/total-size", imageHandler.GetTotalSize)-}--func setupVolumeRoutes(api *gin.RouterGroup, services *Services) {- volumes := api.Group("/volumes")- volumes.Use(middleware.AuthMiddleware(services.Auth))-- volumeHandler := NewVolumeHandler(services.Volume)-- volumes.GET("", volumeHandler.List)- volumes.GET("/:volumeName", volumeHandler.GetByName)- volumes.POST("", volumeHandler.Create)- volumes.DELETE("/:volumeName", volumeHandler.Remove)- volumes.POST("/prune", volumeHandler.Prune)- volumes.GET("/:volumeName/usage", volumeHandler.GetUsage)-}--func setupNetworkRoutes(api *gin.RouterGroup, services *Services) {- networks := api.Group("/networks")- networks.Use(middleware.AuthMiddleware(services.Auth))-- networkHandler := NewNetworkHandler(services.Network)-- networks.GET("", networkHandler.List)- networks.GET("/:id", networkHandler.GetByID)- networks.POST("", networkHandler.Create)- networks.DELETE("/:id", networkHandler.Remove)- networks.POST("/:id/connect", networkHandler.ConnectContainer)- networks.POST("/:id/disconnect", networkHandler.DisconnectContainer)- networks.POST("/prune", networkHandler.Prune)-}--func setupTemplateRoutes(router *gin.RouterGroup, services *Services) {- templates := router.Group("/templates")-- templateHandler := NewTemplateHandler(services.Template)-- templates.GET("/fetch", templateHandler.FetchRegistry)-- templates.GET("", middleware.OptionalAuthMiddleware(services.Auth), templateHandler.GetAllTemplates)- templates.GET("/:id", middleware.OptionalAuthMiddleware(services.Auth), templateHandler.GetTemplate)- templates.GET("/:id/content", middleware.OptionalAuthMiddleware(services.Auth), templateHandler.GetTemplateContent)-- templatesAuth := templates.Group("/")- templatesAuth.Use(middleware.AuthMiddleware(services.Auth))- {- templatesAuth.POST("", templateHandler.CreateTemplate)- templatesAuth.PUT("/:id", templateHandler.UpdateTemplate)- templatesAuth.DELETE("/:id", templateHandler.DeleteTemplate)- templatesAuth.POST("/:id/download", templateHandler.DownloadTemplate)- templatesAuth.GET("/env/default", templateHandler.GetEnvTemplate)- templatesAuth.POST("/env/default", templateHandler.SaveEnvTemplate)- templatesAuth.GET("/registries", templateHandler.GetRegistries)- templatesAuth.POST("/registries", templateHandler.CreateRegistry)- templatesAuth.PUT("/registries/:id", templateHandler.UpdateRegistry)- templatesAuth.DELETE("/registries/:id", templateHandler.DeleteRegistry)- }-}--func setupEventRoutes(api *gin.RouterGroup, services *Services) {- events := api.Group("/events")- events.Use(middleware.AuthMiddleware(services.Auth))-- eventHandler := NewEventHandler(services.Event)-- events.GET("", eventHandler.ListEvents)- events.POST("", eventHandler.CreateEvent)- events.DELETE("/:eventId", eventHandler.DeleteEvent)- events.GET("/environment/:environmentId", eventHandler.GetEventsByEnvironment)-}diff --git a/backend/internal/api/settings_handler.go b/backend/internal/api/settings_handler.goindex 11ca316b2..a0148c86f 100644--- a/backend/internal/api/settings_handler.go+++ b/backend/internal/api/settings_handler.go@@ -5,6 +5,7 @@ import ("github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/dto"+ "github.com/ofkm/arcane-backend/internal/middleware""github.com/ofkm/arcane-backend/internal/services")@@ -12,10 +13,14 @@ type SettingsHandler struct {settingsService *services.SettingsService}-func NewSettingsHandler(settingsService *services.SettingsService) *SettingsHandler {- return &SettingsHandler{- settingsService: settingsService,- }+func NewSettingsHandler(group *gin.RouterGroup, settingsService *services.SettingsService, authMiddleware *middleware.AuthMiddleware) {+ handler := &SettingsHandler{settingsService: settingsService}++ apiGroup := group.Group("/settings")++ apiGroup.GET("/public", handler.GetPublicSettings)+ apiGroup.GET("", authMiddleware.WithAdminNotRequired().Add(), handler.GetSettings)+ apiGroup.PUT("", authMiddleware.WithAdminRequired().Add(), handler.UpdateSettings)}func (h *SettingsHandler) GetSettings(c *gin.Context) {diff --git a/backend/internal/api/stack_handler.go b/backend/internal/api/stack_handler.goindex 83156319d..53bc3c781 100644--- a/backend/internal/api/stack_handler.go+++ b/backend/internal/api/stack_handler.go@@ -17,14 +17,30 @@ import ()type StackHandler struct {- stackService *services.StackService- converterService *services.ConverterService+ stackService *services.StackService}-func NewStackHandler(stackService *services.StackService) *StackHandler {- return &StackHandler{- stackService: stackService,- converterService: services.NewConverterService(),+func NewStackHandler(group *gin.RouterGroup, stackService *services.StackService, authMiddleware *middleware.AuthMiddleware) {++ handler := &StackHandler{stackService: stackService}++ apiGroup := group.Group("/stacks")+ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.GET("", handler.ListStacks)+ apiGroup.POST("", handler.CreateStack)+ apiGroup.GET("/:id", handler.GetStack)+ apiGroup.PUT("/:id", handler.UpdateStack)+ apiGroup.DELETE("/:id", handler.DeleteStack)+ apiGroup.POST("/:id/deploy", handler.DeployStack)+ apiGroup.POST("/:id/stop", handler.StopStack)+ apiGroup.POST("/:id/restart", handler.RestartStack)+ apiGroup.GET("/:id/services", handler.GetStackServices)+ apiGroup.POST("/:id/pull", handler.PullImages)+ apiGroup.POST("/:id/redeploy", handler.RedeployStack)+ apiGroup.POST("/:id/down", handler.DownStack)+ apiGroup.DELETE("/:id/destroy", handler.DestroyStack)+ apiGroup.GET("/:id/logs/stream", handler.GetStackLogsStream)}}diff --git a/backend/internal/api/system_handler.go b/backend/internal/api/system_handler.goindex c2c10fcf1..1a2755a95 100644--- a/backend/internal/api/system_handler.go+++ b/backend/internal/api/system_handler.go@@ -10,6 +10,7 @@ import ("github.com/docker/docker/api/types/image""github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/dto"+ "github.com/ofkm/arcane-backend/internal/middleware""github.com/ofkm/arcane-backend/internal/services""github.com/shirou/gopsutil/v3/cpu""github.com/shirou/gopsutil/v3/disk"@@ -22,10 +23,19 @@ type SystemHandler struct {systemService *services.SystemService}-func NewSystemHandler(dockerService *services.DockerClientService, systemService *services.SystemService) *SystemHandler {- return &SystemHandler{- dockerService: dockerService,- systemService: systemService,+func NewSystemHandler(group *gin.RouterGroup, dockerService *services.DockerClientService, systemService *services.SystemService, authMiddleware *middleware.AuthMiddleware) {+ handler := &SystemHandler{dockerService: dockerService, systemService: systemService}++ apiGroup := group.Group("/system")+ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.GET("/stats", handler.GetStats)+ apiGroup.GET("/docker/info", handler.GetDockerInfo)++ apiGroup.POST("/prune", handler.PruneAll)+ apiGroup.POST("/containers/start-all", handler.StartAllContainers)+ apiGroup.POST("/containers/start-stopped", handler.StartAllStoppedContainers)+ apiGroup.POST("/containers/stop-all", handler.StopAllContainers)}}diff --git a/backend/internal/api/template_handler.go b/backend/internal/api/template_handler.goindex a1ab38aaa..8d4da3f27 100644--- a/backend/internal/api/template_handler.go+++ b/backend/internal/api/template_handler.go@@ -11,6 +11,7 @@ import ("github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/dto"+ "github.com/ofkm/arcane-backend/internal/middleware""github.com/ofkm/arcane-backend/internal/models""github.com/ofkm/arcane-backend/internal/services")@@ -19,9 +20,29 @@ type TemplateHandler struct {templateService *services.TemplateService}-func NewTemplateHandler(templateService *services.TemplateService) *TemplateHandler {- return &TemplateHandler{- templateService: templateService,+func NewTemplateHandler(group *gin.RouterGroup, templateService *services.TemplateService, authMiddleware *middleware.AuthMiddleware) {+ handler := &TemplateHandler{templateService: templateService}++ apiGroup := group.Group("/templates")++ apiGroup.GET("/fetch", handler.FetchRegistry)++ apiGroup.GET("", authMiddleware.WithAdminNotRequired().WithSuccessOptional().Add(), handler.GetAllTemplates)+ apiGroup.GET("/:id", authMiddleware.WithAdminNotRequired().WithSuccessOptional().Add(), handler.GetTemplate)+ apiGroup.GET("/:id/content", authMiddleware.WithAdminNotRequired().WithSuccessOptional().Add(), handler.GetTemplateContent)++ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.POST("", handler.CreateTemplate)+ apiGroup.PUT("/:id", handler.UpdateTemplate)+ apiGroup.DELETE("/:id", handler.DeleteTemplate)+ apiGroup.POST("/:id/download", handler.DownloadTemplate)+ apiGroup.GET("/env/default", handler.GetEnvTemplate)+ apiGroup.POST("/env/default", handler.SaveEnvTemplate)+ apiGroup.GET("/registries", handler.GetRegistries)+ apiGroup.POST("/registries", handler.CreateRegistry)+ apiGroup.PUT("/registries/:id", handler.UpdateRegistry)+ apiGroup.DELETE("/registries/:id", handler.DeleteRegistry)}}diff --git a/backend/internal/api/updater_handler.go b/backend/internal/api/updater_handler.goindex cf54c4dff..25f121130 100644--- a/backend/internal/api/updater_handler.go+++ b/backend/internal/api/updater_handler.go@@ -6,6 +6,7 @@ import ("github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/dto"+ "github.com/ofkm/arcane-backend/internal/middleware""github.com/ofkm/arcane-backend/internal/services")@@ -13,8 +14,16 @@ type UpdaterHandler struct {updaterService *services.UpdaterService}-func NewUpdaterHandler(updaterService *services.UpdaterService) *UpdaterHandler {- return &UpdaterHandler{updaterService: updaterService}+func NewUpdaterHandler(group *gin.RouterGroup, updaterService *services.UpdaterService, authMiddleware *middleware.AuthMiddleware) {+ handler := &UpdaterHandler{updaterService: updaterService}++ apiGroup := group.Group("/updater")+ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.POST("/run", handler.Run)+ apiGroup.GET("/history", handler.History)+ apiGroup.GET("/status", handler.Status)+ }}func (h *UpdaterHandler) Run(c *gin.Context) {diff --git a/backend/internal/api/user_handler.go b/backend/internal/api/user_handler.goindex b08a67137..e09918ae8 100644--- a/backend/internal/api/user_handler.go+++ b/backend/internal/api/user_handler.go@@ -6,6 +6,7 @@ import ("github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/dto"+ "github.com/ofkm/arcane-backend/internal/middleware""github.com/ofkm/arcane-backend/internal/models""github.com/ofkm/arcane-backend/internal/services""github.com/ofkm/arcane-backend/internal/utils"@@ -15,9 +16,18 @@ type UserHandler struct {userService *services.UserService}-func NewUserHandler(userService *services.UserService) *UserHandler {- return &UserHandler{- userService: userService,+func NewUserHandler(group *gin.RouterGroup, userService *services.UserService, authMiddleware *middleware.AuthMiddleware) {++ handler := &UserHandler{userService: userService}++ apiGroup := group.Group("/users")+ apiGroup.Use(authMiddleware.WithAdminRequired().Add())+ {+ apiGroup.GET("", handler.ListUsers)+ apiGroup.POST("", handler.CreateUser)+ apiGroup.GET("/:id", handler.GetUser)+ apiGroup.PUT("/:id", handler.UpdateUser)+ apiGroup.DELETE("/:id", handler.DeleteUser)}}diff --git a/backend/internal/api/volume_handler.go b/backend/internal/api/volume_handler.goindex bf0d5087a..7139b858c 100644--- a/backend/internal/api/volume_handler.go+++ b/backend/internal/api/volume_handler.go@@ -7,17 +7,26 @@ import ("github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/dto""github.com/ofkm/arcane-backend/internal/middleware"- github_com_ofkm_arcane_backend_internal_services "github.com/ofkm/arcane-backend/internal/services"+ "github.com/ofkm/arcane-backend/internal/services""github.com/ofkm/arcane-backend/internal/utils")type VolumeHandler struct {- volumeService *github_com_ofkm_arcane_backend_internal_services.VolumeService+ volumeService *services.VolumeService}-func NewVolumeHandler(volumeService *github_com_ofkm_arcane_backend_internal_services.VolumeService) *VolumeHandler {- return &VolumeHandler{- volumeService: volumeService,+func NewVolumeHandler(group *gin.RouterGroup, volumeService *services.VolumeService, authMiddleware *middleware.AuthMiddleware) {+ handler := &VolumeHandler{volumeService: volumeService}++ apiGroup := group.Group("/volumes")+ apiGroup.Use(authMiddleware.WithAdminNotRequired().Add())+ {+ apiGroup.GET("", handler.List)+ apiGroup.GET("/:volumeName", handler.GetByName)+ apiGroup.POST("", handler.Create)+ apiGroup.DELETE("/:volumeName", handler.Remove)+ apiGroup.POST("/prune", handler.Prune)+ apiGroup.GET("/:volumeName/usage", handler.GetUsage)}}diff --git a/backend/internal/bootstrap/bootstrap.go b/backend/internal/bootstrap/bootstrap.goindex c2f31d469..396fd7ded 100644--- a/backend/internal/bootstrap/bootstrap.go+++ b/backend/internal/bootstrap/bootstrap.go@@ -14,7 +14,6 @@ import ("github.com/gin-gonic/gin""github.com/joho/godotenv"- "github.com/ofkm/arcane-backend/internal/api""github.com/ofkm/arcane-backend/internal/config""github.com/ofkm/arcane-backend/internal/database""github.com/ofkm/arcane-backend/internal/job"@@ -26,18 +25,16 @@ type App struct {DB *database.DBRouter *gin.EngineScheduler *job.Scheduler- Services *api.Services+ Services *ServicesAppCtx context.ContextCancelApp context.CancelFunc}func InitializeApp() (*App, error) {ctx := context.Background()-loadErr := godotenv.Load()-cfg := config.Load()-+ utils.InitEncryption(cfg)SetupLogger(cfg)ConfigureGormLogger(cfg)@@ -47,8 +44,6 @@ func InitializeApp() (*App, error) {appCtx, cancelApp := context.WithCancel(ctx)- utils.InitEncryption(cfg)-db, err := initializeDBAndMigrate(cfg)if err != nil {cancelApp()diff --git a/backend/internal/bootstrap/jobs_bootstrap.go b/backend/internal/bootstrap/jobs_bootstrap.goindex bf2c138d4..00231f211 100644--- a/backend/internal/bootstrap/jobs_bootstrap.go+++ b/backend/internal/bootstrap/jobs_bootstrap.go@@ -5,7 +5,6 @@ import ("fmt""log/slog"- "github.com/ofkm/arcane-backend/internal/api""github.com/ofkm/arcane-backend/internal/job")@@ -17,7 +16,7 @@ func initializeScheduler() (*job.Scheduler, error) {return scheduler, nil}-func registerJobs(appCtx context.Context, scheduler *job.Scheduler, appServices *api.Services) {+func registerJobs(appCtx context.Context, scheduler *job.Scheduler, appServices *Services) {if err := job.RegisterAutoUpdateJob(appCtx, scheduler, appServices.Updater, appServices.Settings); err != nil {slog.ErrorContext(appCtx, "Failed to register auto-update job", slog.Any("error", err))}diff --git a/backend/internal/bootstrap/playwright_router_bootstrap.go b/backend/internal/bootstrap/playwright_router_bootstrap.goindex 0e1384091..7b56f9713 100644--- a/backend/internal/bootstrap/playwright_router_bootstrap.go+++ b/backend/internal/bootstrap/playwright_router_bootstrap.go@@ -11,8 +11,8 @@ import ()func init() {- registerPlaywrightRoutes = []func(apiGroup *gin.RouterGroup, services *api.Services){- func(apiGroup *gin.RouterGroup, svc *api.Services) {+ registerPlaywrightRoutes = []func(apiGroup *gin.RouterGroup, services *Services){+ func(apiGroup *gin.RouterGroup, svc *Services) {playwrightService := services.NewPlaywrightService(svc.Settings)if playwrightService == nil {slog.Warn("Playwright service not available, skipping playwright routes")diff --git a/backend/internal/bootstrap/router_bootstrap.go b/backend/internal/bootstrap/router_bootstrap.goindex d57899801..cbaa9860d 100644--- a/backend/internal/bootstrap/router_bootstrap.go+++ b/backend/internal/bootstrap/router_bootstrap.go@@ -15,9 +15,9 @@ import ("github.com/ofkm/arcane-backend/internal/middleware")-var registerPlaywrightRoutes []func(apiGroup *gin.RouterGroup, services *api.Services)+var registerPlaywrightRoutes []func(apiGroup *gin.RouterGroup, services *Services)-func setupRouter(cfg *config.Config, appServices *api.Services) *gin.Engine {+func setupRouter(cfg *config.Config, appServices *Services) *gin.Engine {if cfg.Environment == "production" {gin.SetMode(gin.ReleaseMode)@@ -37,6 +37,7 @@ func setupRouter(cfg *config.Config, appServices *api.Services) *gin.Engine {"GET /health","HEAD /health",}+router.Use(sloggin.NewWithConfig(slog.Default(), sloggin.Config{Filters: []sloggin.Filter{func(c *gin.Context) bool {@@ -57,17 +58,32 @@ func setupRouter(cfg *config.Config, appServices *api.Services) *gin.Engine {},}))+ authMiddleware := middleware.NewAuthMiddleware(appServices.Auth)router.Use(middleware.SetupCORS(cfg))router.GET("/health", func(c *gin.Context) {c.JSON(http.StatusOK, gin.H{"status": "UP"})})- api.SetupRoutes(router, appServices, cfg)+ apiGroup := router.Group("/api")+ api.NewAuthHandler(apiGroup, appServices.User, appServices.Auth, appServices.Oidc, authMiddleware)+ api.NewContainerHandler(apiGroup, appServices.Container, appServices.Image, authMiddleware)+ api.NewContainerRegistryHandler(apiGroup, appServices.ContainerRegistry, authMiddleware)+ api.NewConverterHandler(apiGroup, appServices.Converter, authMiddleware)+ api.NewEnvironmentHandler(apiGroup, appServices.Environment, appServices.Container, appServices.Image, appServices.Network, appServices.Volume, appServices.Stack, authMiddleware)+ api.NewEventHandler(apiGroup, appServices.Event, authMiddleware)+ api.NewImageHandler(apiGroup, appServices.Image, appServices.ImageUpdate, authMiddleware)+ api.NewImageUpdateHandler(apiGroup, appServices.ImageUpdate, authMiddleware)+ api.NewNetworkHandler(apiGroup, appServices.Network, authMiddleware)+ api.NewOidcHandler(apiGroup, appServices.Auth, appServices.Oidc, cfg)+ api.NewSettingsHandler(apiGroup, appServices.Settings, authMiddleware)+ api.NewSystemHandler(apiGroup, appServices.Docker, appServices.System, authMiddleware)+ api.NewTemplateHandler(apiGroup, appServices.Template, authMiddleware)+ api.NewUpdaterHandler(apiGroup, appServices.Updater, authMiddleware)+ api.NewUserHandler(apiGroup, appServices.User, authMiddleware)+ api.NewVolumeHandler(apiGroup, appServices.Volume, authMiddleware)- // Register playwright routes if available- if registerPlaywrightRoutes != nil {- apiGroup := router.Group("/api")+ if cfg.Environment != "production" {for _, registerFunc := range registerPlaywrightRoutes {registerFunc(apiGroup, appServices)}diff --git a/backend/internal/bootstrap/services_bootstrap.go b/backend/internal/bootstrap/services_bootstrap.goindex e8bc09421..a877e10d3 100644--- a/backend/internal/bootstrap/services_bootstrap.go+++ b/backend/internal/bootstrap/services_bootstrap.go@@ -1,55 +1,54 @@package bootstrapimport (- "log/slog"-- "github.com/ofkm/arcane-backend/internal/api""github.com/ofkm/arcane-backend/internal/config""github.com/ofkm/arcane-backend/internal/database""github.com/ofkm/arcane-backend/internal/services")-func initializeServices(db *database.DB, cfg *config.Config) (*api.Services, *services.DockerClientService, error) {- slog.Info("Initializing services...")- eventService := services.NewEventService(db)- converterService := services.NewConverterService()- settingsService := services.NewSettingsService(db, cfg)- dockerClientService := services.NewDockerClientService(db)- userService := services.NewUserService(db)- containerRegistry := services.NewContainerRegistryService(db)- imageUpdate := services.NewImageUpdateService(db, settingsService, containerRegistry, dockerClientService, eventService)- imageService := services.NewImageService(db, dockerClientService, containerRegistry, imageUpdate, eventService)- stackService := services.NewStackService(db, settingsService, eventService, imageService)- environmentService := services.NewEnvironmentService(db)- containerService := services.NewContainerService(db, eventService, dockerClientService)- volumeService := services.NewVolumeService(db, dockerClientService, eventService)- networkService := services.NewNetworkService(db, dockerClientService, eventService)- templateService := services.NewTemplateService(db)- authService := services.NewAuthService(userService, settingsService, eventService, cfg.JWTSecret, cfg)- oidcService := services.NewOidcService(authService, cfg)- updaterService := services.NewUpdaterService(db, settingsService, dockerClientService, stackService, imageUpdate, containerRegistry, eventService, imageService)- systemService := services.NewSystemService(db, dockerClientService, containerService, imageService, volumeService, networkService, settingsService)+type Services struct {+ User *services.UserService+ Stack *services.StackService+ Environment *services.EnvironmentService+ Settings *services.SettingsService+ Container *services.ContainerService+ Image *services.ImageService+ Volume *services.VolumeService+ Network *services.NetworkService+ ImageUpdate *services.ImageUpdateService+ Auth *services.AuthService+ Oidc *services.OidcService+ Docker *services.DockerClientService+ Converter *services.ConverterService+ Template *services.TemplateService+ ContainerRegistry *services.ContainerRegistryService+ System *services.SystemService+ Updater *services.UpdaterService+ Event *services.EventService+}++func initializeServices(db *database.DB, cfg *config.Config) (*Services, *services.DockerClientService, error) {+ svc := &Services{}- appServices := &api.Services{- User: userService,- Stack: stackService,- Environment: environmentService,- Settings: settingsService,- Container: containerService,- Image: imageService,- Volume: volumeService,- Network: networkService,- Auth: authService,- Oidc: oidcService,- Docker: dockerClientService,- Converter: converterService,- Template: templateService,- ContainerRegistry: containerRegistry,- System: systemService,- Updater: updaterService,- ImageUpdate: imageUpdate,- Event: eventService,- }+ svc.Event = services.NewEventService(db)+ svc.Converter = services.NewConverterService()+ svc.Settings = services.NewSettingsService(db, cfg)+ dockerClient := services.NewDockerClientService(db)+ svc.Docker = dockerClient+ svc.User = services.NewUserService(db)+ svc.ContainerRegistry = services.NewContainerRegistryService(db)+ svc.ImageUpdate = services.NewImageUpdateService(db, svc.Settings, svc.ContainerRegistry, svc.Docker, svc.Event)+ svc.Image = services.NewImageService(db, svc.Docker, svc.ContainerRegistry, svc.ImageUpdate, svc.Event)+ svc.Stack = services.NewStackService(db, svc.Settings, svc.Event, svc.Image)+ svc.Environment = services.NewEnvironmentService(db)+ svc.Container = services.NewContainerService(db, svc.Event, svc.Docker)+ svc.Volume = services.NewVolumeService(db, svc.Docker, svc.Event)+ svc.Network = services.NewNetworkService(db, svc.Docker, svc.Event)+ svc.Template = services.NewTemplateService(db)+ svc.Auth = services.NewAuthService(svc.User, svc.Settings, svc.Event, cfg.JWTSecret, cfg)+ svc.Oidc = services.NewOidcService(svc.Auth, cfg)+ svc.Updater = services.NewUpdaterService(db, svc.Settings, svc.Docker, svc.Stack, svc.ImageUpdate, svc.ContainerRegistry, svc.Event, svc.Image)+ svc.System = services.NewSystemService(db, svc.Docker, svc.Container, svc.Image, svc.Volume, svc.Network, svc.Settings)- return appServices, dockerClientService, nil+ return svc, dockerClient, nil}diff --git a/backend/internal/middleware/auth_middleware.go b/backend/internal/middleware/auth_middleware.goindex ef2920ba6..69569f41f 100644--- a/backend/internal/middleware/auth_middleware.go+++ b/backend/internal/middleware/auth_middleware.go@@ -9,20 +9,52 @@ import ("github.com/ofkm/arcane-backend/internal/services")-func AuthMiddleware(authService *services.AuthService) gin.HandlerFunc {+type AuthOptions struct {+ AdminRequired bool+ SuccessOptional bool+}++type AuthMiddleware struct {+ authService *services.AuthService+ options AuthOptions+}++func NewAuthMiddleware(authService *services.AuthService) *AuthMiddleware {+ return &AuthMiddleware{+ authService: authService,+ options: AuthOptions{+ AdminRequired: false,+ SuccessOptional: false,+ },+ }+}++func (m *AuthMiddleware) WithAdminRequired() *AuthMiddleware {+ clone := *m+ clone.options.AdminRequired = true+ return &clone+}++func (m *AuthMiddleware) WithAdminNotRequired() *AuthMiddleware {+ clone := *m+ clone.options.AdminRequired = false+ return &clone+}++func (m *AuthMiddleware) WithSuccessOptional() *AuthMiddleware {+ clone := *m+ clone.options.SuccessOptional = true+ return &clone+}++func (m *AuthMiddleware) Add() gin.HandlerFunc {return func(c *gin.Context) {- authHeader := c.GetHeader("Authorization")- var tokenString string- if authHeader != "" && strings.HasPrefix(authHeader, "Bearer ") {- tokenString = strings.TrimPrefix(authHeader, "Bearer ")- }- if tokenString == "" {- tokenCookie, err := c.Cookie("token")- if err == nil {- tokenString = tokenCookie+ token := extractBearerOrCookieToken(c)+ if token == "" {+ if m.options.SuccessOptional {+ c.Next()+ return}- }- if tokenString == "" {c.JSON(http.StatusUnauthorized, models.APIError{Code: models.APIErrorCodeUnauthorized,Message: "Authentication required",@@ -30,8 +62,13 @@ func AuthMiddleware(authService *services.AuthService) gin.HandlerFunc {c.Abort()return}- user, err := authService.VerifyToken(c.Request.Context(), tokenString)++ user, err := m.authService.VerifyToken(c.Request.Context(), token)if err != nil {+ if m.options.SuccessOptional {+ c.Next()+ return+ }c.JSON(http.StatusUnauthorized, models.APIError{Code: models.APIErrorCodeUnauthorized,Message: "Invalid or expired token",@@ -40,14 +77,63 @@ func AuthMiddleware(authService *services.AuthService) gin.HandlerFunc {return}- // Store both userID and full user for handlers that expect currentUser+ isAdmin := userHasRole(user, "admin")+ if m.options.AdminRequired && !isAdmin {+ if m.options.SuccessOptional {+ c.Next()+ return+ }+ c.JSON(http.StatusForbidden, models.APIError{+ Code: "FORBIDDEN",+ Message: "You don't have permission to access this resource",+ })+ c.Abort()+ return+ }+c.Set("userID", user.ID)c.Set("currentUser", user)-+ c.Set("userIsAdmin", isAdmin)c.Next()}}+func extractBearerOrCookieToken(c *gin.Context) string {+ authHeader := c.GetHeader("Authorization")+ if authHeader != "" && strings.HasPrefix(authHeader, "Bearer ") {+ return strings.TrimPrefix(authHeader, "Bearer ")+ }+ if tokenCookie, err := c.Cookie("token"); err == nil && tokenCookie != "" {+ return tokenCookie+ }+ return ""+}++func userHasRole(user *models.User, role string) bool {+ for _, r := range user.Roles {+ if r == role {+ return true+ }+ }+ return false+}++// Backward-compatible helpers++// func AuthMiddlewareHandler(authService *services.AuthService) gin.HandlerFunc {+// return NewAuthMiddleware(authService).WithAdminNotRequired().Add()+// }++// func OptionalAuthMiddleware(authService *services.AuthService) gin.HandlerFunc {+// return NewAuthMiddleware(authService).WithAdminNotRequired().WithSuccessOptional().Add()+// }++// func AdminOnlyMiddleware(authService *services.AuthService) gin.HandlerFunc {+// return NewAuthMiddleware(authService).WithAdminRequired().Add()+// }++// Accessors+func GetCurrentUserID(c *gin.Context) (string, bool) {userID, exists := c.Get("userID")if !exists {@@ -62,70 +148,8 @@ func GetCurrentUser(c *gin.Context) (*models.User, bool) {if !exists {return nil, false}- userModel, ok := user.(*models.User)- return userModel, ok-}--func RoleMiddleware(roles ...string) gin.HandlerFunc {- return func(c *gin.Context) {- user, exists := GetCurrentUser(c)- if !exists {- c.JSON(http.StatusUnauthorized, models.APIError{- Code: models.APIErrorCodeUnauthorized,- Message: "Authentication required",- })- c.Abort()- return- }- hasRole := false- for _, requiredRole := range roles {- for _, userRole := range user.Roles {- if userRole == requiredRole {- hasRole = true- break- }- }- if hasRole {- break- }- }- if !hasRole {- c.JSON(http.StatusForbidden, models.APIError{- Code: "FORBIDDEN",- Message: "You don't have permission to access this resource",- })- c.Abort()- return- }- c.Next()- }-}--func OptionalAuthMiddleware(authService *services.AuthService) gin.HandlerFunc {- return func(c *gin.Context) {- authHeader := c.GetHeader("Authorization")- var tokenString string- if authHeader != "" && strings.HasPrefix(authHeader, "Bearer ") {- tokenString = strings.TrimPrefix(authHeader, "Bearer ")- }- if tokenString == "" {- tokenCookie, err := c.Cookie("token")- if err == nil {- tokenString = tokenCookie- }- }- if tokenString != "" {- user, err := authService.VerifyToken(c.Request.Context(), tokenString)- if err == nil {- c.Set("currentUser", user)- }- }- c.Next()- }-}--func AdminOnlyMiddleware() gin.HandlerFunc {- return RoleMiddleware("admin")+ u, ok := user.(*models.User)+ return u, ok}func IsAuthenticated(c *gin.Context) bool {diff --git a/frontend/src/lib/components/sidebar/sidebar-env-switcher.svelte b/frontend/src/lib/components/sidebar/sidebar-env-switcher.svelteindex c42f17f89..8396242df 100644--- a/frontend/src/lib/components/sidebar/sidebar-env-switcher.svelte+++ b/frontend/src/lib/components/sidebar/sidebar-env-switcher.svelte@@ -11,6 +11,12 @@import { goto } from '$app/navigation';import { toast } from 'svelte-sonner';+ type Props = {+ isAdmin?: boolean;+ };++ let { isAdmin = false }: Props = $props();+const sidebar = useSidebar();let currentSelectedEnvironment = $state<Environment | null>(null);@@ -121,12 +127,14 @@{/each}{/if}<DropdownMenu.Separator />- <DropdownMenu.Item class="gap-2 p-2" onSelect={() => goto('/environments')}>- <div class="flex size-6 items-center justify-center rounded-md border bg-transparent">- <PlusIcon class="size-4" />- </div>- <div class="text-muted-foreground font-medium">Manage Environments</div>- </DropdownMenu.Item>+ {#if isAdmin}+ <DropdownMenu.Item class="gap-2 p-2" onSelect={() => goto('/environments')}>+ <div class="flex size-6 items-center justify-center rounded-md border bg-transparent">+ <PlusIcon class="size-4" />+ </div>+ <div class="text-muted-foreground font-medium">Manage Environments</div>+ </DropdownMenu.Item>+ {/if}</DropdownMenu.Content></DropdownMenu.Root></Sidebar.MenuItem>diff --git a/frontend/src/lib/components/sidebar/sidebar.svelte b/frontend/src/lib/components/sidebar/sidebar.svelteindex fc79f3e7e..a1823b9aa 100644--- a/frontend/src/lib/components/sidebar/sidebar.svelte+++ b/frontend/src/lib/components/sidebar/sidebar.svelte@@ -36,6 +36,7 @@const effectiveUser = $derived(user ?? storeUser);const isCollapsed = $derived(sidebar.state === 'collapsed');+ const isAdmin = $derived(!!effectiveUser?.roles?.includes('admin'));</script><Sidebar.Root {collapsible} {...restProps}>@@ -46,8 +47,10 @@<Sidebar.Content><SidebarItemGroup label="Management" items={sidebarItems.managementItems} /><SidebarItemGroup label="Customization" items={sidebarItems.customizationItems} />- <SidebarItemGroup label="Environments" items={sidebarItems.environmentItems} />- <SidebarItemGroup label="Administration" items={sidebarItems.settingsItems} />+ {#if isAdmin}+ <SidebarItemGroup label="Environments" items={sidebarItems.environmentItems} />+ <SidebarItemGroup label="Administration" items={sidebarItems.settingsItems} />+ {/if}</Sidebar.Content><Sidebar.Footer><SidebarUpdatebanner {isCollapsed} {versionInformation} updateAvailable={versionInformation.updateAvailable} />