-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
validate.go
51 lines (45 loc) · 1.24 KB
/
validate.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
package main
import (
"fmt"
"k8s.io/apimachinery/pkg/api/resource"
)
func validateFlags(c InfraConfig) error {
if len(c.Provider) == 0 {
return fmt.Errorf("provider flag is required")
}
if c.Provider == "equinix-metal" {
if len(c.ProjectID) == 0 {
return fmt.Errorf("project-id required for provider: %s", c.Provider)
}
}
if c.Provider == "gce" {
if len(c.ProjectID) == 0 {
return fmt.Errorf("project-id required for provider: %s", c.Provider)
}
if len(c.Zone) == 0 {
return fmt.Errorf("zone required for provider: %s", c.Provider)
}
if len(c.Region) == 0 {
return fmt.Errorf("region required for provider: %s", c.Provider)
}
}
if c.Provider == "azure" {
if len(c.SubscriptionID) == 0 {
return fmt.Errorf("subscription-id required for provider: %s", c.Provider)
}
}
if c.Provider == "hetzner" {
if len(c.Region) == 0 {
return fmt.Errorf("region required for provider: %s", c.Provider)
}
}
if len(c.MaxClientMemory) > 0 {
if _, err := resource.ParseQuantity(c.MaxClientMemory); err != nil {
return fmt.Errorf("invalid memory value: %s", err.Error())
}
}
if len(c.AccessKey) == 0 && len(c.AccessKeyFile) == 0 {
return fmt.Errorf("access-key or access-key-file must be given")
}
return nil
}