-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathaudit_logs.go
70 lines (61 loc) · 1.75 KB
/
audit_logs.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
package stream
import (
"context"
"encoding/json"
"time"
)
type AuditLogsClient struct {
client *Client
}
type AuditLog struct {
EntityType string `json:"entity_type"`
EntityID string `json:"entity_id"`
Action string `json:"action"`
UserID string `json:"user_id"`
Custom map[string]any `json:"custom"`
CreatedAt time.Time `json:"created_at"`
}
type QueryAuditLogsResponse struct {
AuditLogs []AuditLog `json:"audit_logs"`
Next string `json:"next"`
Prev string `json:"prev"`
response
}
type QueryAuditLogsFilters struct {
EntityType string
EntityID string
UserID string
}
type QueryAuditLogsPager struct {
Next string
Prev string
Limit int
}
func (c *AuditLogsClient) QueryAuditLogs(ctx context.Context, filters QueryAuditLogsFilters, pager QueryAuditLogsPager) (*QueryAuditLogsResponse, error) {
endpoint := c.client.makeEndpoint("audit_logs/")
if filters.EntityType != "" && filters.EntityID != "" {
endpoint.addQueryParam(makeRequestOption("entity_type", filters.EntityType))
endpoint.addQueryParam(makeRequestOption("entity_id", filters.EntityID))
}
if filters.UserID != "" {
endpoint.addQueryParam(makeRequestOption("user_id", filters.UserID))
}
if pager.Next != "" {
endpoint.addQueryParam(makeRequestOption("next", pager.Next))
}
if pager.Prev != "" {
endpoint.addQueryParam(makeRequestOption("prev", pager.Prev))
}
if pager.Limit > 0 {
endpoint.addQueryParam(makeRequestOption("limit", pager.Limit))
}
body, err := c.client.get(ctx, endpoint, nil, c.client.authenticator.auditLogsAuth)
if err != nil {
return nil, err
}
var resp QueryAuditLogsResponse
if err := json.Unmarshal(body, &resp); err != nil {
return nil, err
}
return &resp, nil
}