[MM-32390] Config logic refactor (#17578)
* Replace config generator * Cleanup * Some renaming and docs additions to add clarity * Cleanup logging related methods * Cleanup emitter * Fix TestDefaultsGenerator * Move feature flags synchronization logic out of config package * Remove unnecessary util functions * Simplify load/set logic * Refine semantics and add some test to cover them * Remove unnecessary deep copies * Improve logic further * Fix license header * Review file store tests * Fix test * Fix test * Avoid additional write during initialization * More consistent naming * Update app/feature_flags.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> * Move FF synchronizer to its own package * Remove unidiomatic use of sync.Once * Add some comments * Rename function * More comment Co-authored-by: Christopher Speller <crspeller@gmail.com> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b810a40062
Коммит
3681cd3688
@@ -4,7 +4,9 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@@ -14,6 +16,11 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
)
|
||||
|
||||
// marshalConfig converts the given configuration into JSON bytes for persistence.
|
||||
func marshalConfig(cfg *model.Config) ([]byte, error) {
|
||||
return json.MarshalIndent(cfg, "", " ")
|
||||
}
|
||||
|
||||
// desanitize replaces fake settings with their actual values.
|
||||
func desanitize(actual, target *model.Config) {
|
||||
if target.LdapSettings.BindPassword != nil && *target.LdapSettings.BindPassword == model.FAKE_SETTING {
|
||||
@@ -191,20 +198,11 @@ func stripPassword(dsn, schema string) string {
|
||||
return prefix + dsn[:i+1] + dsn[j:]
|
||||
}
|
||||
|
||||
func IsJsonMap(data string) bool {
|
||||
func isJSONMap(data string) bool {
|
||||
var m map[string]interface{}
|
||||
return json.Unmarshal([]byte(data), &m) == nil
|
||||
}
|
||||
|
||||
func JSONToLogTargetCfg(data []byte) (mlog.LogTargetCfg, error) {
|
||||
cfg := make(mlog.LogTargetCfg)
|
||||
err := json.Unmarshal(data, &cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func GetValueByPath(path []string, obj interface{}) (interface{}, bool) {
|
||||
r := reflect.ValueOf(obj)
|
||||
var val reflect.Value
|
||||
@@ -249,3 +247,15 @@ func GetValueByPath(path []string, obj interface{}) (interface{}, bool) {
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func equal(oldCfg, newCfg *model.Config) (bool, error) {
|
||||
oldCfgBytes, err := json.Marshal(oldCfg)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to marshal old config: %w", err)
|
||||
}
|
||||
newCfgBytes, err := json.Marshal(newCfg)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to marshal new config: %w", err)
|
||||
}
|
||||
return !bytes.Equal(oldCfgBytes, newCfgBytes), nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user