forked from kubernetes-sigs/aws-iam-authenticator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapper.go
69 lines (54 loc) · 1.7 KB
/
mapper.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 mapper
import (
"errors"
"fmt"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/aws-iam-authenticator/pkg/config"
)
const (
// Deprecated: use ModeMountedFile instead
ModeFile string = "File"
// Deprecated: use ModeEKSConfigMap instead
ModeConfigMap string = "ConfigMap"
ModeMountedFile string = "MountedFile"
ModeEKSConfigMap string = "EKSConfigMap"
ModeCRD string = "CRD"
)
var (
ValidBackendModeChoices = []string{ModeFile, ModeConfigMap, ModeMountedFile, ModeEKSConfigMap, ModeCRD}
DeprecatedBackendModeChoices = map[string]string{
ModeFile: ModeMountedFile,
ModeConfigMap: ModeEKSConfigMap,
}
BackendModeChoices = []string{ModeMountedFile, ModeEKSConfigMap, ModeCRD}
)
var ErrNotMapped = errors.New("ARN is not mapped")
type Mapper interface {
Name() string
// Start must be non-blocking
Start(stopCh <-chan struct{}) error
Map(canonicalARN string) (*config.IdentityMapping, error)
IsAccountAllowed(accountID string) bool
}
func ValidateBackendMode(modes []string) []error {
var errs []error
validModes := sets.NewString(ValidBackendModeChoices...)
for _, mode := range modes {
if !validModes.Has(mode) {
errs = append(errs, fmt.Errorf("backend-mode %q is not a valid mode", mode))
}
}
for _, mode := range modes {
if replacementMode, ok := DeprecatedBackendModeChoices[mode]; ok {
logrus.Warningf("warning: backend-mode %q is deprecated, use %q instead", mode, replacementMode)
}
}
if len(modes) != sets.NewString(modes...).Len() {
errs = append(errs, fmt.Errorf("backend-mode %q has duplicates", modes))
}
if len(modes) == 0 {
errs = append(errs, fmt.Errorf("at least one backend-mode must be specified"))
}
return errs
}