功能:完善通用云管工作台、审计与诊断能力

This commit is contained in:
songyiming committed 2026-11-11 18:46:16 +08:00
1 parent 5ac692724d
commit 9f05aa20ea
225 files changed
+14266 -141

No files matched your search

+25
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"os"
"strconv"
"strings"
)
@@ -11,10 +12,34 @@ type Config struct {
TrustedProxies []string
Mode, Address, DatabaseURL, JWTSecret, AdminUsername, AdminPassword string
PVEURL, PVETokenID, PVETokenSecret, PVECAFile string
ExclusiveGPUNode string
ExclusiveGPUVMIDs []int
}
func Load() (Config, error) {
c := Config{Mode: env("VDI_MODE", "production"), Address: env("VDI_LISTEN", "127.0.0.1:8080"), DatabaseURL: os.Getenv("DATABASE_URL"), JWTSecret: os.Getenv("VDI_JWT_SECRET"), AdminUsername: os.Getenv("VDI_ADMIN_USERNAME"), AdminPassword: os.Getenv("VDI_ADMIN_PASSWORD"), PVEURL: os.Getenv("PVE_URL"), PVETokenID: os.Getenv("PVE_TOKEN_ID"), PVETokenSecret: os.Getenv("PVE_TOKEN_SECRET"), PVECAFile: os.Getenv("PVE_CA_FILE")}
c.ExclusiveGPUNode = strings.TrimSpace(os.Getenv("VDI_EXCLUSIVE_GPU_NODE"))
ids := strings.TrimSpace(os.Getenv("VDI_EXCLUSIVE_GPU_VMIDS"))
if (c.ExclusiveGPUNode == "") != (ids == "") {
return c, fmt.Errorf("exclusive GPU requires both node and VMIDs")
}
seen := map[int]bool{}
if ids != "" {
if strings.ContainsAny(c.ExclusiveGPUNode, "/\\?# ") {
return c, fmt.Errorf("invalid exclusive GPU node")
}
for _, value := range strings.Split(ids, ",") {
id, err := strconv.Atoi(strings.TrimSpace(value))
if err != nil || id < 100 || seen[id] {
return c, fmt.Errorf("invalid exclusive GPU VMIDs")
}
seen[id] = true
c.ExclusiveGPUVMIDs = append(c.ExclusiveGPUVMIDs, id)
}
if len(seen) < 2 || len(seen) > 16 {
return c, fmt.Errorf("exclusive GPU requires 2 to 16 VMs")
}
}
if value := os.Getenv("VDI_TRUSTED_PROXIES"); value != "" {
for _, proxy := range strings.Split(value, ",") {
proxy = strings.TrimSpace(proxy)