forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.go
87 lines (68 loc) · 2.58 KB
/
strategy.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
package useridentitymapping
import (
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/validation/field"
"github.com/openshift/origin/pkg/user/api"
"github.com/openshift/origin/pkg/user/api/validation"
)
// userIdentityMappingStrategy implements behavior for image repository mappings.
type userIdentityMappingStrategy struct {
runtime.ObjectTyper
}
// Strategy is the default logic that applies when creating UserIdentityMapping
// objects via the REST API.
var Strategy = userIdentityMappingStrategy{kapi.Scheme}
// NamespaceScoped is true for image repository mappings.
func (s userIdentityMappingStrategy) NamespaceScoped() bool {
return false
}
func (userIdentityMappingStrategy) GenerateName(base string) string {
return base
}
func (userIdentityMappingStrategy) AllowCreateOnUpdate() bool {
return true
}
func (userIdentityMappingStrategy) AllowUnconditionalUpdate() bool {
return false
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func (s userIdentityMappingStrategy) PrepareForCreate(ctx kapi.Context, obj runtime.Object) {
mapping := obj.(*api.UserIdentityMapping)
if len(mapping.Name) == 0 {
mapping.Name = mapping.Identity.Name
}
mapping.Namespace = ""
mapping.ResourceVersion = ""
mapping.Identity.Namespace = ""
mapping.Identity.Kind = ""
mapping.Identity.UID = ""
mapping.User.Namespace = ""
mapping.User.Kind = ""
mapping.User.UID = ""
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update
func (s userIdentityMappingStrategy) PrepareForUpdate(ctx kapi.Context, obj, old runtime.Object) {
mapping := obj.(*api.UserIdentityMapping)
if len(mapping.Name) == 0 {
mapping.Name = mapping.Identity.Name
}
mapping.Namespace = ""
mapping.Identity.Namespace = ""
mapping.Identity.Kind = ""
mapping.Identity.UID = ""
mapping.User.Namespace = ""
mapping.User.Kind = ""
mapping.User.UID = ""
}
// Canonicalize normalizes the object after validation.
func (s userIdentityMappingStrategy) Canonicalize(obj runtime.Object) {
}
// Validate validates a new UserIdentityMapping.
func (s userIdentityMappingStrategy) Validate(ctx kapi.Context, obj runtime.Object) field.ErrorList {
return validation.ValidateUserIdentityMapping(obj.(*api.UserIdentityMapping))
}
// Validate validates an updated UserIdentityMapping.
func (s userIdentityMappingStrategy) ValidateUpdate(ctx kapi.Context, obj runtime.Object, old runtime.Object) field.ErrorList {
return validation.ValidateUserIdentityMappingUpdate(obj.(*api.UserIdentityMapping), old.(*api.UserIdentityMapping))
}