Audit logging - new schema (#20447)
* Audit logging - new schema added, old schema removed. * fix linter error by running goimports * Address review comments * Address review comments * Example usage of new audit logging API for the updateUserAuth call * fixed unit test on auditing updating user record * Changed the `TestUpdateConfigDiffInAuditRecord` testcase---it failed, because this PR changes how the `meta` field is serialized into the audit log records. * fix linter error
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6dc897b04f
Коммит
0c5c74904b
41
app/audit.go
41
app/audit.go
@@ -16,13 +16,6 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
)
|
||||
|
||||
const (
|
||||
RestLevelID = 240
|
||||
RestContentLevelID = 241
|
||||
RestPermsLevelID = 242
|
||||
CLILevelID = 243
|
||||
)
|
||||
|
||||
var (
|
||||
LevelAPI = mlog.LvlAuditAPI
|
||||
LevelContent = mlog.LvlAuditContent
|
||||
@@ -69,12 +62,11 @@ func (a *App) LogAuditRecWithLevel(rec *audit.Record, level mlog.Level, err erro
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
if appErr, ok := err.(*model.AppError); ok {
|
||||
rec.AddMeta("err", appErr.Error())
|
||||
rec.AddMeta("code", appErr.StatusCode)
|
||||
} else {
|
||||
rec.AddMeta("err", err)
|
||||
appErr, ok := err.(*model.AppError)
|
||||
if ok {
|
||||
rec.AddErrorCode(appErr.StatusCode)
|
||||
}
|
||||
rec.AddErrorDesc(appErr.Error())
|
||||
rec.Fail()
|
||||
}
|
||||
a.Srv().Audit.LogRecord(level, *rec)
|
||||
@@ -89,16 +81,25 @@ func (a *App) MakeAuditRecord(event string, initialStatus string) *audit.Record
|
||||
}
|
||||
|
||||
rec := &audit.Record{
|
||||
APIPath: "",
|
||||
Event: event,
|
||||
EventName: event,
|
||||
Status: initialStatus,
|
||||
UserID: userID,
|
||||
SessionID: "",
|
||||
Client: fmt.Sprintf("server %s-%s", model.BuildNumber, model.BuildHash),
|
||||
IPAddress: "",
|
||||
Meta: audit.Meta{audit.KeyClusterID: a.GetClusterId()},
|
||||
Meta: map[string]interface{}{
|
||||
audit.KeyAPIPath: "",
|
||||
audit.KeyClusterID: a.GetClusterId(),
|
||||
},
|
||||
Actor: audit.EventActor{
|
||||
UserId: userID,
|
||||
SessionId: "",
|
||||
Client: fmt.Sprintf("server %s-%s", model.BuildNumber, model.BuildHash),
|
||||
IpAddress: "",
|
||||
},
|
||||
EventData: audit.EventData{
|
||||
Parameters: map[string]interface{}{},
|
||||
PriorState: map[string]interface{}{},
|
||||
ResultState: map[string]interface{}{},
|
||||
ObjectType: "",
|
||||
},
|
||||
}
|
||||
rec.AddMetaTypeConverter(model.AuditModelTypeConv)
|
||||
|
||||
return rec
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user