-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit.go
82 lines (70 loc) · 1.84 KB
/
audit.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
package qnp
import (
"bytes"
"encoding/csv"
"io"
"time"
"github.com/gocarina/gocsv"
"github.com/soderasen-au/go-common/util"
)
type (
AuditLogTimeStamp struct {
time.Time
}
AuditLogRecord struct {
EventTime AuditLogTimeStamp
Source string
Event string
Target string
TargetId string
TargetName string
Action string
AppId string
UserId string
UserName string
IpAddress string
Description string
Data string
DataType string
}
NewsstandReportData struct {
Title string `json:"title,omitempty"`
Format string `json:"format,omitempty"`
TaskId string `json:"taskId,omitempty"`
FileSize int64 `json:"fileSize,omitempty"`
Published string `json:"published,omitempty"`
ExecutionId string `json:"executionId,omitempty"`
RecipientId string `json:"recipientId,omitempty"`
RecipientDomainAccount string `json:"recipientDomainAccount,omitempty"`
}
)
func (date *AuditLogTimeStamp) UnmarshalCSV(csv string) (err error) {
date.Time, err = time.Parse(time.RFC3339Nano, csv)
return err
}
func (c *Client) GetAuditLogs() ([]byte, *util.Result) {
data, res := c.Get("/audit/logs", nil)
if res != nil {
return nil, res.With("Get")
}
return data, nil
}
func (c *Client) GetAuditLogRecords() ([]AuditLogRecord, *util.Result) {
data, res := c.GetAuditLogs()
if res != nil {
return nil, res.With("GetAuditLogs")
}
data = bytes.TrimLeft(data, "\xef\xbb\xbf")
gocsv.SetCSVReader(func(in io.Reader) gocsv.CSVReader {
r := csv.NewReader(in)
r.Comma = '\t'
r.LazyQuotes = true
return r
})
var auditRecords []AuditLogRecord
err := gocsv.UnmarshalBytes(data, &auditRecords)
if err != nil {
return nil, util.Error("ParseAuditLog", err)
}
return auditRecords, nil
}