-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
conversion.go
433 lines (346 loc) · 14.6 KB
/
conversion.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
package v1beta3
import (
"sort"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/util"
newer "github.com/openshift/origin/pkg/authorization/api"
uservalidation "github.com/openshift/origin/pkg/user/api/validation"
)
func convert_v1beta3_ResourceAccessReview_To_api_ResourceAccessReview(in *ResourceAccessReview, out *newer.ResourceAccessReview, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if err := s.DefaultConvert(&in.AuthorizationAttributes, &out.Action, conversion.IgnoreMissingFields); err != nil {
return err
}
return nil
}
func convert_api_ResourceAccessReview_To_v1beta3_ResourceAccessReview(in *newer.ResourceAccessReview, out *ResourceAccessReview, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if err := s.DefaultConvert(&in.Action, &out.AuthorizationAttributes, conversion.IgnoreMissingFields); err != nil {
return err
}
return nil
}
func convert_v1beta3_LocalResourceAccessReview_To_api_LocalResourceAccessReview(in *LocalResourceAccessReview, out *newer.LocalResourceAccessReview, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if err := s.DefaultConvert(&in.AuthorizationAttributes, &out.Action, conversion.IgnoreMissingFields); err != nil {
return err
}
return nil
}
func convert_api_LocalResourceAccessReview_To_v1beta3_LocalResourceAccessReview(in *newer.LocalResourceAccessReview, out *LocalResourceAccessReview, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if err := s.DefaultConvert(&in.Action, &out.AuthorizationAttributes, conversion.IgnoreMissingFields); err != nil {
return err
}
return nil
}
func convert_v1beta3_SubjectAccessReview_To_api_SubjectAccessReview(in *SubjectAccessReview, out *newer.SubjectAccessReview, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if err := s.DefaultConvert(&in.AuthorizationAttributes, &out.Action, conversion.IgnoreMissingFields); err != nil {
return err
}
out.Groups = util.NewStringSet(in.GroupsSlice...)
return nil
}
func convert_api_SubjectAccessReview_To_v1beta3_SubjectAccessReview(in *newer.SubjectAccessReview, out *SubjectAccessReview, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if err := s.DefaultConvert(&in.Action, &out.AuthorizationAttributes, conversion.IgnoreMissingFields); err != nil {
return err
}
out.GroupsSlice = in.Groups.List()
return nil
}
func convert_v1beta3_LocalSubjectAccessReview_To_api_LocalSubjectAccessReview(in *LocalSubjectAccessReview, out *newer.LocalSubjectAccessReview, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if err := s.DefaultConvert(&in.AuthorizationAttributes, &out.Action, conversion.IgnoreMissingFields); err != nil {
return err
}
out.Groups = util.NewStringSet(in.GroupsSlice...)
return nil
}
func convert_api_LocalSubjectAccessReview_To_v1beta3_LocalSubjectAccessReview(in *newer.LocalSubjectAccessReview, out *LocalSubjectAccessReview, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
if err := s.DefaultConvert(&in.Action, &out.AuthorizationAttributes, conversion.IgnoreMissingFields); err != nil {
return err
}
out.GroupsSlice = in.Groups.List()
return nil
}
func convert_v1beta3_ResourceAccessReviewResponse_To_api_ResourceAccessReviewResponse(in *ResourceAccessReviewResponse, out *newer.ResourceAccessReviewResponse, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
out.Users = util.NewStringSet(in.UsersSlice...)
out.Groups = util.NewStringSet(in.GroupsSlice...)
return nil
}
func convert_api_ResourceAccessReviewResponse_To_v1beta3_ResourceAccessReviewResponse(in *newer.ResourceAccessReviewResponse, out *ResourceAccessReviewResponse, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields); err != nil {
return err
}
out.UsersSlice = in.Users.List()
out.GroupsSlice = in.Groups.List()
return nil
}
func convert_v1beta3_PolicyRule_To_api_PolicyRule(in *PolicyRule, out *newer.PolicyRule, s conversion.Scope) error {
if err := s.Convert(&in.AttributeRestrictions, &out.AttributeRestrictions, 0); err != nil {
return err
}
out.Resources = util.StringSet{}
out.Resources.Insert(in.Resources...)
out.Resources.Insert(in.ResourceKinds...)
out.Verbs = util.StringSet{}
out.Verbs.Insert(in.Verbs...)
out.ResourceNames = util.NewStringSet(in.ResourceNames...)
out.NonResourceURLs = util.NewStringSet(in.NonResourceURLsSlice...)
return nil
}
func convert_api_PolicyRule_To_v1beta3_PolicyRule(in *newer.PolicyRule, out *PolicyRule, s conversion.Scope) error {
if err := s.Convert(&in.AttributeRestrictions, &out.AttributeRestrictions, 0); err != nil {
return err
}
out.Resources = []string{}
out.Resources = append(out.Resources, in.Resources.List()...)
out.Verbs = []string{}
out.Verbs = append(out.Verbs, in.Verbs.List()...)
out.ResourceNames = in.ResourceNames.List()
out.NonResourceURLsSlice = in.NonResourceURLs.List()
return nil
}
func convert_v1beta3_Policy_To_api_Policy(in *Policy, out *newer.Policy, s conversion.Scope) error {
out.LastModified = in.LastModified
out.Roles = make(map[string]*newer.Role)
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}
func convert_api_Policy_To_v1beta3_Policy(in *newer.Policy, out *Policy, s conversion.Scope) error {
out.LastModified = in.LastModified
out.Roles = make([]NamedRole, 0, 0)
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}
func convert_v1beta3_RoleBinding_To_api_RoleBinding(in *RoleBinding, out *newer.RoleBinding, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
// if the users and groups fields are cleared, then respect only subjects. The field was set in the DefaultConvert above
if in.UserNames == nil && in.GroupNames == nil {
return nil
}
out.Subjects = newer.BuildSubjects(in.UserNames, in.GroupNames, uservalidation.ValidateUserName, uservalidation.ValidateGroupName)
return nil
}
func convert_api_RoleBinding_To_v1beta3_RoleBinding(in *newer.RoleBinding, out *RoleBinding, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
out.UserNames, out.GroupNames = newer.StringSubjectsFor(in.Namespace, in.Subjects)
return nil
}
func convert_v1beta3_PolicyBinding_To_api_PolicyBinding(in *PolicyBinding, out *newer.PolicyBinding, s conversion.Scope) error {
out.LastModified = in.LastModified
out.RoleBindings = make(map[string]*newer.RoleBinding)
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}
func convert_api_PolicyBinding_To_v1beta3_PolicyBinding(in *newer.PolicyBinding, out *PolicyBinding, s conversion.Scope) error {
out.LastModified = in.LastModified
out.RoleBindings = make([]NamedRoleBinding, 0, 0)
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}
// and now the globals
func convert_v1beta3_ClusterPolicy_To_api_ClusterPolicy(in *ClusterPolicy, out *newer.ClusterPolicy, s conversion.Scope) error {
out.LastModified = in.LastModified
out.Roles = make(map[string]*newer.ClusterRole)
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}
func convert_api_ClusterPolicy_To_v1beta3_ClusterPolicy(in *newer.ClusterPolicy, out *ClusterPolicy, s conversion.Scope) error {
out.LastModified = in.LastModified
out.Roles = make([]NamedClusterRole, 0, 0)
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}
func convert_v1beta3_ClusterRoleBinding_To_api_ClusterRoleBinding(in *ClusterRoleBinding, out *newer.ClusterRoleBinding, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
// if the users and groups fields are cleared, then respect only subjects. The field was set in the DefaultConvert above
if in.UserNames == nil && in.GroupNames == nil {
return nil
}
out.Subjects = newer.BuildSubjects(in.UserNames, in.GroupNames, uservalidation.ValidateUserName, uservalidation.ValidateGroupName)
return nil
}
func convert_api_ClusterRoleBinding_To_v1beta3_ClusterRoleBinding(in *newer.ClusterRoleBinding, out *ClusterRoleBinding, s conversion.Scope) error {
if err := s.DefaultConvert(in, out, conversion.IgnoreMissingFields|conversion.AllowDifferentFieldTypeNames); err != nil {
return err
}
out.UserNames, out.GroupNames = newer.StringSubjectsFor(in.Namespace, in.Subjects)
return nil
}
func convert_v1beta3_ClusterPolicyBinding_To_api_ClusterPolicyBinding(in *ClusterPolicyBinding, out *newer.ClusterPolicyBinding, s conversion.Scope) error {
out.LastModified = in.LastModified
out.RoleBindings = make(map[string]*newer.ClusterRoleBinding)
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}
func convert_api_ClusterPolicyBinding_To_v1beta3_ClusterPolicyBinding(in *newer.ClusterPolicyBinding, out *ClusterPolicyBinding, s conversion.Scope) error {
out.LastModified = in.LastModified
out.RoleBindings = make([]NamedClusterRoleBinding, 0, 0)
return s.DefaultConvert(in, out, conversion.IgnoreMissingFields)
}
func init() {
err := api.Scheme.AddConversionFuncs(
convert_v1beta3_SubjectAccessReview_To_api_SubjectAccessReview,
convert_api_SubjectAccessReview_To_v1beta3_SubjectAccessReview,
convert_v1beta3_LocalSubjectAccessReview_To_api_LocalSubjectAccessReview,
convert_api_LocalSubjectAccessReview_To_v1beta3_LocalSubjectAccessReview,
convert_v1beta3_ResourceAccessReview_To_api_ResourceAccessReview,
convert_api_ResourceAccessReview_To_v1beta3_ResourceAccessReview,
convert_v1beta3_LocalResourceAccessReview_To_api_LocalResourceAccessReview,
convert_api_LocalResourceAccessReview_To_v1beta3_LocalResourceAccessReview,
convert_v1beta3_ResourceAccessReviewResponse_To_api_ResourceAccessReviewResponse,
convert_api_ResourceAccessReviewResponse_To_v1beta3_ResourceAccessReviewResponse,
convert_v1beta3_PolicyRule_To_api_PolicyRule,
convert_api_PolicyRule_To_v1beta3_PolicyRule,
convert_v1beta3_Policy_To_api_Policy,
convert_api_Policy_To_v1beta3_Policy,
convert_v1beta3_RoleBinding_To_api_RoleBinding,
convert_api_RoleBinding_To_v1beta3_RoleBinding,
convert_v1beta3_PolicyBinding_To_api_PolicyBinding,
convert_api_PolicyBinding_To_v1beta3_PolicyBinding,
convert_api_ClusterPolicy_To_v1beta3_ClusterPolicy,
convert_v1beta3_ClusterRoleBinding_To_api_ClusterRoleBinding,
convert_api_ClusterRoleBinding_To_v1beta3_ClusterRoleBinding,
convert_v1beta3_ClusterPolicyBinding_To_api_ClusterPolicyBinding,
convert_api_ClusterPolicyBinding_To_v1beta3_ClusterPolicyBinding,
func(in *[]NamedRoleBinding, out *map[string]*newer.RoleBinding, s conversion.Scope) error {
for _, curr := range *in {
newRoleBinding := &newer.RoleBinding{}
if err := s.Convert(&curr.RoleBinding, newRoleBinding, 0); err != nil {
return err
}
(*out)[curr.Name] = newRoleBinding
}
return nil
},
func(in *map[string]*newer.RoleBinding, out *[]NamedRoleBinding, s conversion.Scope) error {
allKeys := make([]string, 0, len(*in))
for key := range *in {
allKeys = append(allKeys, key)
}
sort.Strings(allKeys)
for _, key := range allKeys {
newRoleBinding := (*in)[key]
oldRoleBinding := &RoleBinding{}
if err := s.Convert(newRoleBinding, oldRoleBinding, 0); err != nil {
return err
}
namedRoleBinding := NamedRoleBinding{key, *oldRoleBinding}
*out = append(*out, namedRoleBinding)
}
return nil
},
func(in *[]NamedClusterRole, out *map[string]*newer.ClusterRole, s conversion.Scope) error {
for _, curr := range *in {
newRole := &newer.ClusterRole{}
if err := s.Convert(&curr.Role, newRole, 0); err != nil {
return err
}
if *out == nil {
m := make(map[string]*newer.ClusterRole)
*out = m
}
(*out)[curr.Name] = newRole
}
return nil
},
func(in *map[string]*newer.ClusterRole, out *[]NamedClusterRole, s conversion.Scope) error {
allKeys := make([]string, 0, len(*in))
for key := range *in {
allKeys = append(allKeys, key)
}
sort.Strings(allKeys)
for _, key := range allKeys {
newRole := (*in)[key]
oldRole := &ClusterRole{}
if err := s.Convert(newRole, oldRole, 0); err != nil {
return err
}
namedRole := NamedClusterRole{key, *oldRole}
*out = append(*out, namedRole)
}
return nil
},
func(in *[]NamedRole, out *map[string]*newer.Role, s conversion.Scope) error {
for _, curr := range *in {
newRole := &newer.Role{}
if err := s.Convert(&curr.Role, newRole, 0); err != nil {
return err
}
(*out)[curr.Name] = newRole
}
return nil
},
func(in *map[string]*newer.Role, out *[]NamedRole, s conversion.Scope) error {
allKeys := make([]string, 0, len(*in))
for key := range *in {
allKeys = append(allKeys, key)
}
sort.Strings(allKeys)
for _, key := range allKeys {
newRole := (*in)[key]
oldRole := &Role{}
if err := s.Convert(newRole, oldRole, 0); err != nil {
return err
}
namedRole := NamedRole{key, *oldRole}
*out = append(*out, namedRole)
}
return nil
},
func(in *[]NamedClusterRoleBinding, out *map[string]*newer.ClusterRoleBinding, s conversion.Scope) error {
for _, curr := range *in {
newRoleBinding := &newer.ClusterRoleBinding{}
if err := s.Convert(&curr.RoleBinding, newRoleBinding, 0); err != nil {
return err
}
(*out)[curr.Name] = newRoleBinding
}
return nil
},
func(in *map[string]*newer.ClusterRoleBinding, out *[]NamedClusterRoleBinding, s conversion.Scope) error {
allKeys := make([]string, 0, len(*in))
for key := range *in {
allKeys = append(allKeys, key)
}
sort.Strings(allKeys)
for _, key := range allKeys {
newRoleBinding := (*in)[key]
oldRoleBinding := &ClusterRoleBinding{}
if err := s.Convert(newRoleBinding, oldRoleBinding, 0); err != nil {
return err
}
namedRoleBinding := NamedClusterRoleBinding{key, *oldRoleBinding}
*out = append(*out, namedRoleBinding)
}
return nil
},
)
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
}