-
Notifications
You must be signed in to change notification settings - Fork 0
/
readtenantactivity.go
74 lines (66 loc) · 2.2 KB
/
readtenantactivity.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
package veracity
import (
"bufio"
"bytes"
"encoding/json"
"os"
"path/filepath"
)
// TenantMassif identifies a combination of tenant and massif Typically it is
// used to convey that the massif is the most recently changed for that tenant.
// Note: it is a strict subset of the fields in TenantActivity, maintained seperately due to json marshalling
type TenantMassif struct {
// Massif is the massif index of the most recently appended massif
Massif int `json:"massifindex"`
// Tenant is the tenant identity of the most recently changed log
Tenant string `json:"tenant"`
}
// TenantActivity represents the per tenant output of the watch command
type TenantActivity struct {
// Massif is the massif index of the most recently appended massif
Massif int `json:"massifindex"`
// Tenant is the tenant identity of the most recently changed log
Tenant string `json:"tenant"`
// IDCommitted is the idtimestamp for the most recent entry observed in the log
IDCommitted string `json:"idcommitted"`
// IDConfirmed is the idtimestamp for the most recent entry to be sealed.
IDConfirmed string `json:"idconfirmed"`
LastModified string `json:"lastmodified"`
// MassifURL is the remote path to the most recently changed massif
MassifURL string `json:"massif"`
// SealURL is the remote path to the most recently changed seal
SealURL string `json:"seal"`
}
func filePathToTenantMassifs(filePath string) ([]TenantMassif, error) {
filePath, err := filepath.Abs(filePath)
if err != nil {
return nil, err
}
f, err := os.Open(filePath)
if err != nil {
return nil, err
}
return scannerToTenantMassifs(bufio.NewScanner(f))
}
func stdinToDecodedTenantMassifs() ([]TenantMassif, error) {
return scannerToTenantMassifs(bufio.NewScanner(os.Stdin))
}
func scannerToTenantMassifs(scanner *bufio.Scanner) ([]TenantMassif, error) {
var data []byte
for scanner.Scan() {
data = append(data, scanner.Bytes()...)
}
if err := scanner.Err(); err != nil {
return nil, err
}
return TenantMassifsFromData(data)
}
func TenantMassifsFromData(data []byte) ([]TenantMassif, error) {
decoder := json.NewDecoder(bytes.NewReader(data))
var doc []TenantMassif
err := decoder.Decode(&doc)
if err == nil {
return doc, nil
}
return nil, err
}