backup: pre-hardening baseline
This commit is contained in:
commit
9e4c612dcb
57 changed files with 10393 additions and 0 deletions
138
backend/internal/api/handlers/config.go
Normal file
138
backend/internal/api/handlers/config.go
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/traefik/traefik-gui/backend/internal/models"
|
||||
)
|
||||
|
||||
type ConfigHandler struct {
|
||||
traefikClient TraefikClient
|
||||
}
|
||||
|
||||
type TraefikClient interface {
|
||||
GetRouters(ctx context.Context) ([]models.Router, error)
|
||||
GetServices(ctx context.Context) ([]models.Service, error)
|
||||
GetMiddlewares(ctx context.Context) ([]models.Middleware, error)
|
||||
GetCertificates(ctx context.Context) ([]models.Certificate, error)
|
||||
GetEntryPoints(ctx context.Context) ([]models.EntryPoint, error)
|
||||
GetOverview(ctx context.Context) (*models.Overview, error)
|
||||
}
|
||||
|
||||
func NewConfigHandler(traefikClient TraefikClient) *ConfigHandler {
|
||||
return &ConfigHandler{traefikClient: traefikClient}
|
||||
}
|
||||
|
||||
func (h *ConfigHandler) ListRouters(c *gin.Context) {
|
||||
routers, err := h.traefikClient.GetRouters(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to fetch routers"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, routers)
|
||||
}
|
||||
|
||||
func (h *ConfigHandler) GetRouter(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
routers, err := h.traefikClient.GetRouters(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to fetch routers"})
|
||||
return
|
||||
}
|
||||
|
||||
for _, r := range routers {
|
||||
if r.Name == id {
|
||||
c.JSON(http.StatusOK, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "router not found"})
|
||||
}
|
||||
|
||||
func (h *ConfigHandler) CreateRouter(c *gin.Context) {
|
||||
var router models.Router
|
||||
if err := c.ShouldBindJSON(&router); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid router configuration"})
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Validate and persist to file provider (Phase 2)
|
||||
// For MVP, return success with mock data
|
||||
c.JSON(http.StatusCreated, gin.H{
|
||||
"message": "router created (mock)",
|
||||
"router": router,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *ConfigHandler) UpdateRouter(c *gin.Context) {
|
||||
_ = c.Param("id")
|
||||
var router models.Router
|
||||
if err := c.ShouldBindJSON(&router); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid router configuration"})
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Validate and persist to file provider (Phase 2)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "router updated (mock)",
|
||||
"router": router,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *ConfigHandler) DeleteRouter(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
|
||||
// TODO: Delete from file provider (Phase 2)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "router deleted (mock)",
|
||||
"id": id,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *ConfigHandler) ListServices(c *gin.Context) {
|
||||
services, err := h.traefikClient.GetServices(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to fetch services"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, services)
|
||||
}
|
||||
|
||||
func (h *ConfigHandler) ListMiddlewares(c *gin.Context) {
|
||||
middlewares, err := h.traefikClient.GetMiddlewares(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to fetch middlewares"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, middlewares)
|
||||
}
|
||||
|
||||
func (h *ConfigHandler) ListCertificates(c *gin.Context) {
|
||||
certs, err := h.traefikClient.GetCertificates(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to fetch certificates"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, certs)
|
||||
}
|
||||
|
||||
func (h *ConfigHandler) ListEntryPoints(c *gin.Context) {
|
||||
eps, err := h.traefikClient.GetEntryPoints(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to fetch entrypoints"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, eps)
|
||||
}
|
||||
|
||||
func (h *ConfigHandler) GetOverview(c *gin.Context) {
|
||||
overview, err := h.traefikClient.GetOverview(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to fetch overview"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, overview)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue