[MM-30436] Add support for configuration custom defaults (#16265)

* [MM-30436] Add support for configuration custom defaults

* Addressing review comments

* Addressing PR comments

* Soft fail if the configuration defaults cannot be read

* Directly print error in log message

* Fix linter

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Miguel de la Cruz
2020-11-16 15:25:48 +01:00
коммит произвёл GitHub
родитель c82c37a36e
Коммит 6c857a4525
18 изменённых файлов: 334 добавлений и 131 удалений

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

@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
)
@@ -38,10 +39,13 @@ func StoreOverride(override interface{}) Option {
}
}
// Config applies the given config dsn, whether a path to config.json or a database connection string.
func Config(dsn string, watch bool) Option {
// Config applies the given config dsn, whether a path to config.json
// or a database connection string. It receives as well a set of
// custom defaults that will be applied for any unset property of the
// config loaded from the dsn on top of the normal defaults
func Config(dsn string, watch bool, configDefaults *model.Config) Option {
return func(s *Server) error {
configStore, err := config.NewStore(dsn, watch)
configStore, err := config.NewStore(dsn, watch, configDefaults)
if err != nil {
return errors.Wrap(err, "failed to apply Config option")
}

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

@@ -210,7 +210,7 @@ func NewServer(options ...Option) (*Server, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to load config")
}
configStore, err := config.NewStoreFromBacking(innerStore)
configStore, err := config.NewStoreFromBacking(innerStore, nil)
if err != nil {
return nil, errors.Wrap(err, "failed to load config")
}

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

@@ -386,7 +386,7 @@ func TestSentry(t *testing.T) {
s, err := NewServer(func(server *Server) error {
configStore, _ := config.NewFileStore("config.json", true)
store, _ := config.NewStoreFromBacking(configStore)
store, _ := config.NewStoreFromBacking(configStore, nil)
server.configStore = store
server.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.ListenAddress = ":0"
@@ -437,7 +437,7 @@ func TestSentry(t *testing.T) {
s, err := NewServer(func(server *Server) error {
configStore, _ := config.NewFileStore("config.json", true)
store, _ := config.NewStoreFromBacking(configStore)
store, _ := config.NewStoreFromBacking(configStore, nil)
server.configStore = store
server.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.ListenAddress = ":0"