MM-22785 audit server CLI (#14144)
Add auditing to server CLI. Also: - simplify auditing in API layer - reduce number of AddMeta calls - have models serialize themselves - more consistent field naming
Этот коммит содержится в:
@@ -6,6 +6,10 @@ package audit
|
||||
// Meta represents metadata that can be added to a audit record as name/value pairs.
|
||||
type Meta map[string]interface{}
|
||||
|
||||
// FuncMetaTypeConv defines a function that can convert meta data types into something
|
||||
// that serializes well for audit records.
|
||||
type FuncMetaTypeConv func(val interface{}) (newVal interface{}, converted bool)
|
||||
|
||||
// Record provides a consistent set of fields used for all audit logging.
|
||||
type Record struct {
|
||||
APIPath string
|
||||
@@ -16,6 +20,7 @@ type Record struct {
|
||||
Client string
|
||||
IPAddress string
|
||||
Meta Meta
|
||||
metaConv []FuncMetaTypeConv
|
||||
}
|
||||
|
||||
// Success marks the audit record status as successful.
|
||||
@@ -33,5 +38,22 @@ func (rec *Record) AddMeta(name string, val interface{}) {
|
||||
if rec.Meta == nil {
|
||||
rec.Meta = Meta{}
|
||||
}
|
||||
|
||||
// possibly convert val to something better suited for serializing
|
||||
// via zero or more conversion functions.
|
||||
var converted bool
|
||||
for _, conv := range rec.metaConv {
|
||||
val, converted = conv(val)
|
||||
if converted {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
rec.Meta[name] = val
|
||||
}
|
||||
|
||||
// AddMetaTypeConverter adds a function capable of converting meta field types
|
||||
// into something more suitable for serialization.
|
||||
func (rec *Record) AddMetaTypeConverter(f FuncMetaTypeConv) {
|
||||
rec.metaConv = append(rec.metaConv, f)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user