forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest.go
76 lines (61 loc) · 2.03 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
72
73
74
75
76
package client
import (
"fmt"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/openshift/origin/pkg/oauth/api"
"github.com/openshift/origin/pkg/oauth/api/validation"
)
// REST implements the RESTStorage interface in terms of an Registry.
type REST struct {
registry Registry
}
// NewStorage returns a new REST.
func NewREST(registry Registry) *REST {
return &REST{registry}
}
// New returns a new Client for use with Create and Update.
func (s *REST) New() runtime.Object {
return &api.OAuthClient{}
}
func (*REST) NewList() runtime.Object {
return &api.OAuthClient{}
}
// Get retrieves an Client by id.
func (s *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) {
client, err := s.registry.GetClient(id)
if err != nil {
return nil, err
}
return client, nil
}
// List retrieves a list of Clients that match label.
func (s *REST) List(ctx kapi.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) {
clients, err := s.registry.ListClients(label)
if err != nil {
return nil, err
}
return clients, nil
}
// Create registers the given Client.
func (s *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
client, ok := obj.(*api.OAuthClient)
if !ok {
return nil, fmt.Errorf("not an client: %#v", obj)
}
kapi.FillObjectMetaSystemFields(ctx, &client.ObjectMeta)
if errs := validation.ValidateClient(client); len(errs) > 0 {
return nil, kerrors.NewInvalid("oauthClient", client.Name, errs)
}
if err := s.registry.CreateClient(client); err != nil {
return nil, err
}
return s.Get(ctx, client.Name)
}
// Delete asynchronously deletes an Client specified by its id.
func (s *REST) Delete(ctx kapi.Context, id string) (runtime.Object, error) {
return &kapi.Status{Status: kapi.StatusSuccess}, s.registry.DeleteClient(id)
}