-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
313 lines (306 loc) · 7.85 KB
/
main.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
package main
import (
"github.com/gtfierro/pundat/version"
"github.com/op/go-logging"
"github.com/urfave/cli"
"os"
)
// logger
var log *logging.Logger
func init() {
log = logging.MustGetLogger("pundat")
var format = "%{color}%{level} %{shortfile} %{time:Jan 02 15:04:05} %{color:reset} ▶ %{message}"
var logBackend = logging.NewLogBackend(os.Stderr, "", 0)
logBackendLeveled := logging.AddModuleLevel(logBackend)
logging.SetBackend(logBackendLeveled)
logging.SetFormatter(logging.MustStringFormatter(format))
}
func main() {
app := cli.NewApp()
app.Name = "pundat"
app.Usage = "Archiver and data access tools for BOSSWAVE and BTrDB"
app.Version = version.Release
app.Commands = []cli.Command{
{
Name: "archiver",
Usage: "Start the archiver",
Action: startArchiver,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config,c",
Usage: "Configuration file",
},
},
},
{
Name: "mkconfig",
Usage: "Creates a config file pundat-default.ini (default) in the current directory",
Action: makeConfig,
Flags: []cli.Flag{
cli.StringFlag{
Name: "file,f",
Usage: "Name of the config file",
},
},
},
{
Name: "query",
Usage: "Evaluate query interactively",
Action: doIQuery,
Flags: []cli.Flag{
cli.StringFlag{
Name: "agent,a",
Value: "127.0.0.1:28589",
Usage: "Local BOSSWAVE Agent",
EnvVar: "BW2_AGENT",
},
cli.StringFlag{
Name: "entity,e",
Value: "",
Usage: "The entity to use",
EnvVar: "BW2_DEFAULT_ENTITY",
},
cli.BoolTFlag{
Name: "formattime,f",
Usage: "If true, parse the timestamps in returned responses",
},
cli.StringFlag{
Name: "query,q",
Value: "",
Usage: "If specified, evaluate this query and print the results on stdout. If not specified, use the interactive query",
},
cli.IntFlag{
Name: "timeout,t",
Value: 30,
Usage: "Timeout in seconds to wait for a reply from the archiver",
},
},
},
{
Name: "scan",
Usage: "Find archivers from some base uri",
Action: doScan,
Flags: []cli.Flag{
cli.StringFlag{
Name: "agent,a",
Value: "127.0.0.1:28589",
Usage: "Local BOSSWAVE Agent",
EnvVar: "BW2_AGENT",
},
cli.StringFlag{
Name: "entity,e",
Value: "",
Usage: "The entity to use",
EnvVar: "BW2_DEFAULT_ENTITY",
},
},
},
{
Name: "check",
Usage: "Check access to an archiver on behalf of some key",
Action: doCheck,
Flags: []cli.Flag{
cli.StringFlag{
Name: "agent,a",
Value: "127.0.0.1:28589",
Usage: "Local BOSSWAVE Agent",
EnvVar: "BW2_AGENT",
},
cli.StringFlag{
Name: "entity,e",
Value: "",
Usage: "The entity to use",
EnvVar: "BW2_DEFAULT_ENTITY",
},
cli.StringFlag{
Name: "key, k",
Usage: "The key or alias to check",
},
cli.StringFlag{
Name: "uri, u",
Usage: "The base URI of the archiver",
},
},
},
{
Name: "grant",
Usage: "Grant access to an archiver to some key",
Action: doGrant,
Flags: []cli.Flag{
cli.StringFlag{
Name: "agent,a",
Value: "127.0.0.1:28589",
Usage: "Local BOSSWAVE Agent",
EnvVar: "BW2_AGENT",
},
cli.StringFlag{
Name: "entity,e",
Value: "",
Usage: "The entity to use",
EnvVar: "BW2_DEFAULT_ENTITY",
},
cli.StringFlag{
Name: "bankroll, b",
Value: "",
Usage: "The entity to use for bankrolling",
EnvVar: "BW2_DEFAULT_BANKROLL",
},
cli.StringFlag{
Name: "expiry",
Usage: "Set the expiry on access to archiver measured from now e.g. 3d7h20m",
},
cli.StringFlag{
Name: "key, k",
Usage: "The key or alias to check",
},
cli.StringFlag{
Name: "uri, u",
Usage: "The base URI of the archiver",
},
},
},
{
Name: "range",
Usage: "Check valid ranges of access to a URI of data on behalf of some key",
Action: doRange,
Flags: []cli.Flag{
cli.StringFlag{
Name: "agent,a",
Value: "127.0.0.1:28589",
Usage: "Local BOSSWAVE Agent",
EnvVar: "BW2_AGENT",
},
cli.StringFlag{
Name: "entity,e",
Value: "",
Usage: "The entity to use",
EnvVar: "BW2_DEFAULT_ENTITY",
},
cli.StringFlag{
Name: "key, k",
Usage: "The key or alias to check",
EnvVar: "BW2_DEFAULT_ENTITY",
},
cli.StringFlag{
Name: "uri, u",
Usage: "The URI we want to check ranges to",
},
},
},
// archive request commands
{
Name: "listreq",
Usage: "List all archive requests persisted on the given URI pattern (docs: https://git.io/vDjmW)",
Action: listArchiveRequests,
Flags: []cli.Flag{
cli.StringFlag{
Name: "agent,a",
Value: "127.0.0.1:28589",
Usage: "Local BOSSWAVE Agent",
EnvVar: "BW2_AGENT",
},
cli.StringFlag{
Name: "entity,e",
Value: "",
Usage: "The entity to use",
EnvVar: "BW2_DEFAULT_ENTITY",
},
},
},
{
Name: "rmreq",
Usage: "Remove archive requests specified by file (docs: https://git.io/vDjmW)",
Action: rmConfig,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config,c",
Usage: "Archive request YAML file",
},
cli.StringFlag{
Name: "agent,a",
Value: "127.0.0.1:28589",
Usage: "Local BOSSWAVE Agent",
EnvVar: "BW2_AGENT",
},
cli.StringFlag{
Name: "entity,e",
Value: "",
Usage: "The entity to use",
EnvVar: "BW2_DEFAULT_ENTITY",
},
},
},
{
Name: "addreq",
Usage: "Load archive requests from config file (docs: https://git.io/vDjmW)",
Action: addConfig,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config,c",
Value: "archive.yml",
Usage: "Config file to parse for archive requests",
},
cli.StringFlag{
Name: "agent,a",
Value: "127.0.0.1:28589",
Usage: "Local BOSSWAVE Agent",
EnvVar: "BW2_AGENT",
},
cli.StringFlag{
Name: "entity,e",
EnvVar: "BW2_DEFAULT_ENTITY",
Usage: "The entity to use",
},
},
},
{
Name: "nukereq",
Usage: "Remove ALL archive requests attached at the given URI (docs: https://git.io/vDjmW)",
Action: nukeArchiveRequests,
Flags: []cli.Flag{
cli.StringFlag{
Name: "agent,a",
Value: "127.0.0.1:28589",
Usage: "Local BOSSWAVE Agent",
EnvVar: "BW2_AGENT",
},
cli.StringFlag{
Name: "entity,e",
Value: "",
Usage: "The entity to use",
EnvVar: "BW2_DEFAULT_ENTITY",
},
},
},
{
Name: "gettime",
Usage: "Convert a time expression into a Unix nano timestamp. No arguments => returns current time",
Action: doTime,
},
}
app.Run(os.Args)
}
/*
NOTES:
- query language parsing has been ported over
- first challenge is to get metadata queries working
Questions:
1. Do we save the whole timeseries of metadata records?
- if we only associate the most recent metadata record w/ a timeseries,
then someone who *could* query in the past might not be able to if the md tag
is deleted, but they may have lost permission before the tag was deleted. Now,
they know that the tag no longer applies to the stream.
- the solution here is likely to have the full record of all metadata values,
then build a DOT to ALL of them and filter the list of the most recent unique
(key, srcuri) pairs. this is the "view" of metadata as they are allowed to see it
- TODO: really want to create some sort of model or formalism or notes of how
metadata and permissions and time all play together. What are all the edge cases of
this? We want to plan for those
TODO:
- finish implementing metadata store:
- involves BASIC benchmarks
- implement the DOT stuff
- test the DOT stuff
- port over the archiver query interface:
- the archiver API used by the language
*/