forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest.go
59 lines (49 loc) · 1.85 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
package policy
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
// REST implements the RESTStorage interface in terms of an Registry.
type REST struct {
registry Registry
}
// NewREST creates a new REST for policies.
func NewREST(registry Registry) apiserver.RESTStorage {
return &REST{registry}
}
// New creates a new Policy object
func (r *REST) New() runtime.Object {
return &authorizationapi.Policy{}
}
func (r *REST) NewList() runtime.Object {
return &authorizationapi.PolicyList{}
}
// List obtains a list of Policies that match selector.
func (r *REST) List(ctx kapi.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) {
policies, err := r.registry.ListPolicies(ctx, label, field)
if err != nil {
return nil, err
}
return policies, err
}
// Get obtains the policy specified by its id.
func (r *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) {
policy, err := r.registry.GetPolicy(ctx, id)
if err != nil {
return nil, err
}
return policy, err
}
// Delete asynchronously deletes the Policy specified by its id.
func (r *REST) Delete(ctx kapi.Context, id string) (runtime.Object, error) {
return &kapi.Status{Status: kapi.StatusSuccess}, r.registry.DeletePolicy(ctx, id)
}
// Watch begins watching for new, changed, or deleted PolicyBindings.
func (r *REST) Watch(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return r.registry.WatchPolicies(ctx, label, field, resourceVersion)
}