- Move ORM models from internal/model to pkg/model organized by module (auth/k8s/registry) - Add authentication module with login, user management handlers - Update all import paths to use new model locations - Add frontend auth pages (Login, UserManagement) and authStore - Remove deprecated internal/model/model.go
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package k8s
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
k8s "gitea.loveuer.com/loveuer/cluster/pkg/model/k8s"
|
|
"gitea.loveuer.com/loveuer/cluster/pkg/resp"
|
|
"gitea.loveuer.com/loveuer/cluster/pkg/store"
|
|
"github.com/gofiber/fiber/v3"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func ClusterConfigGet(ctx context.Context, db *gorm.DB, store store.Store) fiber.Handler {
|
|
return func(c fiber.Ctx) error {
|
|
var config k8s.ClusterConfig
|
|
|
|
if err := db.Where("key = ?", "kubeconfig").First(&config).Error; err != nil {
|
|
if err == gorm.ErrRecordNotFound {
|
|
return resp.R200(c, map[string]any{
|
|
"kubeconfig": "",
|
|
})
|
|
}
|
|
return resp.R500(c, "", nil, err)
|
|
}
|
|
|
|
return resp.R200(c, map[string]any{
|
|
"kubeconfig": config.Value,
|
|
})
|
|
}
|
|
}
|
|
|
|
func ClusterConfigSet(ctx context.Context, db *gorm.DB, store store.Store) fiber.Handler {
|
|
return func(c fiber.Ctx) error {
|
|
var req struct {
|
|
Kubeconfig string `json:"kubeconfig"`
|
|
}
|
|
|
|
if err := json.Unmarshal(c.Body(), &req); err != nil {
|
|
return resp.R400(c, "", nil, err)
|
|
}
|
|
|
|
config := k8s.ClusterConfig{
|
|
Key: "kubeconfig",
|
|
Value: req.Kubeconfig,
|
|
}
|
|
|
|
if err := db.Where("key = ?", "kubeconfig").Assign(config).FirstOrCreate(&config).Error; err != nil {
|
|
return resp.R500(c, "", nil, err)
|
|
}
|
|
|
|
return resp.R200(c, nil)
|
|
}
|
|
}
|