-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
52 lines (44 loc) · 1.71 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package minivmm
import (
"path/filepath"
"github.com/caarlos0/env"
)
// Config is the minivmm configuration structure.
type Config struct {
Dir string `env:"VMM_DIR" envDefault:"/opt/minivmm"`
Port int `env:"VMM_LISTEN_PORT" envDefault:"14151"`
Origin string `env:"VMM_ORIGIN,required"`
OIDC string `env:"VMM_OIDC_URL"`
StaticAgents []string `env:"VMM_AGENTS" envSeparator:","`
NoAgentsDiscover bool `env:"VMM_NO_AGENTS_DISCOVER" envDefault:"false"`
CorsOrigins []string `env:"VMM_CORS_ALLOWED_ORIGINS" envSeparator:","`
SubnetCIDR string `env:"VMM_SUBNET_CIDR"`
NameServers []string `env:"VMM_NAME_SERVERS" envDefault:"1.1.1.1,1.0.0.1" envSeparator:","`
ServerCert string `env:"VMM_SERVER_CERT"`
ServerKey string `env:"VMM_SERVER_KEY"`
NoTLS bool `env:"VMM_NO_TLS" envDefault:"false"`
NoAuth bool `env:"VMM_NO_AUTH" envDefault:"false"`
NoKvm bool `env:"VMM_NO_KVM" envDefault:"false"`
VNCKeyboardLayout string `env:"VMM_VNC_KEYBOARD_LAYOUT" envDefault:"en-us"`
VMDir string
ImageDir string
ForwardDir string
}
// C is a global configuration object.
var C *Config = nil
// ParseConfig loads configurations from environment variables and sets to the global configuration
func ParseConfig() error {
c := Config{}
if err := env.Parse(&c); err != nil {
return err
}
c.VMDir = filepath.Join(c.Dir, "vms")
c.ImageDir = filepath.Join(c.Dir, "images")
c.ForwardDir = filepath.Join(c.Dir, "forwards")
C = &c
return nil
}
// SetConfig sets the global configuration with the given one. This function is for testing.
func SetConfig(c *Config) {
C = c
}