-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
71 lines (64 loc) · 1.72 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"errors"
"github.com/BurntSushi/toml"
)
type hcloudConfig struct {
Token string
SSHKey string `toml:"ssh_key"`
SSHKeyPrivatePath string `toml:"ssh_key_private_path"`
PrivateNetwork string `toml:"private_network"`
ServerType string `toml:"server_type"`
Location string
Image string
}
type flatcarConfig struct {
InstallScript string `toml:"install_script"`
InstallArgs string `toml:"install_args"`
InstallDevice string `toml:"install_device"`
Version string
ConfigTemplate string `toml:"config_template"`
TemplateStatic map[string]string `toml:"template_static"`
TemplateCommand string `toml:"template_command"`
}
type config struct {
HCloud hcloudConfig
Flatcar flatcarConfig
}
func verifyConfig(conf *config) error {
if conf.HCloud.Token == "" {
return errors.New("hcloud token missing")
}
if conf.HCloud.SSHKey == "" {
return errors.New("ssh key missing")
}
if conf.HCloud.PrivateNetwork == "" {
return errors.New("private network missing")
}
if conf.HCloud.ServerType == "" {
return errors.New("server type missing")
}
if conf.HCloud.Location == "" {
return errors.New("location missing")
}
if conf.HCloud.Image == "" {
conf.HCloud.Image = "debian-11"
}
if conf.Flatcar.Version == "" {
// TODO: set to latest version if not given
return errors.New("flatcar version missing")
}
if conf.Flatcar.ConfigTemplate == "" {
conf.Flatcar.ConfigTemplate = "ignition.yml.gtpl"
}
return nil
}
func ParseConfig(filename string) (config, error) {
var conf config
_, err := toml.DecodeFile(filename, &conf)
if err != nil {
return conf, err
}
err = verifyConfig(&conf)
return conf, err
}