[MM-32234] Fix config.json getting reset (#16805)
* Add support for read-only config stores * Allow read/write config store for plugin commands that require it
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
77da23e84b
Коммит
9c9fbe6dd9
@@ -46,6 +46,9 @@ func (a *App) EnvironmentConfig() map[string]interface{} {
|
||||
}
|
||||
|
||||
func (s *Server) UpdateConfig(f func(*model.Config)) {
|
||||
if s.configStore.IsReadOnly() {
|
||||
return
|
||||
}
|
||||
old := s.Config()
|
||||
updated := old.Clone()
|
||||
f(updated)
|
||||
|
||||
@@ -43,9 +43,9 @@ func StoreOverride(override interface{}) Option {
|
||||
// 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 {
|
||||
func Config(dsn string, watch, readOnly bool, configDefaults *model.Config) Option {
|
||||
return func(s *Server) error {
|
||||
configStore, err := config.NewStore(dsn, watch, configDefaults)
|
||||
configStore, err := config.NewStore(dsn, watch, readOnly, 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, nil)
|
||||
configStore, err := config.NewStoreFromBacking(innerStore, nil, false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to load config")
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ func TestSentry(t *testing.T) {
|
||||
|
||||
s, err := NewServer(func(server *Server) error {
|
||||
configStore, _ := config.NewFileStore("config.json", true)
|
||||
store, _ := config.NewStoreFromBacking(configStore, nil)
|
||||
store, _ := config.NewStoreFromBacking(configStore, nil, false)
|
||||
server.configStore = store
|
||||
server.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
||||
@@ -435,7 +435,7 @@ func TestSentry(t *testing.T) {
|
||||
|
||||
s, err := NewServer(func(server *Server) error {
|
||||
configStore, _ := config.NewFileStore("config.json", true)
|
||||
store, _ := config.NewStoreFromBacking(configStore, nil)
|
||||
store, _ := config.NewStoreFromBacking(configStore, nil, false)
|
||||
server.configStore = store
|
||||
server.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
||||
|
||||
Ссылка в новой задаче
Block a user