forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
81 lines (70 loc) · 2.89 KB
/
registry.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
79
80
81
package oauthclientauthorization
import (
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"github.com/openshift/origin/pkg/oauth/api"
)
// Registry is an interface for things that know how to store OAuthClientAuthorization objects.
type Registry interface {
// ClientAuthorizationName returns the name of the OAuthClientAuthorization for the given user name and client name
ClientAuthorizationName(userName, clientName string) string
// ListClientAuthorizations obtains a list of client auths that match a selector.
ListClientAuthorizations(ctx kapi.Context, selector labels.Selector) (*api.OAuthClientAuthorizationList, error)
// GetClientAuthorization retrieves a specific client auth.
GetClientAuthorization(ctx kapi.Context, name string) (*api.OAuthClientAuthorization, error)
// CreateClientAuthorization creates a new client auth.
CreateClientAuthorization(ctx kapi.Context, client *api.OAuthClientAuthorization) (*api.OAuthClientAuthorization, error)
// UpdateClientAuthorization updates a client auth.
UpdateClientAuthorization(ctx kapi.Context, client *api.OAuthClientAuthorization) (*api.OAuthClientAuthorization, error)
// DeleteClientAuthorization deletes a client auth.
DeleteClientAuthorization(ctx kapi.Context, name string) error
}
// storage puts strong typing around storage calls
type storage struct {
rest.StandardStorage
}
// NewRegistry returns a new Registry interface for the given Storage. Any mismatched
// types will panic.
func NewRegistry(s rest.StandardStorage) Registry {
return &storage{s}
}
func (s *storage) ClientAuthorizationName(userName, clientName string) string {
return userName + ":" + clientName
}
func (s *storage) ListClientAuthorizations(ctx kapi.Context, label labels.Selector) (*api.OAuthClientAuthorizationList, error) {
obj, err := s.List(ctx, label, fields.Everything())
if err != nil {
return nil, err
}
return obj.(*api.OAuthClientAuthorizationList), nil
}
func (s *storage) GetClientAuthorization(ctx kapi.Context, name string) (*api.OAuthClientAuthorization, error) {
obj, err := s.Get(ctx, name)
if err != nil {
return nil, err
}
return obj.(*api.OAuthClientAuthorization), nil
}
func (s *storage) CreateClientAuthorization(ctx kapi.Context, client *api.OAuthClientAuthorization) (*api.OAuthClientAuthorization, error) {
obj, err := s.Create(ctx, client)
if err != nil {
return nil, err
}
return obj.(*api.OAuthClientAuthorization), nil
}
func (s *storage) UpdateClientAuthorization(ctx kapi.Context, client *api.OAuthClientAuthorization) (*api.OAuthClientAuthorization, error) {
obj, _, err := s.Update(ctx, client)
if err != nil {
return nil, err
}
return obj.(*api.OAuthClientAuthorization), nil
}
func (s *storage) DeleteClientAuthorization(ctx kapi.Context, name string) error {
_, err := s.Delete(ctx, name, nil)
if err != nil {
return err
}
return nil
}