[GH-21565]-Add the request context and logger to all public methods in server/channels/app/audit.go (#25368)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5f8133254d
Коммит
29cd6177c0
@@ -105,6 +105,8 @@ func scheduleExportCmdF(command *cobra.Command, args []string) error {
|
||||
return errors.New("ERROR: The message export feature is not enabled")
|
||||
}
|
||||
|
||||
var rctx request.CTX = request.EmptyContext(a.Log())
|
||||
|
||||
// for now, format is hard-coded to actiance. In time, we'll have to support other formats and inject them into job data
|
||||
format, err := command.Flags().GetString("format")
|
||||
if err != nil {
|
||||
@@ -138,7 +140,6 @@ func scheduleExportCmdF(command *cobra.Command, args []string) error {
|
||||
defer cancel()
|
||||
}
|
||||
|
||||
var rctx request.CTX = request.EmptyContext(a.Log())
|
||||
rctx = rctx.WithContext(ctx)
|
||||
|
||||
job, err := messageExportI.StartSynchronizeJob(rctx, startTime)
|
||||
@@ -147,10 +148,10 @@ func scheduleExportCmdF(command *cobra.Command, args []string) error {
|
||||
} else {
|
||||
CommandPrettyPrintln("SUCCESS: Message export job complete")
|
||||
|
||||
auditRec := a.MakeAuditRecord("scheduleExport", audit.Success)
|
||||
auditRec := a.MakeAuditRecord(rctx, "scheduleExport", audit.Success)
|
||||
auditRec.AddMeta("format", format)
|
||||
auditRec.AddMeta("start", startTime)
|
||||
a.LogAuditRec(auditRec, nil)
|
||||
a.LogAuditRec(rctx, auditRec, nil)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -165,6 +166,8 @@ func buildExportCmdF(format string) func(command *cobra.Command, args []string)
|
||||
}
|
||||
defer a.Srv().Shutdown()
|
||||
|
||||
rctx := request.EmptyContext(a.Log())
|
||||
|
||||
startTime, err := command.Flags().GetInt64("exportFrom")
|
||||
if err != nil {
|
||||
return errors.New("exportFrom flag error")
|
||||
@@ -182,7 +185,7 @@ func buildExportCmdF(format string) func(command *cobra.Command, args []string)
|
||||
return errors.New("message export feature not available")
|
||||
}
|
||||
|
||||
warningsCount, appErr := a.MessageExport().RunExport(request.EmptyContext(a.Log()), format, startTime, limit)
|
||||
warningsCount, appErr := a.MessageExport().RunExport(rctx, format, startTime, limit)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
@@ -196,10 +199,10 @@ func buildExportCmdF(format string) func(command *cobra.Command, args []string)
|
||||
}
|
||||
}
|
||||
|
||||
auditRec := a.MakeAuditRecord("buildExport", audit.Success)
|
||||
auditRec := a.MakeAuditRecord(rctx, "buildExport", audit.Success)
|
||||
auditRec.AddMeta("format", format)
|
||||
auditRec.AddMeta("start", startTime)
|
||||
a.LogAuditRec(auditRec, nil)
|
||||
a.LogAuditRec(rctx, auditRec, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -212,6 +215,8 @@ func bulkExportCmdF(command *cobra.Command, args []string) error {
|
||||
}
|
||||
defer a.Srv().Shutdown()
|
||||
|
||||
rctx := request.EmptyContext(a.Log())
|
||||
|
||||
allTeams, err := command.Flags().GetBool("all-teams")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "all-teams flag error")
|
||||
@@ -250,15 +255,15 @@ func bulkExportCmdF(command *cobra.Command, args []string) error {
|
||||
opts.IncludeAttachments = attachments
|
||||
opts.CreateArchive = archive
|
||||
opts.IncludeArchivedChannels = withArchivedChannels
|
||||
if err := a.BulkExport(request.EmptyContext(a.Log()), fileWriter, filepath.Dir(outPath), nil /* nil job since it's spawned from CLI */, opts); err != nil {
|
||||
if err := a.BulkExport(rctx, fileWriter, filepath.Dir(outPath), nil /* nil job since it's spawned from CLI */, opts); err != nil {
|
||||
CommandPrintErrorln(err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
auditRec := a.MakeAuditRecord("bulkExport", audit.Success)
|
||||
auditRec := a.MakeAuditRecord(rctx, "bulkExport", audit.Success)
|
||||
auditRec.AddMeta("all_teams", allTeams)
|
||||
auditRec.AddMeta("file", args[0])
|
||||
a.LogAuditRec(auditRec, nil)
|
||||
a.LogAuditRec(rctx, auditRec, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ func slackImportCmdF(command *cobra.Command, args []string) error {
|
||||
}
|
||||
defer a.Srv().Shutdown()
|
||||
|
||||
rctx := request.EmptyContext(a.Log())
|
||||
|
||||
if len(args) != 2 {
|
||||
return errors.New("Incorrect number of arguments.")
|
||||
}
|
||||
@@ -79,7 +81,7 @@ func slackImportCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
CommandPrettyPrintln("Running Slack Import. This may take a long time for large teams or teams with many messages.")
|
||||
|
||||
importErr, log := a.SlackImport(request.EmptyContext(a.Log()), fileReader, fileInfo.Size(), team.Id)
|
||||
importErr, log := a.SlackImport(rctx, fileReader, fileInfo.Size(), team.Id)
|
||||
|
||||
if importErr != nil {
|
||||
return err
|
||||
@@ -92,10 +94,10 @@ func slackImportCmdF(command *cobra.Command, args []string) error {
|
||||
CommandPrettyPrintln("Finished Slack Import.")
|
||||
CommandPrettyPrintln("")
|
||||
|
||||
auditRec := a.MakeAuditRecord("slackImport", audit.Success)
|
||||
auditRec := a.MakeAuditRecord(rctx, "slackImport", audit.Success)
|
||||
auditRec.AddMeta("team", team)
|
||||
auditRec.AddMeta("file", args[1])
|
||||
a.LogAuditRec(auditRec, nil)
|
||||
a.LogAuditRec(rctx, auditRec, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -107,6 +109,8 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
|
||||
}
|
||||
defer a.Srv().Shutdown()
|
||||
|
||||
rctx := request.EmptyContext(a.Log())
|
||||
|
||||
apply, err := command.Flags().GetBool("apply")
|
||||
if err != nil {
|
||||
return errors.New("Apply flag error")
|
||||
@@ -152,7 +156,7 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
CommandPrettyPrintln("")
|
||||
|
||||
if err, lineNumber := a.BulkImportWithPath(request.EmptyContext(a.Log()), fileReader, nil, !apply, workers, importPath); err != nil {
|
||||
if err, lineNumber := a.BulkImportWithPath(rctx, fileReader, nil, !apply, workers, importPath); err != nil {
|
||||
CommandPrintErrorln(err.Error())
|
||||
if lineNumber != 0 {
|
||||
CommandPrintErrorln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
|
||||
@@ -162,9 +166,9 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
if apply {
|
||||
CommandPrettyPrintln("Finished Bulk Import.")
|
||||
auditRec := a.MakeAuditRecord("bulkImport", audit.Success)
|
||||
auditRec := a.MakeAuditRecord(rctx, "bulkImport", audit.Success)
|
||||
auditRec.AddMeta("file", args[0])
|
||||
a.LogAuditRec(auditRec, nil)
|
||||
a.LogAuditRec(rctx, auditRec, nil)
|
||||
} else {
|
||||
CommandPrettyPrintln("Validation complete. You can now perform the import by rerunning this command with the --apply flag.")
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||
"github.com/mattermost/mattermost/server/v8/config"
|
||||
@@ -43,6 +44,8 @@ func jobserverCmdF(command *cobra.Command, args []string) error {
|
||||
|
||||
a.Srv().LoadLicense()
|
||||
|
||||
rctx := request.EmptyContext(a.Log())
|
||||
|
||||
// Run jobs
|
||||
mlog.Info("Starting Mattermost job server")
|
||||
defer mlog.Info("Stopped Mattermost job server")
|
||||
@@ -57,8 +60,8 @@ func jobserverCmdF(command *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if !noJobs || !noSchedule {
|
||||
auditRec := a.MakeAuditRecord("jobServer", audit.Success)
|
||||
a.LogAuditRec(auditRec, nil)
|
||||
auditRec := a.MakeAuditRecord(rctx, "jobServer", audit.Success)
|
||||
a.LogAuditRec(rctx, auditRec, nil)
|
||||
}
|
||||
|
||||
signalChan := make(chan os.Signal, 1)
|
||||
|
||||
Ссылка в новой задаче
Block a user