1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-21 13:38:56 +02:00
focalboard/server/services/audit/audit.go
Rajat Dabade c8e729b6fe
[Refactor]: updated dependency for focalboard server (#5009)
* refactor: updated dependency for focalboard server

* chore: more dependency fixes

* refactor: removed the unless code

* refactor: added ctx for login and removed unnessary code

* refactor: bump up go version

* refactor: removed the commented code

* chore: upgraded golinter version

* fix: linter issue

* refactor: removed feature flg fix golinter

* refactor: removed feature flag from code

* revert: statistic and it's function

* refactor: removed ProductLimit related code

* refactor: removed isWithinViewsLimit implementation

* refactor: moved function GetUsedCardsCount to statistics.go from cloud.go

* refactor: removed insight code board

* refactor: removed limit dialog

* refactor: updated dependencies for linux

* chore: golinter fix

* chore: updated helper test function to use newLogger

* fix: go test

* refactor: db ping attempts from config

* revert: feature in action

* revert: feature flag in action

* revert: boardsEditor setting

---------

Co-authored-by: Rajat Dabade <rajat@Rajats-MacBook-Pro.local>
2024-06-07 23:30:08 +05:30

85 lines
2.3 KiB
Go

package audit
import (
"github.com/mattermost/mattermost/server/public/shared/mlog"
)
const (
DefMaxQueueSize = 1000
KeyAPIPath = "api_path"
KeyEvent = "event"
KeyStatus = "status"
KeyUserID = "user_id"
KeySessionID = "session_id"
KeyClient = "client"
KeyIPAddress = "ip_address"
KeyClusterID = "cluster_id"
KeyTeamID = "team_id"
Success = "success"
Attempt = "attempt"
Fail = "fail"
)
var (
LevelAuth = mlog.Level{ID: 1000, Name: "auth"}
LevelModify = mlog.Level{ID: 1001, Name: "mod"}
LevelRead = mlog.Level{ID: 1002, Name: "read"}
)
// Audit provides auditing service.
type Audit struct {
auditLogger *mlog.Logger
}
// NewAudit creates a new Audit instance which can be configured via `(*Audit).Configure`.
func NewAudit(options ...mlog.Option) (*Audit, error) {
logger, err := mlog.NewLogger(options...)
if err != nil {
return nil, err
}
return &Audit{
auditLogger: logger,
}, nil
}
// Configure provides a new configuration for this audit service.
// Zero or more sources of config can be provided:
//
// cfgFile - path to file containing JSON
// cfgEscaped - JSON string probably from ENV var
//
// For each case JSON containing log targets is provided. Target name collisions are resolved
// using the following precedence:
//
// cfgFile > cfgEscaped
func (a *Audit) Configure(cfgFile string, cfgEscaped string) error {
return a.auditLogger.Configure(cfgFile, cfgEscaped, nil)
}
// Shutdown shuts down the audit service after making best efforts to flush any
// remaining records.
func (a *Audit) Shutdown() error {
return a.auditLogger.Shutdown()
}
// LogRecord emits an audit record with complete info.
func (a *Audit) LogRecord(level mlog.Level, rec *Record) {
fields := make([]mlog.Field, 0, 7+len(rec.Meta))
fields = append(fields, mlog.String(KeyAPIPath, rec.APIPath))
fields = append(fields, mlog.String(KeyEvent, rec.Event))
fields = append(fields, mlog.String(KeyStatus, rec.Status))
fields = append(fields, mlog.String(KeyUserID, rec.UserID))
fields = append(fields, mlog.String(KeySessionID, rec.SessionID))
fields = append(fields, mlog.String(KeyClient, rec.Client))
fields = append(fields, mlog.String(KeyIPAddress, rec.IPAddress))
for _, meta := range rec.Meta {
fields = append(fields, mlog.Any(meta.K, meta.V))
}
a.auditLogger.Log(level, "audit "+rec.Event, fields...)
}