-
Notifications
You must be signed in to change notification settings - Fork 28
/
audit.go
67 lines (61 loc) · 2.01 KB
/
audit.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
// Copyright 2016-Present Couchbase, Inc.
//
// Use of this software is governed by the Business Source License included
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
// in that file, in accordance with the Business Source License, use of this
// software will be governed by the Apache License, Version 2.0, included in
// the file licenses/APL2.txt.
package cbft
import (
"github.com/couchbase/cbgt/rest"
"github.com/couchbase/goutils/go-cbaudit"
"net/http"
)
const (
AuditDeleteIndexEvent = 24576 // 0x6000
AuditCreateUpdateIndexEvent = 24577 // 0x6001
AuditControlEvent = 24579 // 0x6003
AuditConfigRefreshEvent = 24580 // 0x6004
AuditConfigReplanEvent = 24581 // 0x6005
AuditRunGCEvent = 24582 // 0x6006
AuditProfileCPUEvent = 24583 // 0x6007
AuditProfileMemoryEvent = 24584 // 0x6008
AuditAccessDeniedEvent = 24585 // 0x6009
)
type IndexControlAuditLog struct {
audit.CommonAuditFields
IndexName string `json:"index_name"`
Control string `json:"control_name"`
}
type IndexAuditLog struct {
audit.CommonAuditFields
IndexName string `json:"index_name"`
}
func GetAuditEventData(eventId uint32, req *http.Request) interface{} {
switch eventId {
case AuditDeleteIndexEvent, AuditCreateUpdateIndexEvent:
indexName := rest.IndexNameLookup(req)
d := IndexAuditLog{
CommonAuditFields: audit.GetCommonAuditFields(req),
IndexName: indexName,
}
return d
case AuditConfigReplanEvent, AuditRunGCEvent,
AuditProfileCPUEvent, AuditProfileMemoryEvent:
return audit.GetCommonAuditFields(req)
case AuditControlEvent:
indexName := rest.IndexNameLookup(req)
d := IndexControlAuditLog{
CommonAuditFields: audit.GetCommonAuditFields(req),
IndexName: indexName,
Control: rest.RequestVariableLookup(req, "op"),
}
return d
case AuditAccessDeniedEvent:
return IndexAuditLog{
CommonAuditFields: audit.GetCommonAuditFields(req),
IndexName: rest.IndexNameLookup(req),
}
}
return nil
}