Support for additional audit config via env var (#26785)

* Add support for additional audit config via env var
This commit is contained in:
Doug Lauder 2024-04-15 12:14:26 -04:00 committed by GitHub
parent 52ad3bd7b7
commit 2825ab689c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -4,10 +4,13 @@
package app package app
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"net/http" "net/http"
"os"
"os/user" "os/user"
"strings"
"github.com/mattermost/mattermost/server/public/model" "github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/mlog" "github.com/mattermost/mattermost/server/public/shared/mlog"
@ -132,6 +135,16 @@ func (s *Server) configureAudit(adt *audit.Audit, bAllowAdvancedLogging bool) er
return fmt.Errorf("invalid config for audit, %w", err) return fmt.Errorf("invalid config for audit, %w", err)
} }
// Append additional config from env var; any target name collisions will be overwritten.
additionalJSON := strings.TrimSpace(os.Getenv("MM_EXPERIMENTALAUDITSETTINGS_ADDITIONAL"))
if additionalJSON != "" {
cfgAdditional := make(mlog.LoggerConfiguration)
if err := json.Unmarshal([]byte(additionalJSON), &cfgAdditional); err != nil {
return fmt.Errorf("invalid additional config for audit, %w", err)
}
cfg.Append(cfgAdditional)
}
return adt.Configure(cfg) return adt.Configure(cfg)
} }

View File

@ -248,7 +248,7 @@ func (l *Logger) Configure(cfgFile string, cfgEscaped string, factories *Factori
} }
// ConfigureTargets provides a new configuration for this logger via a `LoggerConfig` map. // ConfigureTargets provides a new configuration for this logger via a `LoggerConfig` map.
// Typically `mlog.Configure` is used instead which accepts JSON formatted configuration. // `Logger.Configure` can be used instead which accepts JSON formatted configuration.
// An optional set of factories can be provided which will be called to create any target // An optional set of factories can be provided which will be called to create any target
// types or formatters not built-in. // types or formatters not built-in.
func (l *Logger) ConfigureTargets(cfg LoggerConfiguration, factories *Factories) error { func (l *Logger) ConfigureTargets(cfg LoggerConfiguration, factories *Factories) error {