* config file store

Introduce an interface and concrete implementation for accessing the config.

This mostly maps 1:1 with the exiting usage in `App`, except for internalizing the watcher. A future change will likely eliminate `App.PersistConfig()` and make this implicit on `Set` or `Patch`

* experimental file test changes

* emoji: move file driver checks from api4 to app

It is no longer possible to app.UpdateConfig and provide an invalid configuration, making it hard to test this case. This check doesn't really belong in the api anyway, since it's a configuration validity check and not a permissions check. Either way, the check now occurs at the App level.

* api4: generate valid public link salts for test

* TestStartServerRateLimiterCriticalError: use mock store to test invalid config

* remove config_test.go

* remove needsSave, and have Load() save to the backing store as necessary

* restore README.md

* move ldap UserFilter check to model isValid checks

* remove databaseStore until ready

* remove unimplemented Patch

* simplify unlockOnce implementation

* revert forgetting to set s.Ldap

* config/file.go: rename ReadOnlyConfigurationError to ErrReadOnlyConfiguration

* config: export FileStore

* add TestFileStoreSave

* improved config/utils test coverage

* restore config/README.md copy

* tweaks

* file store: acquire a write lock on Save/Close to safely close watcher

* fix unmarshal_test.go
Этот коммит содержится в:
Jesse Hallam
2019-02-12 14:19:01 -04:00
коммит произвёл Christopher Speller
родитель 9cfcab2307
Коммит 285b646d67
35 изменённых файлов: 2426 добавлений и 1115 удалений

41
config/store.go Обычный файл
Просмотреть файл

@@ -0,0 +1,41 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package config
import (
"github.com/mattermost/mattermost-server/model"
)
// Listener is a callback function invoked when the configuration changes.
type Listener func(oldConfig *model.Config, newConfig *model.Config)
// Store abstracts the act of getting and setting the configuration.
type Store interface {
// Get fetches the current, cached configuration.
Get() *model.Config
// GetEnvironmentOverrides fetches the configuration fields overridden by environment variables.
GetEnvironmentOverrides() map[string]interface{}
// Set replaces the current configuration in its entirety, without updating the backing store.
Set(*model.Config) (*model.Config, error)
// Load updates the current configuration from the backing store, possibly initializing.
Load() (err error)
// Save writes the current configuration to the backing store.
Save() error
// AddListener adds a callback function to invoke when the configuration is modified.
AddListener(listener Listener) string
// RemoveListener removes a callback function using an id returned from AddListener.
RemoveListener(id string)
// String describes the backing store for the config.
String() string
// Close cleans up resources associated with the store.
Close() error
}