-
Notifications
You must be signed in to change notification settings - Fork 473
/
service_binding_checker.go
41 lines (35 loc) · 1.08 KB
/
service_binding_checker.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
package authorization
import (
"github.com/kiali/kiali/kubernetes"
"github.com/kiali/kiali/models"
)
type BindingChecker struct {
ServiceRoles []kubernetes.IstioObject
ServiceRoleBinding kubernetes.IstioObject
}
func (sc BindingChecker) Check() ([]*models.IstioCheck, bool) {
validations := make([]*models.IstioCheck, 0)
if roleRefSpec, found := sc.ServiceRoleBinding.GetSpec()["roleRef"]; found {
if roleRef, ok := roleRefSpec.(map[string]interface{}); ok {
if roleKind, found := roleRef["kind"]; found && roleKind == "ServiceRole" {
if roleName, found := roleRef["name"]; found {
if roleRefName, ok := roleName.(string); ok {
if !sc.checkMatch(roleRefName) {
validation := models.Build("servicerolebinding.invalid.role", "spec/roleRef/name")
validations = append(validations, &validation)
}
}
}
}
}
}
return validations, len(validations) == 0
}
func (sc BindingChecker) checkMatch(roleRefName string) bool {
for _, sr := range sc.ServiceRoles {
if roleRefName == sr.GetObjectMeta().Name {
return true
}
}
return false
}