-
Notifications
You must be signed in to change notification settings - Fork 53
/
stores.go
127 lines (103 loc) · 4.14 KB
/
stores.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package storage
import (
"context"
"time"
corev1 "github.com/rancher/opni/pkg/apis/core/v1"
"github.com/rancher/opni/pkg/keyring"
)
type Backend interface {
TokenStore
ClusterStore
RBACStore
KeyringStoreBroker
KeyValueStoreBroker
}
type MutatorFunc[T any] func(T)
type TokenMutator = MutatorFunc[*corev1.BootstrapToken]
type ClusterMutator = MutatorFunc[*corev1.Cluster]
type TokenStore interface {
CreateToken(ctx context.Context, ttl time.Duration, opts ...TokenCreateOption) (*corev1.BootstrapToken, error)
DeleteToken(ctx context.Context, ref *corev1.Reference) error
GetToken(ctx context.Context, ref *corev1.Reference) (*corev1.BootstrapToken, error)
UpdateToken(ctx context.Context, ref *corev1.Reference, mutator TokenMutator) (*corev1.BootstrapToken, error)
ListTokens(ctx context.Context) ([]*corev1.BootstrapToken, error)
}
type ClusterStore interface {
CreateCluster(ctx context.Context, cluster *corev1.Cluster) error
DeleteCluster(ctx context.Context, ref *corev1.Reference) error
GetCluster(ctx context.Context, ref *corev1.Reference) (*corev1.Cluster, error)
UpdateCluster(ctx context.Context, ref *corev1.Reference, mutator ClusterMutator) (*corev1.Cluster, error)
WatchCluster(ctx context.Context, cluster *corev1.Cluster) (<-chan WatchEvent[*corev1.Cluster], error)
WatchClusters(ctx context.Context, known []*corev1.Cluster) (<-chan WatchEvent[*corev1.Cluster], error)
ListClusters(ctx context.Context, matchLabels *corev1.LabelSelector, matchOptions corev1.MatchOptions) (*corev1.ClusterList, error)
}
type RBACStore interface {
CreateRole(context.Context, *corev1.Role) error
DeleteRole(context.Context, *corev1.Reference) error
GetRole(context.Context, *corev1.Reference) (*corev1.Role, error)
CreateRoleBinding(context.Context, *corev1.RoleBinding) error
DeleteRoleBinding(context.Context, *corev1.Reference) error
GetRoleBinding(context.Context, *corev1.Reference) (*corev1.RoleBinding, error)
ListRoles(context.Context) (*corev1.RoleList, error)
ListRoleBindings(context.Context) (*corev1.RoleBindingList, error)
}
type KeyringStore interface {
Put(ctx context.Context, keyring keyring.Keyring) error
Get(ctx context.Context) (keyring.Keyring, error)
Delete(ctx context.Context) error
}
type KeyValueStoreT[T any] interface {
Put(ctx context.Context, key string, value T) error
Get(ctx context.Context, key string) (T, error)
Delete(ctx context.Context, key string) error
ListKeys(ctx context.Context, prefix string) ([]string, error)
}
type KeyValueStore KeyValueStoreT[[]byte]
type KeyringStoreBroker interface {
KeyringStore(namespace string, ref *corev1.Reference) KeyringStore
}
type KeyValueStoreBroker interface {
KeyValueStore(namespace string) KeyValueStore
}
// A store that can be used to compute subject access rules
type SubjectAccessCapableStore interface {
ListClusters(ctx context.Context, matchLabels *corev1.LabelSelector, matchOptions corev1.MatchOptions) (*corev1.ClusterList, error)
GetRole(ctx context.Context, ref *corev1.Reference) (*corev1.Role, error)
ListRoleBindings(ctx context.Context) (*corev1.RoleBindingList, error)
}
type WatchEventType string
const (
WatchEventCreate WatchEventType = "PUT"
WatchEventUpdate WatchEventType = "UPDATE"
WatchEventDelete WatchEventType = "DELETE"
)
type WatchEvent[T any] struct {
EventType WatchEventType
Current T
Previous T
}
type HttpTtlCache[T any] interface {
// getter for default cache's configuration
MaxAge() time.Duration
Get(key string) (resp T, ok bool)
// If 0 is passed as ttl, the default cache's configuration will be used
Set(key string, resp T)
Delete(key string)
}
type GrpcTtlCache[T any] interface {
// getter for default cache's configuration
MaxAge() time.Duration
Get(key string) (resp T, ok bool)
// If 0 is passed as ttl, the default cache's configuration will be used
Set(key string, resp T, ttl time.Duration)
Delete(key string)
}
var (
storeBuilderCache = map[string]func(...any) (any, error){}
)
func RegisterStoreBuilder[T ~string](name T, builder func(...any) (any, error)) {
storeBuilderCache[string(name)] = builder
}
func GetStoreBuilder[T ~string](name T) func(...any) (any, error) {
return storeBuilderCache[string(name)]
}