-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
69 lines (53 loc) · 1.48 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
package hetzner
import (
"errors"
"fmt"
"os"
"gitlab.com/gitlab-org/fleeting/fleeting/provider"
)
func (g *InstanceGroup) validate() error {
errs := []error{}
// Defaults
if g.settings.Protocol == "" {
g.settings.Protocol = provider.ProtocolSSH
}
if g.settings.Username == "" {
g.settings.Username = "root"
}
// Checks
if g.Name == "" {
errs = append(errs, fmt.Errorf("missing required plugin config: name"))
}
if g.Token == "" {
errs = append(errs, fmt.Errorf("missing required plugin config: token"))
}
if g.Location == "" {
errs = append(errs, fmt.Errorf("missing required plugin config: location"))
}
if g.ServerType == "" {
errs = append(errs, fmt.Errorf("missing required plugin config: server_type"))
}
if g.Image == "" {
errs = append(errs, fmt.Errorf("missing required plugin config: image"))
}
if g.UserData != "" && g.UserDataFile != "" {
errs = append(errs, fmt.Errorf("mutually exclusive plugin config provided: user_data, user_data_file"))
}
if g.settings.Protocol == provider.ProtocolWinRM {
errs = append(errs, fmt.Errorf("unsupported connector config protocol: %s", g.settings.Protocol))
}
return errors.Join(errs...)
}
func (g *InstanceGroup) populate() error {
if g.UserDataFile != "" {
userData, err := os.ReadFile(g.UserDataFile)
if err != nil {
return fmt.Errorf("failed to read user data file: %w", err)
}
g.UserData = string(userData)
}
g.labels = map[string]string{
"managed-by": Version.Name,
}
return nil
}