refactor: reorganize models to pkg/model and add authentication module
- 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
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"gitea.loveuer.com/loveuer/cluster/internal/model"
|
||||
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"
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
func ClusterConfigGet(ctx context.Context, db *gorm.DB, store store.Store) fiber.Handler {
|
||||
return func(c fiber.Ctx) error {
|
||||
var config model.ClusterConfig
|
||||
var config k8s.ClusterConfig
|
||||
|
||||
if err := db.Where("key = ?", "kubeconfig").First(&config).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
@@ -40,7 +40,7 @@ func ClusterConfigSet(ctx context.Context, db *gorm.DB, store store.Store) fiber
|
||||
return resp.R400(c, "", nil, err)
|
||||
}
|
||||
|
||||
config := model.ClusterConfig{
|
||||
config := k8s.ClusterConfig{
|
||||
Key: "kubeconfig",
|
||||
Value: req.Kubeconfig,
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"gitea.loveuer.com/loveuer/cluster/internal/model"
|
||||
k8sModel "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"
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func getK8sClient(db *gorm.DB) (*kubernetes.Clientset, error) {
|
||||
var config model.ClusterConfig
|
||||
var config k8sModel.ClusterConfig
|
||||
|
||||
if err := db.Where("key = ?", "kubeconfig").First(&config).Error; err != nil {
|
||||
return nil, fmt.Errorf("kubeconfig not found: %w", err)
|
||||
@@ -52,7 +52,7 @@ func getK8sClient(db *gorm.DB) (*kubernetes.Clientset, error) {
|
||||
}
|
||||
|
||||
func getK8sConfig(db *gorm.DB) (*rest.Config, error) {
|
||||
var config model.ClusterConfig
|
||||
var config k8sModel.ClusterConfig
|
||||
|
||||
if err := db.Where("key = ?", "kubeconfig").First(&config).Error; err != nil {
|
||||
return nil, fmt.Errorf("kubeconfig not found: %w", err)
|
||||
@@ -428,7 +428,7 @@ func K8sResourceApply(ctx context.Context, db *gorm.DB, store store.Store) fiber
|
||||
return resp.R400(c, "", nil, fmt.Errorf("yaml content is empty"))
|
||||
}
|
||||
|
||||
var config model.ClusterConfig
|
||||
var config k8sModel.ClusterConfig
|
||||
if err := db.Where("key = ?", "kubeconfig").First(&config).Error; err != nil {
|
||||
return resp.R500(c, "", nil, fmt.Errorf("kubeconfig not found: %w", err))
|
||||
}
|
||||
@@ -636,7 +636,7 @@ func K8sResourceUpdate(ctx context.Context, db *gorm.DB, store store.Store) fibe
|
||||
return resp.R400(c, "", nil, fmt.Errorf("yaml content is empty"))
|
||||
}
|
||||
|
||||
var config model.ClusterConfig
|
||||
var config k8sModel.ClusterConfig
|
||||
if err := db.Where("key = ?", "kubeconfig").First(&config).Error; err != nil {
|
||||
return resp.R500(c, "", nil, fmt.Errorf("kubeconfig not found: %w", err))
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"gitea.loveuer.com/loveuer/cluster/internal/model"
|
||||
k8s "gitea.loveuer.com/loveuer/cluster/pkg/model/k8s"
|
||||
"gitea.loveuer.com/loveuer/cluster/pkg/store"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func Init(ctx context.Context, db *gorm.DB, store store.Store) error {
|
||||
if err := db.AutoMigrate(
|
||||
&model.ClusterConfig{},
|
||||
&k8s.ClusterConfig{},
|
||||
); err != nil {
|
||||
log.Fatalf("failed to migrate k8s database: %v", err)
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user