forked from go-auth0/auth0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
125 lines (107 loc) · 3.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
package management
import (
"encoding/json"
"time"
auth0 "github.com/yieldr/go-auth0"
)
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",
}
type Log struct {
ID *string `json:"_id"`
LogID *string `json:"log_id"`
// The date when the event was created
Date *time.Time `json:"date"`
// The log event type
Type *string `json:"type"`
// The id of the client
ClientID *string `json:"client_id"`
// The name of the client
ClientName *string `json:"client_name"`
// The IP of the log event source
IP *string `json:"ip"`
LocationInfo map[string]interface{} `json:"location_info"`
Details map[string]interface{} `json:"details"`
// The user's unique identifier
UserID *string `json:"user_id"`
}
func (l *Log) String() string {
b, _ := json.Marshal(l)
return string(b)
}
func (l *Log) TypeName() string {
if name, ok := logTypeName[auth0.StringValue(l.Type)]; ok {
return name
}
return ""
}
type LogManager struct {
m *Management
}
func NewLogManager(m *Management) *LogManager {
return &LogManager{m}
}
func (lm *LogManager) Read(id string, opts ...reqOption) (*Log, error) {
l := new(Log)
err := lm.m.get(lm.m.uri("logs", id), l)
return l, err
}
func (lm *LogManager) List(opts ...reqOption) ([]*Log, error) {
var l []*Log
err := lm.m.get(lm.m.uri("logs")+lm.m.q(opts), &l)
return l, err
}
func (lm *LogManager) Search(opts ...reqOption) ([]*Log, error) {
return lm.List(opts...)
}