- 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
82 lines
2.1 KiB
Go
82 lines
2.1 KiB
Go
package registry
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"gitea.loveuer.com/loveuer/cluster/pkg/model/registry"
|
|
"gitea.loveuer.com/loveuer/cluster/pkg/resp"
|
|
"gitea.loveuer.com/loveuer/cluster/pkg/store"
|
|
"github.com/gofiber/fiber/v3"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// RegistryConfigGet returns the registry configuration
|
|
func RegistryConfigGet(ctx context.Context, db *gorm.DB, store store.Store) fiber.Handler {
|
|
return func(c fiber.Ctx) error {
|
|
var configs []registry.RegistryConfig
|
|
if err := db.Find(&configs).Error; err != nil {
|
|
return resp.R500(c, "", nil, err)
|
|
}
|
|
|
|
// Convert to map for easier frontend access
|
|
configMap := make(map[string]string)
|
|
for _, config := range configs {
|
|
configMap[config.Key] = config.Value
|
|
}
|
|
|
|
return resp.R200(c, map[string]interface{}{
|
|
"configs": configMap,
|
|
})
|
|
}
|
|
}
|
|
|
|
// RegistryConfigSet sets a registry configuration value
|
|
func RegistryConfigSet(ctx context.Context, db *gorm.DB, store store.Store) fiber.Handler {
|
|
return func(c fiber.Ctx) error {
|
|
var req struct {
|
|
Key string `json:"key"`
|
|
Value string `json:"value"`
|
|
}
|
|
|
|
// Parse JSON body
|
|
body := c.Body()
|
|
if len(body) == 0 {
|
|
return resp.R400(c, "EMPTY_BODY", nil, "request body is empty")
|
|
}
|
|
if err := json.Unmarshal(body, &req); err != nil {
|
|
return resp.R400(c, "INVALID_REQUEST", nil, "invalid request body")
|
|
}
|
|
|
|
if req.Key == "" {
|
|
return resp.R400(c, "MISSING_KEY", nil, "key is required")
|
|
}
|
|
|
|
// Find or create config
|
|
var config registry.RegistryConfig
|
|
err := db.Where("key = ?", req.Key).First(&config).Error
|
|
if err == gorm.ErrRecordNotFound {
|
|
// Create new config
|
|
config = registry.RegistryConfig{
|
|
Key: req.Key,
|
|
Value: req.Value,
|
|
}
|
|
if err := db.Create(&config).Error; err != nil {
|
|
return resp.R500(c, "", nil, err)
|
|
}
|
|
} else if err != nil {
|
|
return resp.R500(c, "", nil, err)
|
|
} else {
|
|
// Update existing config
|
|
config.Value = req.Value
|
|
if err := db.Save(&config).Error; err != nil {
|
|
return resp.R500(c, "", nil, err)
|
|
}
|
|
}
|
|
|
|
return resp.R200(c, map[string]interface{}{
|
|
"config": config,
|
|
})
|
|
}
|
|
}
|