forked from sensu/sensu-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clusterrolebinding_store.go
65 lines (54 loc) · 2.34 KB
/
clusterrolebinding_store.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
package etcd
import (
"context"
"path"
"github.com/sensu/sensu-go/backend/store"
"github.com/sensu/sensu-go/types"
)
var (
clusterRoleBindingPathPrefix = "rbac/clusterrolebindings"
)
func getClusterRoleBindingPath(clusterRole *types.ClusterRoleBinding) string {
return path.Join(store.Root, clusterRoleBindingPathPrefix, clusterRole.Name)
}
// GetClusterRoleBindingsPath gets the path of the cluster role binding store.
func GetClusterRoleBindingsPath(ctx context.Context, name string) string {
return path.Join(store.Root, clusterRoleBindingPathPrefix, name)
}
// CreateClusterRoleBinding ...
func (s *Store) CreateClusterRoleBinding(ctx context.Context, clusterRoleBinding *types.ClusterRoleBinding) error {
if err := clusterRoleBinding.Validate(); err != nil {
return &store.ErrNotValid{Err: err}
}
return Create(ctx, s.client, getClusterRoleBindingPath(clusterRoleBinding), "", clusterRoleBinding)
}
// CreateOrUpdateClusterRoleBinding ...
func (s *Store) CreateOrUpdateClusterRoleBinding(ctx context.Context, clusterRoleBinding *types.ClusterRoleBinding) error {
if err := clusterRoleBinding.Validate(); err != nil {
return &store.ErrNotValid{Err: err}
}
return CreateOrUpdate(ctx, s.client, getClusterRoleBindingPath(clusterRoleBinding), "", clusterRoleBinding)
}
// DeleteClusterRoleBinding ...
func (s *Store) DeleteClusterRoleBinding(ctx context.Context, name string) error {
return Delete(ctx, s.client, GetClusterRoleBindingsPath(ctx, name))
}
// GetClusterRoleBinding ...
func (s *Store) GetClusterRoleBinding(ctx context.Context, name string) (*types.ClusterRoleBinding, error) {
role := &types.ClusterRoleBinding{}
err := Get(ctx, s.client, GetClusterRoleBindingsPath(ctx, name), role)
return role, err
}
// ListClusterRoleBindings ...
func (s *Store) ListClusterRoleBindings(ctx context.Context, pred *store.SelectionPredicate) ([]*types.ClusterRoleBinding, error) {
roles := []*types.ClusterRoleBinding{}
err := List(ctx, s.client, GetClusterRoleBindingsPath, &roles, pred)
return roles, err
}
// UpdateClusterRoleBinding ...
func (s *Store) UpdateClusterRoleBinding(ctx context.Context, clusterRoleBinding *types.ClusterRoleBinding) error {
if err := clusterRoleBinding.Validate(); err != nil {
return &store.ErrNotValid{Err: err}
}
return Update(ctx, s.client, getClusterRoleBindingPath(clusterRoleBinding), "", clusterRoleBinding)
}