-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathaudit.go
More file actions
44 lines (38 loc) · 804 Bytes
/
audit.go
File metadata and controls
44 lines (38 loc) · 804 Bytes
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
/*
* Radon
*
* Copyright 2018 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/
package proxy
import (
"time"
"github.com/xelabs/go-mysqlstack/driver"
"github.com/xelabs/go-mysqlstack/sqlparser/depends/sqltypes"
)
type mode int
const (
// R enum.
R mode = iota
// W enum.
W
)
func (spanner *Spanner) auditLog(session *driver.Session, m mode, typ string, query string, qr *sqltypes.Result) error {
adit := spanner.audit
user := session.User()
host := session.Addr()
connID := session.ID()
affected := uint64(0)
if qr != nil {
affected = uint64(len(qr.Rows))
}
now := time.Now().UTC()
switch m {
case R:
adit.LogReadEvent(typ, user, host, connID, query, affected, now)
case W:
adit.LogWriteEvent(typ, user, host, connID, query, affected, now)
}
return nil
}