forked from keybase/client
/
kvstore.go
317 lines (286 loc) · 8.84 KB
/
kvstore.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// Auto-generated to Go types and interfaces using avdl-compiler v1.4.9 (https://github.com/keybase/node-avdl-compiler)
// Input file: avdl/keybase1/kvstore.avdl
package keybase1
import (
"github.com/keybase/go-framed-msgpack-rpc/rpc"
context "golang.org/x/net/context"
"time"
)
type KVGetResult struct {
TeamName string `codec:"teamName" json:"teamName"`
Namespace string `codec:"namespace" json:"namespace"`
EntryKey string `codec:"entryKey" json:"entryKey"`
EntryValue *string `codec:"entryValue" json:"entryValue"`
Revision int `codec:"revision" json:"revision"`
}
func (o KVGetResult) DeepCopy() KVGetResult {
return KVGetResult{
TeamName: o.TeamName,
Namespace: o.Namespace,
EntryKey: o.EntryKey,
EntryValue: (func(x *string) *string {
if x == nil {
return nil
}
tmp := (*x)
return &tmp
})(o.EntryValue),
Revision: o.Revision,
}
}
type KVPutResult struct {
TeamName string `codec:"teamName" json:"teamName"`
Namespace string `codec:"namespace" json:"namespace"`
EntryKey string `codec:"entryKey" json:"entryKey"`
Revision int `codec:"revision" json:"revision"`
}
func (o KVPutResult) DeepCopy() KVPutResult {
return KVPutResult{
TeamName: o.TeamName,
Namespace: o.Namespace,
EntryKey: o.EntryKey,
Revision: o.Revision,
}
}
type KVEntryID struct {
TeamID TeamID `codec:"teamID" json:"teamID"`
Namespace string `codec:"namespace" json:"namespace"`
EntryKey string `codec:"entryKey" json:"entryKey"`
}
func (o KVEntryID) DeepCopy() KVEntryID {
return KVEntryID{
TeamID: o.TeamID.DeepCopy(),
Namespace: o.Namespace,
EntryKey: o.EntryKey,
}
}
type EncryptedKVEntry struct {
V int `codec:"v" json:"v"`
E []byte `codec:"e" json:"e"`
N []byte `codec:"n" json:"n"`
}
func (o EncryptedKVEntry) DeepCopy() EncryptedKVEntry {
return EncryptedKVEntry{
V: o.V,
E: (func(x []byte) []byte {
if x == nil {
return nil
}
return append([]byte{}, x...)
})(o.E),
N: (func(x []byte) []byte {
if x == nil {
return nil
}
return append([]byte{}, x...)
})(o.N),
}
}
type KVListNamespaceResult struct {
TeamName string `codec:"teamName" json:"teamName"`
Namespaces []string `codec:"namespaces" json:"namespaces"`
}
func (o KVListNamespaceResult) DeepCopy() KVListNamespaceResult {
return KVListNamespaceResult{
TeamName: o.TeamName,
Namespaces: (func(x []string) []string {
if x == nil {
return nil
}
ret := make([]string, len(x))
for i, v := range x {
vCopy := v
ret[i] = vCopy
}
return ret
})(o.Namespaces),
}
}
type KVListEntryKey struct {
EntryKey string `codec:"entryKey" json:"entryKey"`
Revision int `codec:"revision" json:"revision"`
}
func (o KVListEntryKey) DeepCopy() KVListEntryKey {
return KVListEntryKey{
EntryKey: o.EntryKey,
Revision: o.Revision,
}
}
type KVListEntryResult struct {
TeamName string `codec:"teamName" json:"teamName"`
Namespace string `codec:"namespace" json:"namespace"`
EntryKeys []KVListEntryKey `codec:"entryKeys" json:"entryKeys"`
}
func (o KVListEntryResult) DeepCopy() KVListEntryResult {
return KVListEntryResult{
TeamName: o.TeamName,
Namespace: o.Namespace,
EntryKeys: (func(x []KVListEntryKey) []KVListEntryKey {
if x == nil {
return nil
}
ret := make([]KVListEntryKey, len(x))
for i, v := range x {
vCopy := v.DeepCopy()
ret[i] = vCopy
}
return ret
})(o.EntryKeys),
}
}
type KVDeleteEntryResult struct {
TeamName string `codec:"teamName" json:"teamName"`
Namespace string `codec:"namespace" json:"namespace"`
EntryKey string `codec:"entryKey" json:"entryKey"`
Revision int `codec:"revision" json:"revision"`
}
func (o KVDeleteEntryResult) DeepCopy() KVDeleteEntryResult {
return KVDeleteEntryResult{
TeamName: o.TeamName,
Namespace: o.Namespace,
EntryKey: o.EntryKey,
Revision: o.Revision,
}
}
type GetKVEntryArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
TeamName string `codec:"teamName" json:"teamName"`
Namespace string `codec:"namespace" json:"namespace"`
EntryKey string `codec:"entryKey" json:"entryKey"`
}
type PutKVEntryArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
TeamName string `codec:"teamName" json:"teamName"`
Namespace string `codec:"namespace" json:"namespace"`
EntryKey string `codec:"entryKey" json:"entryKey"`
Revision int `codec:"revision" json:"revision"`
EntryValue string `codec:"entryValue" json:"entryValue"`
}
type ListKVNamespacesArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
TeamName string `codec:"teamName" json:"teamName"`
}
type ListKVEntriesArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
TeamName string `codec:"teamName" json:"teamName"`
Namespace string `codec:"namespace" json:"namespace"`
}
type DelKVEntryArg struct {
SessionID int `codec:"sessionID" json:"sessionID"`
TeamName string `codec:"teamName" json:"teamName"`
Namespace string `codec:"namespace" json:"namespace"`
EntryKey string `codec:"entryKey" json:"entryKey"`
Revision int `codec:"revision" json:"revision"`
}
type KvstoreInterface interface {
GetKVEntry(context.Context, GetKVEntryArg) (KVGetResult, error)
PutKVEntry(context.Context, PutKVEntryArg) (KVPutResult, error)
ListKVNamespaces(context.Context, ListKVNamespacesArg) (KVListNamespaceResult, error)
ListKVEntries(context.Context, ListKVEntriesArg) (KVListEntryResult, error)
DelKVEntry(context.Context, DelKVEntryArg) (KVDeleteEntryResult, error)
}
func KvstoreProtocol(i KvstoreInterface) rpc.Protocol {
return rpc.Protocol{
Name: "keybase.1.kvstore",
Methods: map[string]rpc.ServeHandlerDescription{
"getKVEntry": {
MakeArg: func() interface{} {
var ret [1]GetKVEntryArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]GetKVEntryArg)
if !ok {
err = rpc.NewTypeError((*[1]GetKVEntryArg)(nil), args)
return
}
ret, err = i.GetKVEntry(ctx, typedArgs[0])
return
},
},
"putKVEntry": {
MakeArg: func() interface{} {
var ret [1]PutKVEntryArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]PutKVEntryArg)
if !ok {
err = rpc.NewTypeError((*[1]PutKVEntryArg)(nil), args)
return
}
ret, err = i.PutKVEntry(ctx, typedArgs[0])
return
},
},
"listKVNamespaces": {
MakeArg: func() interface{} {
var ret [1]ListKVNamespacesArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]ListKVNamespacesArg)
if !ok {
err = rpc.NewTypeError((*[1]ListKVNamespacesArg)(nil), args)
return
}
ret, err = i.ListKVNamespaces(ctx, typedArgs[0])
return
},
},
"listKVEntries": {
MakeArg: func() interface{} {
var ret [1]ListKVEntriesArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]ListKVEntriesArg)
if !ok {
err = rpc.NewTypeError((*[1]ListKVEntriesArg)(nil), args)
return
}
ret, err = i.ListKVEntries(ctx, typedArgs[0])
return
},
},
"delKVEntry": {
MakeArg: func() interface{} {
var ret [1]DelKVEntryArg
return &ret
},
Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
typedArgs, ok := args.(*[1]DelKVEntryArg)
if !ok {
err = rpc.NewTypeError((*[1]DelKVEntryArg)(nil), args)
return
}
ret, err = i.DelKVEntry(ctx, typedArgs[0])
return
},
},
},
}
}
type KvstoreClient struct {
Cli rpc.GenericClient
}
func (c KvstoreClient) GetKVEntry(ctx context.Context, __arg GetKVEntryArg) (res KVGetResult, err error) {
err = c.Cli.Call(ctx, "keybase.1.kvstore.getKVEntry", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}
func (c KvstoreClient) PutKVEntry(ctx context.Context, __arg PutKVEntryArg) (res KVPutResult, err error) {
err = c.Cli.Call(ctx, "keybase.1.kvstore.putKVEntry", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}
func (c KvstoreClient) ListKVNamespaces(ctx context.Context, __arg ListKVNamespacesArg) (res KVListNamespaceResult, err error) {
err = c.Cli.Call(ctx, "keybase.1.kvstore.listKVNamespaces", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}
func (c KvstoreClient) ListKVEntries(ctx context.Context, __arg ListKVEntriesArg) (res KVListEntryResult, err error) {
err = c.Cli.Call(ctx, "keybase.1.kvstore.listKVEntries", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}
func (c KvstoreClient) DelKVEntry(ctx context.Context, __arg DelKVEntryArg) (res KVDeleteEntryResult, err error) {
err = c.Cli.Call(ctx, "keybase.1.kvstore.delKVEntry", []interface{}{__arg}, &res, 0*time.Millisecond)
return
}