[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")
}