forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
355 lines (310 loc) · 8.76 KB
/
interfaces.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package libkb
/*
* Interfaces
*
* Here are the interfaces that we're going to assume when
* implementing the features of command-line clients or
* servers. Depending on the context, we might get different
* instantiations of these interfaces.
*/
import (
"io"
"net/http"
"net/url"
"time"
"golang.org/x/net/context"
"github.com/PuerkitoBio/goquery"
keybase1 "github.com/keybase/client/go/protocol"
jsonw "github.com/keybase/go-jsonw"
)
type CommandLine interface {
GetHome() string
GetServerURI() string
GetConfigFilename() string
GetSessionFilename() string
GetDbFilename() string
GetDebug() (bool, bool)
GetProxy() string
GetLogFormat() string
GetGpgHome() string
GetAPIDump() (bool, bool)
GetUserCacheMaxAge() (time.Duration, bool)
GetProofCacheSize() (int, bool)
GetMerkleKIDs() []string
GetPinentry() string
GetGpg() string
GetGpgOptions() []string
GetPGPFingerprint() *PGPFingerprint
GetSecretKeyringTemplate() string
GetSocketFile() string
GetPidFile() string
GetStandalone() (bool, bool)
GetAutoFork() (bool, bool)
GetNoAutoFork() (bool, bool)
GetLocalRPCDebug() string
GetTimers() string
GetSplitLogOutput() (bool, bool)
GetLogFile() string
GetRunMode() (RunMode, error)
GetScraperTimeout() (time.Duration, bool)
GetAPITimeout() (time.Duration, bool)
GetTorMode() (TorMode, error)
GetTorHiddenAddress() string
GetTorProxy() string
// Lower-level functions
GetGString(string) string
GetString(string) string
GetBool(string, bool) (bool, bool)
}
type Server interface {
}
type ObjType byte
type DbKey struct {
Typ ObjType
Key string
}
type LocalDb interface {
Open() error
ForceOpen() error
Close() error
Nuke() (string, error)
Put(id DbKey, aliases []DbKey, value []byte) error
Delete(id DbKey) error
Get(id DbKey) ([]byte, bool, error)
Lookup(alias DbKey) ([]byte, bool, error)
}
type ConfigReader interface {
GetHome() string
GetServerURI() string
GetConfigFilename() string
GetSessionFilename() string
GetDbFilename() string
GetDebug() (bool, bool)
GetAutoFork() (bool, bool)
GetUserConfig() (*UserConfig, error)
GetUserConfigForUsername(s NormalizedUsername) (*UserConfig, error)
GetProxy() string
GetLogFormat() string
GetGpgHome() string
GetBundledCA(host string) string
GetStringAtPath(string) (string, bool)
GetBoolAtPath(string) (bool, bool)
GetIntAtPath(string) (int, bool)
GetNullAtPath(string) bool
GetUserCacheMaxAge() (time.Duration, bool)
GetProofCacheSize() (int, bool)
GetProofCacheLongDur() (time.Duration, bool)
GetProofCacheMediumDur() (time.Duration, bool)
GetProofCacheShortDur() (time.Duration, bool)
GetMerkleKIDs() []string
GetPinentry() string
GetNoPinentry() (bool, bool)
GetGpg() string
GetGpgOptions() []string
GetSecretKeyringTemplate() string
GetSalt() []byte
GetSocketFile() string
GetPidFile() string
GetStandalone() (bool, bool)
GetLocalRPCDebug() string
GetTimers() string
GetDeviceID() keybase1.DeviceID
GetUsername() NormalizedUsername
GetAllUsernames() (current NormalizedUsername, others []NormalizedUsername, err error)
GetUID() keybase1.UID
GetProxyCACerts() ([]string, error)
GetSplitLogOutput() (bool, bool)
GetLogFile() string
GetRunMode() (RunMode, error)
GetScraperTimeout() (time.Duration, bool)
GetAPITimeout() (time.Duration, bool)
GetSecurityAccessGroupOverride() (bool, bool)
GetTorMode() (TorMode, error)
GetTorHiddenAddress() string
GetTorProxy() string
}
type ConfigWriterTransacter interface {
Commit() error
Abort() error
}
type ConfigWriter interface {
SetUserConfig(cfg *UserConfig, overwrite bool) error
SwitchUser(un NormalizedUsername) error
NukeUser(un NormalizedUsername) error
SetDeviceID(keybase1.DeviceID) error
SetStringAtPath(string, string) error
SetBoolAtPath(string, bool) error
SetIntAtPath(string, int) error
SetNullAtPath(string) error
DeleteAtPath(string)
Reset()
Save() error
BeginTransaction() (ConfigWriterTransacter, error)
}
type HTTPRequest interface {
SetEnvironment(env Env)
}
type Usage struct {
Config bool
GpgKeyring bool
KbKeyring bool
API bool
Socket bool
}
type Command interface {
GetUsage() Usage
}
type JSONPayload map[string]interface{}
type APIArg struct {
Endpoint string
uArgs url.Values
Args HTTPArgs
JSONPayload JSONPayload
NeedSession bool
SessionR SessionReader
HTTPStatus []int
AppStatus []string
DecodeTo interface{}
Contextified
}
type APIRes struct {
Status *jsonw.Wrapper
Body *jsonw.Wrapper
HTTPStatus int
AppStatus string
}
type ExternalHTMLRes struct {
HTTPStatus int
GoQuery *goquery.Document
}
type ExternalTextRes struct {
HTTPStatus int
Body string
}
type ExternalAPIRes struct {
HTTPStatus int
Body *jsonw.Wrapper
}
type API interface {
Get(APIArg) (*APIRes, error)
GetResp(APIArg) (*http.Response, error)
GetDecode(APIArg, interface{}) error
Post(APIArg) (*APIRes, error)
PostJSON(APIArg) (*APIRes, error)
PostResp(APIArg) (*http.Response, error)
PostDecode(APIArg, interface{}) error
}
type ExternalAPI interface {
Get(APIArg) (*ExternalAPIRes, error)
Post(APIArg) (*ExternalAPIRes, error)
GetHTML(APIArg) (*ExternalHTMLRes, error)
GetText(APIArg) (*ExternalTextRes, error)
PostHTML(APIArg) (*ExternalHTMLRes, error)
}
type IdentifyUI interface {
Start(string)
FinishWebProofCheck(keybase1.RemoteProof, keybase1.LinkCheckResult)
FinishSocialProofCheck(keybase1.RemoteProof, keybase1.LinkCheckResult)
Confirm(*keybase1.IdentifyOutcome) (keybase1.ConfirmResult, error)
DisplayCryptocurrency(keybase1.Cryptocurrency)
DisplayKey(keybase1.IdentifyKey)
ReportLastTrack(*keybase1.TrackSummary)
LaunchNetworkChecks(*keybase1.Identity, *keybase1.User)
DisplayTrackStatement(string) error
ReportTrackToken(IdentifyCacheToken) error
SetStrict(b bool)
Finish()
}
type Checker struct {
F func(string) bool
Hint string
PreserveSpace bool
}
type PromptArg struct {
TerminalPrompt string
PinentryDesc string
PinentryPrompt string
Checker *Checker
RetryMessage string
UseSecretStore bool
}
type LoginUI interface {
keybase1.LoginUiInterface
}
type ProveUI interface {
PromptOverwrite(context.Context, keybase1.PromptOverwriteArg) (bool, error)
PromptUsername(context.Context, keybase1.PromptUsernameArg) (string, error)
OutputPrechecks(context.Context, keybase1.OutputPrechecksArg) error
PreProofWarning(context.Context, keybase1.PreProofWarningArg) (bool, error)
OutputInstructions(context.Context, keybase1.OutputInstructionsArg) error
OkToCheck(context.Context, keybase1.OkToCheckArg) (bool, error)
DisplayRecheckWarning(context.Context, keybase1.DisplayRecheckWarningArg) error
}
type SecretUI interface {
GetSecret(pinentry keybase1.SecretEntryArg, terminal *keybase1.SecretEntryArg) (*keybase1.SecretEntryRes, error)
GetNewPassphrase(keybase1.GetNewPassphraseArg) (keybase1.GetPassphraseRes, error)
GetKeybasePassphrase(keybase1.GetKeybasePassphraseArg) (keybase1.GetPassphraseRes, error)
GetPaperKeyPassphrase(keybase1.GetPaperKeyPassphraseArg) (string, error)
GetPassphrase(pinentry keybase1.GUIEntryArg, terminal *keybase1.SecretEntryArg) (keybase1.GetPassphraseRes, error)
}
type LogUI interface {
Debug(format string, args ...interface{})
Info(format string, args ...interface{})
Warning(format string, args ...interface{})
Notice(format string, args ...interface{})
Errorf(format string, args ...interface{})
Critical(format string, args ...interface{})
}
type GPGUI interface {
keybase1.GpgUiInterface
}
type ProvisionUI interface {
keybase1.ProvisionUiInterface
}
type PromptDefault int
const (
PromptDefaultNo PromptDefault = iota
PromptDefaultYes
PromptDefaultNeither
)
type PromptDescriptor int
type TerminalUI interface {
OutputWriter() io.Writer
Output(string) error
Printf(fmt string, args ...interface{}) (int, error)
PromptYesNo(PromptDescriptor, string, PromptDefault) (bool, error)
Prompt(PromptDescriptor, string) (string, error)
PromptPassword(PromptDescriptor, string) (string, error)
PromptForConfirmation(prompt string) error
}
type DumbOutputUI interface {
Printf(fmt string, args ...interface{}) (int, error)
PrintfStderr(fmt string, args ...interface{}) (int, error)
}
type UI interface {
GetIdentifyUI() IdentifyUI
GetIdentifyTrackUI(strict bool) IdentifyUI
GetLoginUI() LoginUI
GetSecretUI() SecretUI
GetTerminalUI() TerminalUI
GetDumbOutputUI() DumbOutputUI
GetProveUI() ProveUI
GetLogUI() LogUI
GetGPGUI() GPGUI
GetProvisionUI(role KexRole) ProvisionUI
Configure() error
Shutdown() error
}
type UIRouter interface {
SetUI(ConnectionID, UIKind)
GetIdentifyUI() (IdentifyUI, error)
GetSecretUI() (SecretUI, error)
Shutdown()
}
type UIConsumer interface {
Name() string
RequiredUIs() []UIKind
SubConsumers() []UIConsumer
}