forked from sensu/sensu-go
/
rolebinding.go
38 lines (30 loc) · 1.24 KB
/
rolebinding.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
package client
import (
corev2 "github.com/sensu/sensu-go/api/core/v2"
"github.com/sensu/sensu-go/types"
)
var roleBindingsPath = createNSBasePath(coreAPIGroup, coreAPIVersion, "rolebindings")
// CreateRoleBinding with the given role binding
func (client *RestClient) CreateRoleBinding(roleBinding *types.RoleBinding) error {
return client.Post(roleBindingsPath(roleBinding.Namespace), roleBinding)
}
// DeleteRoleBinding with the given name
func (client *RestClient) DeleteRoleBinding(namespace, name string) error {
return client.Delete(roleBindingsPath(namespace, name))
}
// FetchRoleBinding with the given name
func (client *RestClient) FetchRoleBinding(name string) (*types.RoleBinding, error) {
roleBinding := &types.RoleBinding{}
if err := client.Get(roleBindingsPath(client.config.Namespace(), name), roleBinding); err != nil {
return nil, err
}
return roleBinding, nil
}
// ListRoleBindings lists the role bindings within the given namespace.
func (client *RestClient) ListRoleBindings(namespace string, options *ListOptions) ([]corev2.RoleBinding, error) {
roleBindings := []corev2.RoleBinding{}
if err := client.List(roleBindingsPath(namespace), &roleBindings, options); err != nil {
return roleBindings, err
}
return roleBindings, nil
}