Add auditing to server CLI.

Also:
- simplify auditing in API layer
- reduce number of AddMeta calls
- have models serialize themselves
- more consistent field naming
Этот коммит содержится в:
Doug Lauder
2020-04-08 00:52:30 -04:00
коммит произвёл GitHub
родитель e2d1af17de
Коммит 6a27ed4a1d
45 изменённых файлов: 1488 добавлений и 244 удалений

Просмотреть файл

@@ -29,7 +29,7 @@ func (c *Context) LogAuditRec(rec *audit.Record) {
c.LogAuditRecWithLevel(rec, app.RestLevel)
}
// LogAuditRec logs an audit record using specificed Level.
// LogAuditRec logs an audit record using specified Level.
func (c *Context) LogAuditRecWithLevel(rec *audit.Record, level audit.Level) {
if rec == nil {
return
@@ -42,15 +42,12 @@ func (c *Context) LogAuditRecWithLevel(rec *audit.Record, level audit.Level) {
}
rec.Fail()
}
if cid := c.App.GetClusterId(); cid != "" {
rec.AddMeta(audit.KeyClusterID, cid)
}
c.App.Srv().Audit.LogRecord(level, *rec)
}
// MakeAuditRecord creates a audit record pre-populated with data from this context.
func (c *Context) MakeAuditRecord(event string, initialStatus string) *audit.Record {
return &audit.Record{
rec := &audit.Record{
APIPath: c.App.Path(),
Event: event,
Status: initialStatus,
@@ -58,8 +55,11 @@ func (c *Context) MakeAuditRecord(event string, initialStatus string) *audit.Rec
SessionID: c.App.Session().Id,
Client: c.App.UserAgent(),
IPAddress: c.App.IpAddress(),
Meta: audit.Meta{},
Meta: audit.Meta{audit.KeyClusterID: c.App.GetClusterId()},
}
rec.AddMetaTypeConverter(model.AuditModelTypeConv)
return rec
}
func (c *Context) LogAudit(extraInfo string) {