-
Notifications
You must be signed in to change notification settings - Fork 2
/
validation.go
78 lines (68 loc) · 1.97 KB
/
validation.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
72
73
74
75
76
77
78
package cmd
import (
"fmt"
"os"
"github.com/logicmonitor/k8s-release-manager/pkg/backend"
"github.com/spf13/cobra"
)
func failAuth(cmd *cobra.Command) {
err := cmd.Help()
if err != nil {
fmt.Println(err.Error())
}
os.Exit(0)
}
func validateCommonConfig() bool {
valid := true
if rlsmgrconfig.Backend.StoragePath == "" {
fmt.Println("You must specify --path")
valid = false
}
return valid
}
func validateImportConfig() bool {
valid := true
if rlsmgrconfig.Import.Target != "" && rlsmgrconfig.Import.Namespace == "" {
// if target namespace is specified, source namespace is also required
fmt.Println("You must specify --namespace if --target-namespace is specified")
valid = false
}
if rlsmgrconfig.Import.Namespace != "" && len(rlsmgrconfig.Import.ExcludeNamespaces) > 0 {
// if target namespace is specified, you can't also set exclude namespaces
fmt.Println("The flags --namespace and --exclude-namespaces are mutually exclusive")
valid = false
}
return valid
}
func validateS3Config(opts *backend.S3Opts) bool {
valid := true
if opts.Bucket == "" {
fmt.Println("You must specify --bucket")
valid = false
}
if opts.Region == "" {
fmt.Println("You must specify --region")
valid = false
}
return valid
}
func validateS3Auth(opts *backend.S3Opts) bool {
if !validateS3SessionToken(opts) || !validateS3Tokens(opts) {
return false
}
return true
}
func validateS3Tokens(opts *backend.S3Opts) bool {
if (opts.Auth.AccessKeyID != "" && opts.Auth.SecretAccessKey == "") || (opts.Auth.AccessKeyID == "" && opts.Auth.SecretAccessKey != "") {
fmt.Println("You must specify both --accessKeyID and --secretAccessKey or neither")
return false
}
return true
}
func validateS3SessionToken(opts *backend.S3Opts) bool {
if opts.Auth.SessionToken != "" && (opts.Auth.AccessKeyID == "" || opts.Auth.SecretAccessKey == "") {
fmt.Println("If --sessionToken is specified, you must specify --accessKeyID and --secretAccessKey")
return false
}
return true
}