-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathlog.go
215 lines (179 loc) · 6.55 KB
/
log.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
package management
import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
)
var logTypeName = map[string]string{
"s": "Success Login",
"ssa": "Success Silent Auth",
"fsa": "Failed Silent Auth",
"seacft": "Success Exchange (Authorization Code for Access Token)",
"feacft": "Failed Exchange (Authorization Code for Access Token)",
"seccft": "Success Exchange (Client Credentials for Access Token)",
"feccft": "Failed Exchange (Client Credentials for Access Token)",
"sepft": "Success Exchange (Password for Access Token)",
"fepft": "Failed Exchange (Password for Access Token)",
"f": "Failed Login",
"w": "Warnings During Login",
"du": "Deleted User",
"fu": "Failed Login (invalid email/username)",
"fp": "Failed Login (wrong password)",
"fc": "Failed by Connector",
"fco": "Failed by CORS",
"con": "Connector Online",
"coff": "Connector Offline",
"fcpro": "Failed Connector Provisioning",
"ss": "Success Signup",
"fs": "Failed Signup",
"cs": "Code Sent",
"cls": "Code/Link Sent",
"sv": "Success Verification Email",
"fv": "Failed Verification Email",
"scp": "Success Change Password",
"fcp": "Failed Change Password",
"sce": "Success Change Email",
"fce": "Failed Change Email",
"scu": "Success Change Username",
"fcu": "Failed Change Username",
"scpn": "Success Change Phone Number",
"fcpn": "Failed Change Phone Number",
"svr": "Success Verification Email Request",
"fvr": "Failed Verification Email Request",
"scpr": "Success Change Password Request",
"fcpr": "Failed Change Password Request",
"fn": "Failed Sending Notification",
"sapi": "API Operation",
"fapi": "Failed API Operation",
"limit_wc": "Blocked Account",
"limit_mu": "Blocked IP Address",
"limit_ui": "Too Many Calls to /userinfo",
"api_limit": "Rate Limit On API",
"sdu": "Successful User Deletion",
"fdu": "Failed User Deletion",
"slo": "Success Logout",
"flo": "Failed Logout",
"sd": "Success Delegation",
"fd": "Failed Delegation",
"fcoa": "Failed Cross Origin Authentication",
"scoa": "Success Cross Origin Authentication",
}
// Log for analyzing business needs.
//
// See: https://auth0.com/docs/deploy-monitor/logs
type Log struct {
ID *string `json:"_id"`
// Unique ID of the log event.
LogID *string `json:"log_id"`
// The date when the log event was created.
Date *time.Time `json:"date"`
// The log event type.
Type *string `json:"type"`
// The log event description.
Description *string `json:"description"`
// Name of the connection the log event relates to.
Connection *string `json:"connection"`
// ID of the connection the log event relates to.
ConnectionID *string `json:"connection_id"`
// ID of the organization the log event relates to.
OrganizationID *string `json:"organization_id"`
// Name of the organization the log event relates to.
OrganizationName *string `json:"organization_name"`
// The ID of the client (application).
ClientID *string `json:"client_id"`
// The name of the client (application).
ClientName *string `json:"client_name"`
// The IP address of the log event source.
IP *string `json:"ip"`
// Hostname the log event applies to.
Hostname *string `json:"hostname"`
// Additional useful details about this event (structure is dependent upon event type).
Details map[string]interface{} `json:"details"`
// ID of the user involved in the log event.
UserID *string `json:"user_id"`
// Name of the user involved in the log event.
UserName *string `json:"user_name"`
// User agent string from the client device that caused the event.
UserAgent *string `json:"user_agent"`
// API audience the event applies to.
Audience *string `json:"audience"`
// Scope permissions applied to the event.
Scope *string `json:"-"`
// Name of the strategy involved in the event.
Strategy *string `json:"strategy"`
// Type of strategy involved in the event.
StrategyType *string `json:"strategy_type"`
// Whether the client was a mobile device (true) or desktop/laptop/server (false).
IsMobile *bool `json:"isMobile"`
// Information about the location that triggered this event based on the `ip`.
LocationInfo map[string]interface{} `json:"location_info"`
}
// TypeName returns the type name of an Event Log.
func (l *Log) TypeName() string {
if l.Type == nil {
return ""
}
if name, ok := logTypeName[*l.Type]; ok {
return name
}
return ""
}
// UnmarshalJSON is a custom deserializer for the Log type.
//
// It is required due to differences in the scope field which cane be a string or array of strings.
func (l *Log) UnmarshalJSON(data []byte) error {
type log Log
type logWrapper struct {
*log
RawScope interface{} `json:"scope"`
}
alias := &logWrapper{(*log)(l), nil}
err := json.Unmarshal(data, alias)
if err != nil {
return err
}
if alias.RawScope != nil {
switch rawScope := alias.RawScope.(type) {
case []interface{}:
scopes := make([]string, len(rawScope))
for i, v := range rawScope {
scopes[i] = v.(string)
}
scope := strings.Join(scopes, " ")
l.Scope = &scope
case string:
l.Scope = &rawScope
default:
return fmt.Errorf("unexpected type for field scope: %T", alias.RawScope)
}
}
return nil
}
// LogManager manages Auth0 Log resources.
type LogManager manager
// Read the data related to the log entry identified by id. This returns a
// single log entry representation as specified in the schema.
//
// See: https://auth0.com/docs/api/management/v2#!/Logs/get_logs_by_id
func (m *LogManager) Read(ctx context.Context, id string, opts ...RequestOption) (l *Log, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("logs", id), &l, opts...)
return
}
// List all log entries that match the specified search criteria (or lists all
// log entries if no criteria are used). Set custom search criteria using the
// `q` parameter, or search from a specific log id ("search from checkpoint").
//
// For more information on all possible event types, their respective acronyms
// and descriptions, Log Data Event Listing.
//
// See: https://auth0.com/docs/api/management/v2#!/Logs/get_logs
func (m *LogManager) List(ctx context.Context, opts ...RequestOption) (l []*Log, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("logs"), &l, opts...)
return
}
// Search is an alias for List.
func (m *LogManager) Search(ctx context.Context, opts ...RequestOption) ([]*Log, error) {
return m.List(ctx, opts...)
}