forked from projectatomic/atomic-enterprise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest.go
77 lines (62 loc) · 2.2 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
77
package authorizetoken
import (
"fmt"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"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"
//"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) apiserver.RESTStorage {
return &REST{registry}
}
// New returns a new AuthorizeToken for use with Create and Update.
func (s *REST) New() runtime.Object {
return &api.OAuthAuthorizeToken{}
}
func (*REST) NewList() runtime.Object {
return &api.OAuthAuthorizeToken{}
}
// Get retrieves an AuthorizeToken by id.
func (s *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) {
token, err := s.registry.GetAuthorizeToken(id)
if err != nil {
return nil, err
}
return token, nil
}
// List retrieves a list of AuthorizeTokens that match selector.
func (s *REST) List(ctx kapi.Context, selector, fields labels.Selector) (runtime.Object, error) {
tokens, err := s.registry.ListAuthorizeTokens(selector)
if err != nil {
return nil, err
}
return tokens, nil
}
// Create registers the given AuthorizeToken.
func (s *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
token, ok := obj.(*api.OAuthAuthorizeToken)
if !ok {
return nil, fmt.Errorf("not an token: %#v", obj)
}
kapi.FillObjectMetaSystemFields(ctx, &token.ObjectMeta)
if errs := validation.ValidateAuthorizeToken(token); len(errs) > 0 {
return nil, kerrors.NewInvalid("token", token.Name, errs)
}
if err := s.registry.CreateAuthorizeToken(token); err != nil {
return nil, err
}
return s.Get(ctx, token.Name)
}
// Delete asynchronously deletes an AuthorizeToken specified by its id.
func (s *REST) Delete(ctx kapi.Context, id string) (runtime.Object, error) {
return &kapi.Status{Status: kapi.StatusSuccess}, s.registry.DeleteAuthorizeToken(id)
}