diff --git a/server/channels/app/audit.go b/server/channels/app/audit.go index bcd1aedf32..659ef697dc 100644 --- a/server/channels/app/audit.go +++ b/server/channels/app/audit.go @@ -111,13 +111,17 @@ func (s *Server) configureAudit(adt *audit.Audit, bAllowAdvancedLogging bool) er var logConfigSrc config.LogConfigSrc dsn := s.platform.Config().ExperimentalAuditSettings.GetAdvancedLoggingConfig() - if bAllowAdvancedLogging && !utils.IsEmptyJSON(dsn) { - var err error - logConfigSrc, err = config.NewLogConfigSrc(dsn, s.platform.GetConfigStore()) - if err != nil { - return fmt.Errorf("invalid config source for audit, %w", err) + if bAllowAdvancedLogging { + if !utils.IsEmptyJSON(dsn) { + var err error + logConfigSrc, err = config.NewLogConfigSrc(dsn, s.platform.GetConfigStore()) + if err != nil { + return fmt.Errorf("invalid config source for audit, %w", err) + } + mlog.Debug("Loaded audit configuration", mlog.String("source", string(dsn))) + } else { + s.Log().Debug("Advanced logging config not provided for audit") } - mlog.Debug("Loaded audit configuration", mlog.String("source", string(dsn))) } // ExperimentalAuditSettings provides basic file audit (E0, E10); logConfigSrc provides advanced config (E20). diff --git a/server/channels/app/platform/config.go b/server/channels/app/platform/config.go index eb656285eb..01b85432d7 100644 --- a/server/channels/app/platform/config.go +++ b/server/channels/app/platform/config.go @@ -129,6 +129,8 @@ func (ps *PlatformService) ConfigureLogger(name string, logger *mlog.Logger, log return fmt.Errorf("invalid config source for %s, %w", name, err) } ps.logger.Info("Loaded configuration for "+name, mlog.String("source", string(dsn))) + } else { + ps.logger.Debug("Advanced logging config not provided for " + name) } cfg, err := config.MloggerConfigFromLoggerConfig(logSettings, logConfigSrc, getPath) diff --git a/server/config/environment.go b/server/config/environment.go index 14b3edf56e..807af6272f 100644 --- a/server/config/environment.go +++ b/server/config/environment.go @@ -72,7 +72,11 @@ func applyEnvKey(key, value string, rValueSubject reflect.Value) { if err == nil { rFieldValue.Set(reflect.ValueOf(intVal)) } - case reflect.SliceOf(reflect.TypeOf("")).Kind(): + case reflect.Slice: + if rFieldValue.Type() == reflect.TypeOf(json.RawMessage{}) { + rFieldValue.Set(reflect.ValueOf([]byte(value))) + break + } rFieldValue.Set(reflect.ValueOf(strings.Split(value, " "))) case reflect.Map: target := reflect.New(rFieldValue.Type()).Interface() diff --git a/server/public/model/config.go b/server/public/model/config.go index 06bc443d93..8ad1d72d0a 100644 --- a/server/public/model/config.go +++ b/server/public/model/config.go @@ -1336,31 +1336,23 @@ func (s *LogSettings) SetDefaults() { } if utils.IsEmptyJSON(s.AdvancedLoggingJSON) { - // copy any non-empty AdvancedLoggingConfig (deprecated) to the new field. - if s.AdvancedLoggingConfig != nil && !utils.IsEmptyJSON([]byte(*s.AdvancedLoggingConfig)) { - s.AdvancedLoggingJSON = utils.StringPtrToJSON(s.AdvancedLoggingConfig) - - } else { - s.AdvancedLoggingJSON = []byte("{}") - } + s.AdvancedLoggingJSON = []byte("{}") } - // temporarily let AdvancedLoggingConfig take precedence. + if s.AdvancedLoggingConfig == nil { s.AdvancedLoggingConfig = NewString("") } - //s.AdvancedLoggingConfig = nil } // GetAdvancedLoggingConfig returns the advanced logging config as a []byte. -// AdvancedLoggingJSON takes precident over the deprecated AdvancedLoggingConfig. +// AdvancedLoggingJSON takes precedence over the deprecated AdvancedLoggingConfig. func (s *LogSettings) GetAdvancedLoggingConfig() []byte { - // temporarily let AdvancedLoggingConfig take precedence. - if s.AdvancedLoggingConfig != nil && !utils.IsEmptyJSON([]byte(*s.AdvancedLoggingConfig)) { - return []byte(*s.AdvancedLoggingConfig) - } if !utils.IsEmptyJSON(s.AdvancedLoggingJSON) { return s.AdvancedLoggingJSON } + if s.AdvancedLoggingConfig != nil && !utils.IsEmptyJSON([]byte(*s.AdvancedLoggingConfig)) { + return []byte(*s.AdvancedLoggingConfig) + } return []byte("{}") } @@ -1406,31 +1398,23 @@ func (s *ExperimentalAuditSettings) SetDefaults() { } if utils.IsEmptyJSON(s.AdvancedLoggingJSON) { - // copy any non-empty AdvancedLoggingConfig (deprecated) to the new field. - if s.AdvancedLoggingConfig != nil && !utils.IsEmptyJSON([]byte(*s.AdvancedLoggingConfig)) { - s.AdvancedLoggingJSON = utils.StringPtrToJSON(s.AdvancedLoggingConfig) - } else { - s.AdvancedLoggingJSON = []byte("{}") - } + s.AdvancedLoggingJSON = []byte("{}") } - // temporarily let AdvancedLoggingConfig take precedence. if s.AdvancedLoggingConfig == nil { s.AdvancedLoggingConfig = NewString("") } - //s.AdvancedLoggingConfig = nil } // GetAdvancedLoggingConfig returns the advanced logging config as a []byte. -// AdvancedLoggingJSON takes precident over the deprecated AdvancedLoggingConfig. +// AdvancedLoggingJSON takes precedence over the deprecated AdvancedLoggingConfig. func (s *ExperimentalAuditSettings) GetAdvancedLoggingConfig() []byte { - // temporarily let AdvancedLoggingConfig take precedence. - if s.AdvancedLoggingConfig != nil && !utils.IsEmptyJSON([]byte(*s.AdvancedLoggingConfig)) { - return []byte(*s.AdvancedLoggingConfig) - } if !utils.IsEmptyJSON(s.AdvancedLoggingJSON) { return s.AdvancedLoggingJSON } + if s.AdvancedLoggingConfig != nil && !utils.IsEmptyJSON([]byte(*s.AdvancedLoggingConfig)) { + return []byte(*s.AdvancedLoggingConfig) + } return []byte("{}") } @@ -1481,30 +1465,23 @@ func (s *NotificationLogSettings) SetDefaults() { } if utils.IsEmptyJSON(s.AdvancedLoggingJSON) { - // copy any non-empty AdvancedLoggingConfig (deprecated) to the new field. - if s.AdvancedLoggingConfig != nil && !utils.IsEmptyJSON([]byte(*s.AdvancedLoggingConfig)) { - s.AdvancedLoggingJSON = utils.StringPtrToJSON(s.AdvancedLoggingConfig) - } else { - s.AdvancedLoggingJSON = []byte("{}") - } + s.AdvancedLoggingJSON = []byte("{}") } - // temporarily let AdvancedLoggingConfig take precedence. + if s.AdvancedLoggingConfig == nil { s.AdvancedLoggingConfig = NewString("") } - //s.AdvancedLoggingConfig = nil } // GetAdvancedLoggingConfig returns the advanced logging config as a []byte. -// AdvancedLoggingJSON takes precident over the deprecated AdvancedLoggingConfig. +// AdvancedLoggingJSON takes precedence over the deprecated AdvancedLoggingConfig. func (s *NotificationLogSettings) GetAdvancedLoggingConfig() []byte { - // temporarily let AdvancedLoggingConfig take precedence. - if s.AdvancedLoggingConfig != nil && !utils.IsEmptyJSON([]byte(*s.AdvancedLoggingConfig)) { - return []byte(*s.AdvancedLoggingConfig) - } if !utils.IsEmptyJSON(s.AdvancedLoggingJSON) { return s.AdvancedLoggingJSON } + if s.AdvancedLoggingConfig != nil && !utils.IsEmptyJSON([]byte(*s.AdvancedLoggingConfig)) { + return []byte(*s.AdvancedLoggingConfig) + } return []byte("{}") } diff --git a/server/public/utils/json.go b/server/public/utils/json.go index 4e311bcba0..62443bea73 100644 --- a/server/public/utils/json.go +++ b/server/public/utils/json.go @@ -7,6 +7,7 @@ import ( "bytes" "encoding/json" "strings" + "unicode" "github.com/pkg/errors" ) @@ -57,7 +58,19 @@ func NewHumanizedJSONError(err error, data []byte, offset int64) *HumanizedJSONE } func IsEmptyJSON(j json.RawMessage) bool { - if len(j) == 0 || bytes.Equal(j, []byte("{}")) || bytes.Equal(j, []byte("\"\"")) || bytes.Equal(j, []byte("[]")) { + if len(j) == 0 { + return true + } + + // remove all whitespace + jj := make([]byte, 0, len(j)) + for _, b := range j { + if !unicode.IsSpace(rune(b)) { + jj = append(jj, b) + } + } + + if len(jj) == 0 || bytes.Equal(jj, []byte("{}")) || bytes.Equal(jj, []byte("\"\"")) || bytes.Equal(jj, []byte("[]")) { return true } return false diff --git a/server/public/utils/json_test.go b/server/public/utils/json_test.go index 145c6d276a..e10a7ea8ab 100644 --- a/server/public/utils/json_test.go +++ b/server/public/utils/json_test.go @@ -283,6 +283,11 @@ func TestIsJSONEmpty(t *testing.T) { []byte("\"hello\""), false, }, + { + "whitespace still empty", + []byte(" \n { \t } "), + true, + }, } for _, testCase := range testCases {