-
Notifications
You must be signed in to change notification settings - Fork 0
/
rbac.go
84 lines (72 loc) · 2.55 KB
/
rbac.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
79
80
81
82
83
84
package clustermanager
import (
"github.com/rancher/norman/types"
"github.com/sirupsen/logrus"
)
func (m *Manager) CanCreate(apiContext *types.APIContext, schema *types.Schema) error {
ac, err := m.getAccessControl(apiContext, schema)
if err != nil {
return err
}
return ac.CanCreate(apiContext, schema)
}
func (m *Manager) CanList(apiContext *types.APIContext, schema *types.Schema) error {
ac, err := m.getAccessControl(apiContext, schema)
if err != nil {
return err
}
return ac.CanList(apiContext, schema)
}
func (m *Manager) CanGet(apiContext *types.APIContext, schema *types.Schema) error {
ac, err := m.getAccessControl(apiContext, schema)
if err != nil {
return err
}
return ac.CanGet(apiContext, schema)
}
func (m *Manager) CanUpdate(apiContext *types.APIContext, obj map[string]interface{}, schema *types.Schema) error {
ac, err := m.getAccessControl(apiContext, schema)
if err != nil {
return err
}
return ac.CanUpdate(apiContext, obj, schema)
}
func (m *Manager) CanDelete(apiContext *types.APIContext, obj map[string]interface{}, schema *types.Schema) error {
ac, err := m.getAccessControl(apiContext, schema)
if err != nil {
return err
}
return ac.CanDelete(apiContext, obj, schema)
}
func (m *Manager) CanDo(apiGroup, resource, verb string, apiContext *types.APIContext, obj map[string]interface{}, schema *types.Schema) error {
ac, err := m.getAccessControl(apiContext, schema)
if err != nil {
return err
}
return ac.CanDo(apiGroup, resource, verb, apiContext, obj, schema)
}
func (m *Manager) Filter(apiContext *types.APIContext, schema *types.Schema, obj map[string]interface{}, context map[string]string) map[string]interface{} {
ac, err := m.getAccessControl(apiContext, schema)
if err != nil {
logrus.Warnf("failed to find access control: %v", err)
return nil
}
return ac.Filter(apiContext, schema, obj, context)
}
func (m *Manager) FilterList(apiContext *types.APIContext, schema *types.Schema, obj []map[string]interface{}, context map[string]string) []map[string]interface{} {
ac, err := m.getAccessControl(apiContext, schema)
if err != nil {
logrus.Warnf("failed to find access control: %v", err)
return nil
}
return ac.FilterList(apiContext, schema, obj, context)
}
func (m *Manager) getAccessControl(apiContext *types.APIContext, schema *types.Schema) (types.AccessControl, error) {
return m.AccessControl(apiContext, getContext(schema))
}
func getContext(schema *types.Schema) types.StorageContext {
if schema == nil || schema.Store == nil {
return types.DefaultStorageContext
}
return schema.Store.Context()
}