forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
strategy.go
88 lines (69 loc) · 2.71 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
88
package useridentitymapping
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/kubernetes/pkg/api/legacyscheme"
userapi "github.com/openshift/origin/pkg/user/apis/user"
"github.com/openshift/origin/pkg/user/apis/user/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{legacyscheme.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 apirequest.Context, obj runtime.Object) {
mapping := obj.(*userapi.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 apirequest.Context, obj, old runtime.Object) {
mapping := obj.(*userapi.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 apirequest.Context, obj runtime.Object) field.ErrorList {
return validation.ValidateUserIdentityMapping(obj.(*userapi.UserIdentityMapping))
}
// Validate validates an updated UserIdentityMapping.
func (s userIdentityMappingStrategy) ValidateUpdate(ctx apirequest.Context, obj runtime.Object, old runtime.Object) field.ErrorList {
return validation.ValidateUserIdentityMappingUpdate(obj.(*userapi.UserIdentityMapping), old.(*userapi.UserIdentityMapping))
}