forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
policies.go
61 lines (51 loc) · 2.15 KB
/
policies.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
package client
import (
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/watch"
authorizationapi "github.com/openshift/origin/pkg/authorization/api"
)
// PoliciesNamespacer has methods to work with Policy resources in a namespace
type PoliciesNamespacer interface {
Policies(namespace string) PolicyInterface
}
// PolicyInterface exposes methods on Policy resources.
type PolicyInterface interface {
List(label labels.Selector, field fields.Selector) (*authorizationapi.PolicyList, error)
Get(name string) (*authorizationapi.Policy, error)
Delete(name string) error
Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
}
// policies implements PoliciesNamespacer interface
type policies struct {
r *Client
ns string
}
// newPolicies returns a policies
func newPolicies(c *Client, namespace string) *policies {
return &policies{
r: c,
ns: namespace,
}
}
// List returns a list of policies that match the label and field selectors.
func (c *policies) List(label labels.Selector, field fields.Selector) (result *authorizationapi.PolicyList, err error) {
result = &authorizationapi.PolicyList{}
err = c.r.Get().Namespace(c.ns).Resource("policies").LabelsSelectorParam(label).FieldsSelectorParam(field).Do().Into(result)
return
}
// Get returns information about a particular policy and error if one occurs.
func (c *policies) Get(name string) (result *authorizationapi.Policy, err error) {
result = &authorizationapi.Policy{}
err = c.r.Get().Namespace(c.ns).Resource("policies").Name(name).Do().Into(result)
return
}
// Delete deletes a policy, returns error if one occurs.
func (c *policies) Delete(name string) (err error) {
err = c.r.Delete().Namespace(c.ns).Resource("policies").Name(name).Do().Error()
return
}
// Watch returns a watch.Interface that watches the requested policies
func (c *policies) Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().Prefix("watch").Namespace(c.ns).Resource("policies").Param("resourceVersion", resourceVersion).LabelsSelectorParam(label).FieldsSelectorParam(field).Watch()
}