@@ -11,18 +11,32 @@ import (
1111 "gopkg.in/yaml.v2"
1212)
1313
14+ type VmImage struct {
15+ Location string `yaml:"location"`
16+ Arch string `yaml:"arch"`
17+ }
18+
19+ type VmConfig struct {
20+ Manager string `yaml:"manager"`
21+ HostsResolver string `yaml:"hosts_resolver"`
22+ Images []VmImage `yaml:"images"`
23+ Ubuntu string `yaml:"ubuntu"`
24+ }
25+
1426type Config struct {
1527 AllowDevelopmentDeploys bool `yaml:"allow_development_deploys"`
1628 AskVaultPass bool `yaml:"ask_vault_pass"`
1729 CheckForUpdates bool `yaml:"check_for_updates"`
1830 LoadPlugins bool `yaml:"load_plugins"`
1931 Open map [string ]string `yaml:"open"`
2032 VirtualenvIntegration bool `yaml:"virtualenv_integration"`
33+ Vm VmConfig `yaml:"vm"`
2134}
2235
2336var (
24- ErrUnsupportedType = errors .New ("Invalid env var config setting: value is an unsupported type." )
25- ErrCouldNotParse = errors .New ("Invalid env var config setting: failed to parse value" )
37+ UnsupportedTypeErr = errors .New ("Invalid env var config setting: value is an unsupported type." )
38+ CouldNotParseErr = errors .New ("Invalid env var config setting: failed to parse value" )
39+ InvalidConfigErr = errors .New ("Invalid config file" )
2640)
2741
2842func NewConfig (defaultConfig Config ) Config {
@@ -37,7 +51,19 @@ func (c *Config) LoadFile(path string) error {
3751 }
3852
3953 if err := yaml .Unmarshal (configYaml , & c ); err != nil {
40- return err
54+ return fmt .Errorf ("%w: %s" , InvalidConfigErr , err )
55+ }
56+
57+ if c .Vm .Manager != "lima" && c .Vm .Manager != "auto" && c .Vm .Manager != "mock" {
58+ return fmt .Errorf ("%w: unsupported value for `vm.manager`. Must be one of: auto, lima" , InvalidConfigErr )
59+ }
60+
61+ if c .Vm .Ubuntu != "18.04" && c .Vm .Ubuntu != "20.04" && c .Vm .Ubuntu != "22.04" {
62+ return fmt .Errorf ("%w: unsupported value for `vm.ubuntu`. Must be one of: 18.04, 20.04, 22.04" , InvalidConfigErr )
63+ }
64+
65+ if c .Vm .HostsResolver != "hosts_file" {
66+ return fmt .Errorf ("%w: unsupported value for `vm.hosts_resolver`. Must be one of: hosts_file" , InvalidConfigErr )
4167 }
4268
4369 return nil
@@ -72,27 +98,27 @@ func (c *Config) LoadEnv(prefix string) error {
7298 val , err := strconv .ParseBool (value )
7399
74100 if err != nil {
75- return fmt .Errorf ("%w '%s'\n '%s' can't be parsed as a boolean" , ErrCouldNotParse , env , value )
101+ return fmt .Errorf ("%w '%s'\n '%s' can't be parsed as a boolean" , CouldNotParseErr , env , value )
76102 }
77103
78104 structValue .SetBool (val )
79105 case reflect .Int :
80106 val , err := strconv .ParseInt (value , 10 , 32 )
81107
82108 if err != nil {
83- return fmt .Errorf ("%w '%s'\n '%s' can't be parsed as an integer" , ErrCouldNotParse , env , value )
109+ return fmt .Errorf ("%w '%s'\n '%s' can't be parsed as an integer" , CouldNotParseErr , env , value )
84110 }
85111
86112 structValue .SetInt (val )
87113 case reflect .Float32 :
88114 val , err := strconv .ParseFloat (value , 32 )
89115 if err != nil {
90- return fmt .Errorf ("%w '%s'\n '%s' can't be parsed as a float" , ErrCouldNotParse , env , value )
116+ return fmt .Errorf ("%w '%s'\n '%s' can't be parsed as a float" , CouldNotParseErr , env , value )
91117 }
92118
93119 structValue .SetFloat (val )
94120 default :
95- return fmt .Errorf ("%w\n %s setting of type %s is unsupported." , ErrUnsupportedType , env , field .Type .String ())
121+ return fmt .Errorf ("%w\n %s setting of type %s is unsupported." , UnsupportedTypeErr , env , field .Type .String ())
96122 }
97123 }
98124 }
0 commit comments