forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
etcd.go
78 lines (64 loc) · 2.5 KB
/
etcd.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
package etcd
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
etcdgeneric "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/openshift/origin/pkg/oauth/api"
"github.com/openshift/origin/pkg/oauth/registry/oauthauthorizetoken"
)
// rest implements a RESTStorage for authorize tokens against etcd
type REST struct {
// Cannot inline because we don't want the Update function
store *etcdgeneric.Etcd
}
const EtcdPrefix = "/oauth/authorizetokens"
// NewREST returns a RESTStorage object that will work against authorize tokens
func NewREST(h tools.EtcdHelper) *REST {
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.OAuthAuthorizeToken{} },
NewListFunc: func() runtime.Object { return &api.OAuthAuthorizeTokenList{} },
KeyRootFunc: func(ctx kapi.Context) string {
return EtcdPrefix
},
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return etcdgeneric.NoNamespaceKeyFunc(ctx, EtcdPrefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.OAuthAuthorizeToken).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return oauthauthorizetoken.Matcher(label, field)
},
TTLFunc: func(obj runtime.Object, update bool) (uint64, error) {
token := obj.(*api.OAuthAuthorizeToken)
expires := uint64(token.ExpiresIn)
return expires, nil
},
EndpointName: "oauthauthorizetokens",
Helper: h,
}
store.CreateStrategy = oauthauthorizetoken.Strategy
return &REST{store}
}
func (r *REST) New() runtime.Object {
return r.store.NewFunc()
}
func (r *REST) NewList() runtime.Object {
return r.store.NewListFunc()
}
func (r *REST) Get(ctx kapi.Context, name string) (runtime.Object, error) {
return r.store.Get(ctx, name)
}
func (r *REST) List(ctx kapi.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) {
return r.store.List(ctx, label, field)
}
func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {
return r.store.Create(ctx, obj)
}
func (r *REST) Delete(ctx kapi.Context, name string, options *kapi.DeleteOptions) (runtime.Object, error) {
return r.store.Delete(ctx, name, options)
}