NewConfig creates a new Config instance populated with values from environment variables. This function reads all supported environment variables and creates a Config with those values. Environment variables that are not set will result in zero values for the corresponding fields. Environment vari
()
| 358 | // log.Fatal("Invalid config:", err) |
| 359 | // } |
| 360 | func NewConfig() *Config { |
| 361 | config := &Config{ |
| 362 | Profiles: make(map[string]ProfileConfig), |
| 363 | // Read environment variables for legacy fields |
| 364 | Addr: os.Getenv("PVETUI_ADDR"), |
| 365 | User: os.Getenv("PVETUI_USER"), |
| 366 | Password: os.Getenv("PVETUI_PASSWORD"), |
| 367 | TokenID: os.Getenv("PVETUI_TOKEN_ID"), |
| 368 | TokenSecret: os.Getenv("PVETUI_TOKEN_SECRET"), |
| 369 | Realm: os.Getenv("PVETUI_REALM"), |
| 370 | ApiPath: os.Getenv("PVETUI_API_PATH"), |
| 371 | Insecure: strings.ToLower(os.Getenv("PVETUI_INSECURE")) == trueString, |
| 372 | SSHUser: os.Getenv("PVETUI_SSH_USER"), |
| 373 | SSHKeyfile: ExpandHomePath(os.Getenv("PVETUI_SSH_KEYFILE")), |
| 374 | VMSSHKeyfile: ExpandHomePath(os.Getenv("PVETUI_VM_SSH_KEYFILE")), |
| 375 | AgeDir: ExpandHomePath(os.Getenv("PVETUI_AGE_DIR")), |
| 376 | SSHJumpHost: SSHJumpHost{ |
| 377 | Addr: os.Getenv("PVETUI_SSH_JUMPHOST_ADDR"), |
| 378 | User: os.Getenv("PVETUI_SSH_JUMPHOST_USER"), |
| 379 | Keyfile: os.Getenv("PVETUI_SSH_JUMPHOST_KEYFILE"), |
| 380 | Port: parseEnvPort("PVETUI_SSH_JUMPHOST_PORT"), |
| 381 | }, |
| 382 | Debug: strings.ToLower(os.Getenv("PVETUI_DEBUG")) == trueString, |
| 383 | CacheDir: ExpandHomePath(os.Getenv("PVETUI_CACHE_DIR")), |
| 384 | KeyBindings: DefaultKeyBindings(), |
| 385 | Plugins: PluginConfig{ |
| 386 | Ansible: AnsiblePluginConfig{ |
| 387 | Bootstrap: AnsibleBootstrapConfig{ |
| 388 | CreateHome: true, |
| 389 | ExcludeWindowsGuests: true, |
| 390 | InstallAuthorizedKey: true, |
| 391 | DryRunDefault: true, |
| 392 | }, |
| 393 | }, |
| 394 | }, |
| 395 | ShowIcons: strings.ToLower(os.Getenv("PVETUI_SHOW_ICONS")) != "false", |
| 396 | } |
| 397 | // Set default values for Realm and ApiPath only |
| 398 | if config.Realm == "" { |
| 399 | config.Realm = defaultRealm |
| 400 | } |
| 401 | if config.ApiPath == "" { |
| 402 | config.ApiPath = defaultApiPath |
| 403 | } |
| 404 | if config.AgeDir != "" { |
| 405 | SetAgeDirOverride(config.AgeDir) |
| 406 | } |
| 407 | |
| 408 | return config |
| 409 | } |
| 410 | |
| 411 | var ( |
| 412 | configPath string |