forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.go
45 lines (37 loc) · 1.4 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
package useridentitymapping
import (
"fmt"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/openshift/origin/pkg/user/api"
"github.com/openshift/origin/pkg/user/api/validation"
)
// REST implements the RESTStorage interface in terms of an Registry.
type REST struct {
registry Registry
}
// NewREST returns a new REST.
func NewREST(registry Registry) apiserver.RESTStorage {
return &REST{registry}
}
// New returns a new UserIdentityMapping for use with Create and Update.
func (s *REST) New() runtime.Object {
return &api.UserIdentityMapping{}
}
// Get retrieves an UserIdentityMapping by id.
func (s *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) {
return s.registry.GetUserIdentityMapping(id)
}
// Update will create or update a UserIdentityMapping
func (s *REST) Update(ctx kapi.Context, obj runtime.Object) (runtime.Object, bool, error) {
mapping, ok := obj.(*api.UserIdentityMapping)
if !ok {
return nil, false, fmt.Errorf("not a user identity mapping: %#v", obj)
}
if errs := validation.ValidateUserIdentityMapping(mapping); len(errs) > 0 {
return nil, false, errors.NewInvalid("userIdentityMapping", mapping.Name, errs)
}
return s.registry.CreateOrUpdateUserIdentityMapping(mapping)
}