-
Notifications
You must be signed in to change notification settings - Fork 39
/
types.go
550 lines (475 loc) · 14.3 KB
/
types.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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
package common
import (
"time"
)
// AccessType is whether a database is private, or public, or both
type AccessType int
const (
DB_BOTH AccessType = iota
DB_PRIVATE
DB_PUBLIC
)
type ActivityRange string
const (
TODAY ActivityRange = "today"
THIS_WEEK = "week"
THIS_MONTH = "month"
ALL_TIME = "all"
)
type ForkType int
const (
SPACE ForkType = iota
ROOT
STEM
BRANCH
END
)
// ValType indicates the type of data in a field returned from a SQLite query
type ValType int
const (
Binary ValType = iota
Image
Null
Text
Integer
Float
)
// DefaultNumDisplayRows is the number of rows to display by default on the database page
const DefaultNumDisplayRows = 25
// MaxDatabaseSize is the maximum database size accepted for upload (in MB)
const MaxDatabaseSize = 512
// MaxLicenceSize is the maximum licence size accepted for upload (in MB)
const MaxLicenceSize = 1
// MinioFolderChars is the number of leading characters of a files' sha256 used as the Minio folder name
// eg: When set to 6, then "34f4255a737156147fbd0a44323a895d18ade79d4db521564d1b0dbb8764cbbc"
// -> Minio folder: "34f425"
// -> Minio filename: "5a737156147fbd0a44323a895d18ade79d4db521564d1b0dbb8764cbbc"
const MinioFolderChars = 6
// QuerySource is used internally to help choose the output format from a SQL query
type QuerySource int
const (
WebUI QuerySource = iota
DB4S
Visualisation
API
Internal
)
// ************************
// Configuration file types
// TomlConfig is a top level structure containing the server configuration info
type TomlConfig struct {
Api ApiInfo
Auth0 Auth0Info
DB4S DB4SInfo
Environment EnvInfo
DiskCache DiskCacheInfo
Event EventProcessingInfo
Licence LicenceInfo
Memcache MemcacheInfo
Minio MinioInfo
Pg PGInfo
Sign SigningInfo
Web WebInfo
}
// ApiInfo contains configuration info for the API daemon
type ApiInfo struct {
BaseDir string `toml:"base_dir"`
BindAddress string `toml:"bind_address"`
Certificate string `toml:"certificate"`
CertificateKey string `toml:"certificate_key"`
RequestLog string `toml:"request_log"`
ServerName string `toml:"server_name"`
}
// Auth0Info contains the Auth0 connection info used authenticating webUI users
type Auth0Info struct {
ClientID string
ClientSecret string
Domain string
}
// DB4SInfo contains configuration info for the DB4S end point daemon
type DB4SInfo struct {
CAChain string `toml:"ca_chain"`
Certificate string
CertificateKey string `toml:"certificate_key"`
Debug bool
Port int
Server string
}
// DiskCacheInfo contains the path to the root of the local disk cache
type DiskCacheInfo struct {
Directory string
}
// EnvInfo holds information about the purpose of the running server. eg "is this a production, docker,
// or development" instance?
type EnvInfo struct {
Environment string
UserOverride string `toml:"user_override"`
}
// EventProcessingInfo hold configuration for the event processing loop
type EventProcessingInfo struct {
Delay time.Duration `toml:"delay"`
EmailQueueDir string `toml:"email_queue_dir"`
EmailQueueProcessingDelay time.Duration `toml:"email_queue_processing_delay"`
}
// LicenceDir holds the path to the licence files
type LicenceInfo struct {
LicenceDir string `toml:"licence_dir"`
}
// MemcacheInfo contains the Memcached configuration parameters
type MemcacheInfo struct {
DefaultCacheTime int `toml:"default_cache_time"`
Server string `toml:"server"`
ViewCountFlushDelay time.Duration `toml:"view_count_flush_delay"`
}
// MinioInfo contains the Minio connection parameters
type MinioInfo struct {
AccessKey string `toml:"access_key"`
HTTPS bool
Secret string
Server string
}
// PGInfo contains the PostgreSQL connection parameters
type PGInfo struct {
Database string
NumConnections int `toml:"num_connections"`
Port int
Password string
Server string
SSL bool
Username string
}
// SigningInfo contains the info used for signing DB4S client certificates
type SigningInfo struct {
CertDaysValid int `toml:"cert_days_valid"`
Enabled bool `toml:"enabled"`
IntermediateCert string `toml:"intermediate_cert"`
IntermediateKey string `toml:"intermediate_key"`
}
// WebInfo contains configuration info for the webUI daemon
type WebInfo struct {
BaseDir string `toml:"base_dir"`
BindAddress string `toml:"bind_address"`
Certificate string `toml:"certificate"`
CertificateKey string `toml:"certificate_key"`
RequestLog string `toml:"request_log"`
ServerName string `toml:"server_name"`
SessionStorePassword string `toml:"session_store_password"`
}
// End of configuration file types
// *******************************
type ActivityRow struct {
Count int `json:"count"`
DBName string `json:"dbname"`
Owner string `json:"owner"`
}
type ActivityStats struct {
Downloads []ActivityRow
Forked []ActivityRow
Starred []ActivityRow
Uploads []UploadRow
Viewed []ActivityRow
}
// APIJSONColumn is a copy of the Column type from github.com/gwenn/gosqlite, but including JSON field name info
type APIJSONColumn struct {
Cid int `json:"column_id"`
Name string `json:"name"`
DataType string `json:"data_type"`
NotNull bool `json:"not_null"`
DfltValue string `json:"default_value"`
Pk int `json:"primary_key"`
Autoinc bool `json:"autoinc"`
CollSeq string `json:"collation_seq"`
}
// APIKey is an internal structure used for passing around user API keys
type APIKey struct {
Key string `json:"key"`
DateCreated time.Time `json:"date_created"`
}
type Auth0Set struct {
CallbackURL string
ClientID string
Domain string
}
type BranchEntry struct {
Commit string `json:"commit"`
CommitCount int `json:"commit_count"`
Description string `json:"description"`
}
type CommitData struct {
AuthorAvatar string `json:"author_avatar"`
AuthorEmail string `json:"author_email"`
AuthorName string `json:"author_name"`
AuthorUsername string `json:"author_username"`
ID string `json:"id"`
LicenceChange string `json:"licence_change"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
}
type CommitEntry struct {
AuthorEmail string `json:"author_email"`
AuthorName string `json:"author_name"`
CommitterEmail string `json:"committer_email"`
CommitterName string `json:"committer_name"`
ID string `json:"id"`
Message string `json:"message"`
OtherParents []string `json:"other_parents"`
Parent string `json:"parent"`
Timestamp time.Time `json:"timestamp"`
Tree DBTree `json:"tree"`
}
type DataValue struct {
Name string
Type ValType
Value interface{}
}
type DataRow []DataValue
type DBEntry struct {
Folder string
DateEntry time.Time
DBName string
Owner string
OwnerDisplayName string `json:"display_name"`
}
type DBTreeEntryType string
const (
TREE DBTreeEntryType = "tree"
DATABASE = "db"
LICENCE = "licence"
)
type DBTree struct {
ID string `json:"id"`
Entries []DBTreeEntry `json:"entries"`
}
type DBTreeEntry struct {
EntryType DBTreeEntryType `json:"entry_type"`
LastModified time.Time `json:"last_modified"`
LicenceSHA string `json:"licence"`
Name string `json:"name"`
Sha256 string `json:"sha256"`
Size int64 `json:"size"`
}
type DBInfo struct {
Branch string
Branches int
BranchList []string
Commits int
CommitID string
Contributors int
Database string
DateCreated time.Time
DBEntry DBTreeEntry
DefaultBranch string
DefaultTable string
Discussions int
Downloads int
Folder string
Forks int
FullDesc string
LastModified time.Time
Licence string
LicenceURL string
MRs int
OneLineDesc string
Public bool
RepoModified time.Time
Releases int
SHA256 string
Size int64
SourceURL string
Stars int
Tables []string
Tags int
Views int
Watchers int
}
type DiscussionCommentType string
const (
TEXT DiscussionCommentType = "txt"
CLOSE = "cls"
REOPEN = "rop"
)
type DiscussionCommentEntry struct {
AvatarURL string `json:"avatar_url"`
Body string `json:"body"`
BodyRendered string `json:"body_rendered"`
Commenter string `json:"commenter"`
DateCreated time.Time `json:"creation_date"`
EntryType DiscussionCommentType `json:"entry_type"`
ID int `json:"com_id"`
}
type DiscussionType int
const (
DISCUSSION DiscussionType = 0 // These are not iota, as it would be seriously bad for these numbers to change
MERGE_REQUEST = 1
)
type DiscussionEntry struct {
AvatarURL string `json:"avatar_url"`
Body string `json:"body"`
BodyRendered string `json:"body_rendered"`
CommentCount int `json:"comment_count"`
Creator string `json:"creator"`
DateCreated time.Time `json:"creation_date"`
ID int `json:"disc_id"`
LastModified time.Time `json:"last_modified"`
MRDetails MergeRequestEntry `json:"mr_details"`
Open bool `json:"open"`
Title string `json:"title"`
Type DiscussionType `json:"discussion_type"`
}
type EventDetails struct {
DBName string `json:"database_name"`
DiscID int `json:"discussion_id"`
Folder string `json:"database_folder"`
ID string `json:"event_id"`
Message string `json:"message"`
Owner string `json:"database_owner"`
Timestamp time.Time `json:"event_timestamp"`
Title string `json:"title"`
Type EventType `json:"event_type"`
URL string `json:"event_url"`
UserName string `json:"username"`
}
type EventType int
const (
EVENT_NEW_DISCUSSION EventType = 0 // These are not iota, as it would be seriously bad for these numbers to change
EVENT_NEW_MERGE_REQUEST = 1
EVENT_NEW_COMMENT = 2
EVENT_NEW_RELEASE = 3
)
type ForkEntry struct {
DBName string `json:"database_name"`
Folder string `json:"database_folder"`
ForkedFrom int `json:"forked_from"`
IconList []ForkType `json:"icon_list"`
ID int `json:"id"`
Owner string `json:"database_owner"`
Processed bool `json:"processed"`
Public bool `json:"public"`
Deleted bool `json:"deleted"`
}
type JsonError struct {
Error string `json:"error"`
}
type LicenceEntry struct {
FileFormat string `json:"file_format"`
FullName string `json:"full_name"`
Order int `json:"order"`
Sha256 string `json:"sha256"`
URL string `json:"url"`
}
type MergeRequestState int
const (
OPEN MergeRequestState = 0 // These are not iota, as it would be seriously bad for these numbers to change
CLOSED_WITH_MERGE = 1
CLOSED_WITHOUT_MERGE = 2
)
type MergeRequestEntry struct {
Commits []CommitEntry `json:"commits"`
DestBranch string `json:"destination_branch"`
SourceBranch string `json:"source_branch"`
SourceDBID int64 `json:"source_database_id"`
SourceDBName string `json:"source_database_name"`
SourceFolder string `json:"source_folder"`
SourceOwner string `json:"source_owner"`
State MergeRequestState `json:"state"`
}
type MetaInfo struct {
AvatarURL string
Database string
ForkDatabase string
ForkDeleted bool
ForkFolder string
ForkOwner string
LoggedInUser string
NumStatusUpdates int
Owner string
Protocol string
Server string
Title string
}
type ReleaseEntry struct {
Commit string `json:"commit"`
Date time.Time `json:"date"`
Description string `json:"description"`
ReleaserEmail string `json:"email"`
ReleaserName string `json:"name"`
Size int64 `json:"size"`
}
type SQLiteDBinfo struct {
Info DBInfo
MaxRows int
MinioBkt string
MinioId string
}
type SQLiteRecordSet struct {
ColCount int
ColNames []string
Offset int
Records []DataRow
RowCount int
SortCol string
SortDir string
Tablename string
TotalRows int
}
type StatusUpdateEntry struct {
DiscID int `json:"discussion_id"`
Title string `json:"title"`
URL string `json:"event_url"`
}
type TagEntry struct {
Commit string `json:"commit"`
Date time.Time `json:"date"`
Description string `json:"description"`
TaggerEmail string `json:"email"`
TaggerName string `json:"name"`
}
type UploadRow struct {
DBName string `json:"dbname"`
Owner string `json:"owner"`
UploadDate time.Time `json:"upload_date"`
}
// UserInfoSlice is used for sorting a UserInfo list by Last Modified date descending
type UserInfoSlice []UserInfo
func (u UserInfoSlice) Len() int {
return len(u)
}
func (u UserInfoSlice) Less(i, j int) bool {
return u[i].LastModified.After(u[j].LastModified) // Swap to Before() for an ascending list
}
func (u UserInfoSlice) Swap(i, j int) {
u[i], u[j] = u[j], u[i]
}
type UserDetails struct {
AvatarURL string
ClientCert []byte
DateJoined time.Time
DisplayName string
Email string
Password string
PHash []byte
PVerify string
Username string
}
type UserInfo struct {
FullName string `json:"full_name"`
LastModified time.Time
Username string
}
type VisParamsV2 struct {
ChartType string `json:"chart_type"`
ShowXLabel bool `json:"show_x_label"`
ShowYLabel bool `json:"show_y_label"`
SQL string `json:"sql"`
XAXisColumn string `json:"x_axis_label"`
YAXisColumn string `json:"y_axis_label"`
}
type VisRowV1 struct {
Name string
Value int
}
type WhereClause struct {
Column string
Type string
Value string
}