-
Notifications
You must be signed in to change notification settings - Fork 12
/
clientconfig_helper.go
58 lines (52 loc) · 1.97 KB
/
clientconfig_helper.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
// Copyright 2022 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package types
import "strings"
// StringToTarget converts string to Target type
func StringToTarget(target string) Target {
if target == string(targetK8s) || target == string(TargetK8s) {
return TargetK8s
} else if target == string(targetTMC) || target == string(TargetTMC) {
return TargetTMC
} else if target == string(targetOperations) || target == string(TargetOperations) {
return TargetOperations
} else if target == string(TargetGlobal) {
return TargetGlobal
} else if target == string(TargetUnknown) {
return TargetUnknown
}
return TargetUnknown
}
// IsValidTarget validates the target string specified is valid or not
// TargetGlobal and TargetUnknown are special targets and hence this function
// provide flexibility additional arguments to allow them based on the requirement
func IsValidTarget(target string, allowGlobal, allowUnknown bool) bool {
return target == string(targetK8s) ||
target == string(TargetK8s) ||
target == string(targetTMC) ||
target == string(TargetTMC) ||
target == string(targetOperations) ||
target == string(TargetOperations) ||
(allowGlobal && target == string(TargetGlobal)) ||
(allowUnknown && target == string(TargetUnknown))
}
// StringToContextType converts string to ContextType
func StringToContextType(contextType string) ContextType {
contextType = strings.ToLower(contextType)
if contextType == string(contextTypeK8s) || contextType == string(ContextTypeK8s) {
return ContextTypeK8s
} else if contextType == string(contextTypeTMC) || contextType == string(ContextTypeTMC) {
return ContextTypeTMC
} else if contextType == string(ContextTypeTanzu) {
return ContextTypeTanzu
}
return ""
}
// IsValidContextType validates the contextType string specified is valid or not
func IsValidContextType(contextType string) bool {
ct := StringToContextType(contextType)
if ct == "" && contextType != "" {
return false
}
return true
}