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
|
package slack
import (
"context"
"net/url"
"strconv"
)
type AuditLogResponse struct {
Entries []AuditEntry `json:"entries"`
SlackResponse
}
type AuditEntry struct {
ID string `json:"id"`
DateCreate int `json:"date_create"`
Action string `json:"action"`
Actor struct {
Type string `json:"type"`
User AuditUser `json:"user"`
} `json:"actor"`
Entity struct {
Type string `json:"type"`
// Only one of the below will be completed, based on the value of Type a user, a channel, a file, an app, a workspace, or an enterprise
User AuditUser `json:"user"`
Channel AuditChannel `json:"channel"`
File AuditFile `json:"file"`
App AuditApp `json:"app"`
Workspace AuditWorkspace `json:"workspace"`
Enterprise AuditEnterprise `json:"enterprise"`
} `json:"entity"`
Context struct {
Location struct {
Type string `json:"type"`
ID string `json:"id"`
Name string `json:"name"`
Domain string `json:"domain"`
} `json:"location"`
UA string `json:"ua"`
IPAddress string `json:"ip_address"`
} `json:"context"`
Details struct {
NewValue interface{} `json:"new_value"`
PreviousValue interface{} `json:"previous_value"`
MobileOnly bool `json:"mobile_only"`
WebOnly bool `json:"web_only"`
NonSSOOnly bool `json:"non_sso_only"`
ExportType string `json:"export_type"`
ExportStart string `json:"export_start_ts"`
ExportEnd string `json:"export_end_ts"`
} `json:"details"`
}
type AuditUser struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Team string `json:"team"`
}
type AuditChannel struct {
ID string `json:"id"`
Name string `json:"name"`
Privacy string `json:"privacy"`
IsShared bool `json:"is_shared"`
IsOrgShared bool `json:"is_org_shared"`
}
type AuditFile struct {
ID string `json:"id"`
Name string `json:"name"`
Filetype string `json:"filetype"`
Title string `json:"title"`
}
type AuditApp struct {
ID string `json:"id"`
Name string `json:"name"`
IsDistributed bool `json:"is_distributed"`
IsDirectoryApproved bool `json:"is_directory_approved"`
IsWorkflowApp bool `json:"is_workflow_app"`
Scopes []string `json:"scopes"`
}
type AuditWorkspace struct {
ID string `json:"id"`
Name string `json:"name"`
Domain string `json:"domain"`
}
type AuditEnterprise struct {
ID string `json:"id"`
Name string `json:"name"`
Domain string `json:"domain"`
}
// AuditLogParameters contains all the parameters necessary (including the optional ones) for a GetAuditLogs() request
type AuditLogParameters struct {
Limit int
Cursor string
Latest int
Oldest int
Action string
Actor string
Entity string
}
func (api *Client) auditLogsRequest(ctx context.Context, path string, values url.Values) (*AuditLogResponse, error) {
response := &AuditLogResponse{}
err := api.getMethod(ctx, path, api.token, values, response)
if err != nil {
return nil, err
}
return response, response.Err()
}
// GetAuditLogs retrieves a page of audit entires according to the parameters given
func (api *Client) GetAuditLogs(params AuditLogParameters) (entries []AuditEntry, nextCursor string, err error) {
return api.GetAuditLogsContext(context.Background(), params)
}
// GetAuditLogsContext retrieves a page of audit entries according to the parameters given with a custom context
func (api *Client) GetAuditLogsContext(ctx context.Context, params AuditLogParameters) (entries []AuditEntry, nextCursor string, err error) {
values := url.Values{}
if params.Limit != 0 {
values.Add("limit", strconv.Itoa(params.Limit))
}
if params.Oldest != 0 {
values.Add("oldest", strconv.Itoa(params.Oldest))
}
if params.Latest != 0 {
values.Add("latest", strconv.Itoa(params.Latest))
}
if params.Cursor != "" {
values.Add("cursor", params.Cursor)
}
if params.Action != "" {
values.Add("action", params.Action)
}
if params.Actor != "" {
values.Add("actor", params.Actor)
}
if params.Entity != "" {
values.Add("entity", params.Entity)
}
response, err := api.auditLogsRequest(ctx, "audit/v1/logs", values)
if err != nil {
return nil, "", err
}
return response.Entries, response.ResponseMetadata.Cursor, response.Err()
}
|