功能:扩展云管资源运维、账号授权及监控管理
This commit is contained in:
1 parent
eef485306f
commit
6134d49c16
87 files changed
+29498
-126
No files matched your search
@@ -2,17 +2,28 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
TrustedProxies []string
|
||||
Mode, Address, DatabaseURL, JWTSecret, AdminUsername, AdminPassword string
|
||||
PVEURL, PVETokenID, PVETokenSecret, PVECAFile string
|
||||
}
|
||||
|
||||
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")}
|
||||
if value := os.Getenv("VDI_TRUSTED_PROXIES"); value != "" {
|
||||
for _, proxy := range strings.Split(value, ",") {
|
||||
proxy = strings.TrimSpace(proxy)
|
||||
if _, _, err := net.ParseCIDR(proxy); err != nil && net.ParseIP(proxy) == nil {
|
||||
return c, fmt.Errorf("invalid VDI_TRUSTED_PROXIES entry")
|
||||
}
|
||||
c.TrustedProxies = append(c.TrustedProxies, proxy)
|
||||
}
|
||||
}
|
||||
if c.Mode != "demo" && c.Mode != "production" {
|
||||
return c, fmt.Errorf("VDI_MODE must be demo or production")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user