-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
identitymapping.go
56 lines (46 loc) · 1.56 KB
/
identitymapping.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
package v1alpha5
import (
"github.com/pkg/errors"
)
// IAMIdentityMapping contains IAM accounts, users, roles and services that will be added to the
// aws-auth configmap to enable access to the cluster
type IAMIdentityMapping struct {
// +optional
ARN string `json:"arn,omitempty"`
Username string `json:"username,omitempty"`
Groups []string `json:"groups,omitempty"`
Account string `json:"account,omitempty"`
ServiceName string `json:"serviceName,omitempty"`
Namespace string `json:"namespace,omitempty"`
NoDuplicateARNs bool `json:"noDuplicateARNs,omitempty"`
}
func (im *IAMIdentityMapping) hasARNOptions() bool {
return im.hasARN() && im.hasUsername() && im.hasGroups()
}
func (im *IAMIdentityMapping) hasARN() bool {
return im.ARN != ""
}
func (im *IAMIdentityMapping) hasUsername() bool {
return im.Username != ""
}
func (im *IAMIdentityMapping) hasGroups() bool {
return len(im.Groups) > 0
}
func (im *IAMIdentityMapping) Validate() error {
if im.ServiceName != "" {
if im.hasARNOptions() {
return errors.New("cannot use arn, username, and groups with serviceName")
}
if im.Namespace == "" {
return errors.New("namespace is required when using serviceName")
}
} else {
if im.Namespace != "" {
return errors.New("serviceName is required when using namespace")
}
}
if im.Account != "" && (im.hasARN() || im.hasUsername() || im.hasGroups() || im.ServiceName != "" || im.Namespace != "") {
return errors.New("account cannot be configured with any other options")
}
return nil
}