This repository has been archived by the owner on Mar 22, 2018. It is now read-only.
/
rest.go
71 lines (58 loc) · 2.06 KB
/
rest.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
package user
import (
"fmt"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kerrs "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/openshift/origin/pkg/user/api"
"github.com/openshift/origin/pkg/user/api/validation"
)
// userStrategy implements behavior for Users
type userStrategy struct {
runtime.ObjectTyper
}
// Strategy is the default logic that applies when creating and updating User
// objects via the REST API.
var Strategy = userStrategy{kapi.Scheme}
// NamespaceScoped is false for users
func (userStrategy) NamespaceScoped() bool {
return false
}
func (userStrategy) GenerateName(base string) string {
return base
}
func (userStrategy) ResetBeforeCreate(obj runtime.Object) {
}
// Validate validates a new user
func (userStrategy) Validate(obj runtime.Object) kerrs.ValidationErrorList {
user := obj.(*api.User)
return validation.ValidateUser(user)
}
// AllowCreateOnUpdate is false for users
func (userStrategy) AllowCreateOnUpdate() bool {
return false
}
// ValidateUpdate is the default update validation for an end user.
func (userStrategy) ValidateUpdate(obj, old runtime.Object) kerrs.ValidationErrorList {
return validation.ValidateUserUpdate(obj.(*api.User), old.(*api.User))
}
// MatchUser returns a generic matcher for a given label and field selector.
func MatchUser(label labels.Selector, field fields.Selector) generic.Matcher {
return generic.MatcherFunc(func(obj runtime.Object) (bool, error) {
userObj, ok := obj.(*api.User)
if !ok {
return false, fmt.Errorf("not a user")
}
fields := UserToSelectableFields(userObj)
return label.Matches(labels.Set(userObj.Labels)) && field.Matches(fields), nil
})
}
// UserToSelectableFields returns a label set that represents the object
func UserToSelectableFields(user *api.User) labels.Set {
return labels.Set{
"name": user.Name,
}
}