MM-16725 Respect env var overrides when setting config (#11821)

* Respect env var overrides when setting config

* Use strings.NewReader
Этот коммит содержится в:
Joram Wilander
2019-08-09 11:33:59 -04:00
коммит произвёл GitHub
родитель 9ea0a60d88
Коммит 404c49f62f
15 изменённых файлов: 85 добавлений и 23 удалений

Просмотреть файл

@@ -6,6 +6,7 @@ package config
import (
"bytes"
"io"
"strings"
"sync"
"github.com/mattermost/mattermost-server/model"
@@ -42,7 +43,7 @@ func (cs *commonStore) GetEnvironmentOverrides() map[string]interface{} {
// using the persist function argument.
//
// This function assumes no lock has been acquired, as it acquires a write lock itself.
func (cs *commonStore) set(newCfg *model.Config, validate func(*model.Config) error, persist func(*model.Config) error) (*model.Config, error) {
func (cs *commonStore) set(newCfg *model.Config, allowEnvironmentOverrides bool, validate func(*model.Config) error, persist func(*model.Config) error) (*model.Config, error) {
cs.configLock.Lock()
var unlockOnce sync.Once
defer unlockOnce.Do(cs.configLock.Unlock)
@@ -56,7 +57,14 @@ func (cs *commonStore) set(newCfg *model.Config, validate func(*model.Config) er
// return nil, errors.New("old configuration modified instead of cloning")
// }
newCfg = newCfg.Clone()
// To both clone and re-apply the environment variable overrides we marshal and then
// unmarshal the config again.
var err error
newCfg, _, err = unmarshalConfig(strings.NewReader(newCfg.ToJson()), allowEnvironmentOverrides)
if err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal config with env overrides")
}
newCfg.SetDefaults()
// Sometimes the config is received with "fake" data in sensitive fields. Apply the real