forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
267 lines (213 loc) · 6.42 KB
/
interfaces.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package interfaces
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
type Policy interface {
Name() string
Namespace() string
Roles() map[string]Role
}
type PolicyBinding interface {
Name() string
Namespace() string
PolicyRef() kapi.ObjectReference
RoleBindings() map[string]RoleBinding
}
type Role interface {
Name() string
Namespace() string
Rules() []authorizationapi.PolicyRule
}
type RoleBinding interface {
Name() string
Namespace() string
RoleRef() kapi.ObjectReference
Users() util.StringSet
Groups() util.StringSet
}
func NewClusterPolicyAdapter(policy *authorizationapi.ClusterPolicy) Policy {
return ClusterPolicyAdapter{policy: policy}
}
func NewLocalPolicyAdapter(policy *authorizationapi.Policy) Policy {
return PolicyAdapter{policy: policy}
}
func NewClusterPolicyBindingAdapter(policyBinding *authorizationapi.ClusterPolicyBinding) PolicyBinding {
return ClusterPolicyBindingAdapter{policyBinding: policyBinding}
}
func NewLocalPolicyBindingAdapter(policyBinding *authorizationapi.PolicyBinding) PolicyBinding {
return PolicyBindingAdapter{policyBinding: policyBinding}
}
func NewClusterPolicyBindingAdapters(list *authorizationapi.ClusterPolicyBindingList) []PolicyBinding {
ret := make([]PolicyBinding, 0, len(list.Items))
for i := range list.Items {
ret = append(ret, NewClusterPolicyBindingAdapter(&list.Items[i]))
}
return ret
}
func NewLocalPolicyBindingAdapters(list *authorizationapi.PolicyBindingList) []PolicyBinding {
ret := make([]PolicyBinding, 0, len(list.Items))
for i := range list.Items {
ret = append(ret, NewLocalPolicyBindingAdapter(&list.Items[i]))
}
return ret
}
func NewClusterRoleBindingAdapter(roleBinding *authorizationapi.ClusterRoleBinding) RoleBinding {
return ClusterRoleBindingAdapter{roleBinding: roleBinding}
}
func NewLocalRoleBindingAdapter(roleBinding *authorizationapi.RoleBinding) RoleBinding {
return RoleBindingAdapter{roleBinding: roleBinding}
}
func NewClusterRoleAdapter(role *authorizationapi.ClusterRole) Role {
return ClusterRoleAdapter{role: role}
}
func NewLocalRoleAdapter(role *authorizationapi.Role) Role {
return RoleAdapter{role: role}
}
type PolicyAdapter struct {
policy *authorizationapi.Policy
adaptedRoles map[string]Role
}
func (a PolicyAdapter) Name() string {
return a.policy.Name
}
func (a PolicyAdapter) Namespace() string {
return a.policy.Namespace
}
func (a PolicyAdapter) Roles() map[string]Role {
if a.adaptedRoles == nil {
adaptedRoles := map[string]Role{}
for key := range a.policy.Roles {
adaptedRoles[key] = RoleAdapter{a.policy.Roles[key]}
}
a.adaptedRoles = adaptedRoles
}
return a.adaptedRoles
}
type RoleAdapter struct {
role *authorizationapi.Role
}
func (a RoleAdapter) Name() string {
return a.role.Name
}
func (a RoleAdapter) Namespace() string {
return a.role.Namespace
}
func (a RoleAdapter) Rules() []authorizationapi.PolicyRule {
return a.role.Rules
}
type ClusterPolicyAdapter struct {
policy *authorizationapi.ClusterPolicy
adaptedRoles map[string]Role
}
func (a ClusterPolicyAdapter) Name() string {
return a.policy.Name
}
func (a ClusterPolicyAdapter) Namespace() string {
return a.policy.Namespace
}
func (a ClusterPolicyAdapter) Roles() map[string]Role {
if a.adaptedRoles == nil {
adaptedRoles := map[string]Role{}
for key := range a.policy.Roles {
adaptedRoles[key] = ClusterRoleAdapter{a.policy.Roles[key]}
}
a.adaptedRoles = adaptedRoles
}
return a.adaptedRoles
}
type ClusterRoleAdapter struct {
role *authorizationapi.ClusterRole
}
func (a ClusterRoleAdapter) Name() string {
return a.role.Name
}
func (a ClusterRoleAdapter) Namespace() string {
return a.role.Namespace
}
func (a ClusterRoleAdapter) Rules() []authorizationapi.PolicyRule {
return a.role.Rules
}
type PolicyBindingAdapter struct {
policyBinding *authorizationapi.PolicyBinding
adaptedRoleBindings map[string]RoleBinding
}
func (a PolicyBindingAdapter) Name() string {
return a.policyBinding.Name
}
func (a PolicyBindingAdapter) Namespace() string {
return a.policyBinding.Namespace
}
func (a PolicyBindingAdapter) PolicyRef() kapi.ObjectReference {
return a.policyBinding.PolicyRef
}
func (a PolicyBindingAdapter) RoleBindings() map[string]RoleBinding {
if a.adaptedRoleBindings == nil {
adaptedRoleBindings := map[string]RoleBinding{}
for key := range a.policyBinding.RoleBindings {
adaptedRoleBindings[key] = RoleBindingAdapter{a.policyBinding.RoleBindings[key]}
}
a.adaptedRoleBindings = adaptedRoleBindings
}
return a.adaptedRoleBindings
}
type RoleBindingAdapter struct {
roleBinding *authorizationapi.RoleBinding
}
func (a RoleBindingAdapter) Name() string {
return a.roleBinding.Name
}
func (a RoleBindingAdapter) Namespace() string {
return a.roleBinding.Namespace
}
func (a RoleBindingAdapter) RoleRef() kapi.ObjectReference {
return a.roleBinding.RoleRef
}
func (a RoleBindingAdapter) Users() util.StringSet {
return a.roleBinding.Users
}
func (a RoleBindingAdapter) Groups() util.StringSet {
return a.roleBinding.Groups
}
type ClusterPolicyBindingAdapter struct {
policyBinding *authorizationapi.ClusterPolicyBinding
adaptedRoleBindings map[string]RoleBinding
}
func (a ClusterPolicyBindingAdapter) Name() string {
return a.policyBinding.Name
}
func (a ClusterPolicyBindingAdapter) Namespace() string {
return a.policyBinding.Namespace
}
func (a ClusterPolicyBindingAdapter) PolicyRef() kapi.ObjectReference {
return a.policyBinding.PolicyRef
}
func (a ClusterPolicyBindingAdapter) RoleBindings() map[string]RoleBinding {
if a.adaptedRoleBindings == nil {
adaptedRoleBindings := map[string]RoleBinding{}
for key := range a.policyBinding.RoleBindings {
adaptedRoleBindings[key] = ClusterRoleBindingAdapter{a.policyBinding.RoleBindings[key]}
}
a.adaptedRoleBindings = adaptedRoleBindings
}
return a.adaptedRoleBindings
}
type ClusterRoleBindingAdapter struct {
roleBinding *authorizationapi.ClusterRoleBinding
}
func (a ClusterRoleBindingAdapter) Name() string {
return a.roleBinding.Name
}
func (a ClusterRoleBindingAdapter) Namespace() string {
return a.roleBinding.Namespace
}
func (a ClusterRoleBindingAdapter) RoleRef() kapi.ObjectReference {
return a.roleBinding.RoleRef
}
func (a ClusterRoleBindingAdapter) Users() util.StringSet {
return a.roleBinding.Users
}
func (a ClusterRoleBindingAdapter) Groups() util.StringSet {
return a.roleBinding.Groups
}