* 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 удалений

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

@@ -167,24 +167,18 @@ func configShowCmdF(command *cobra.Command, args []string) error {
}
defer app.Shutdown()
// check that no arguments are given
err = cobra.NoArgs(command, args)
if err != nil {
return err
}
// set up the config object
config := app.Config()
// pretty print
fmt.Printf("%s", prettyPrintStruct(*config))
fmt.Printf("%s", prettyPrintStruct(*app.Config()))
return nil
}
// printConfigValues function prints out the value of the configSettings working recursively or
// gives an error if config setting is not in the file.
func printConfigValues(configMap map[string]interface{}, configSetting []string, name string) (string, error) {
res, ok := configMap[configSetting[0]]
if !ok {
return "", fmt.Errorf("%s configuration setting is not in the file", name)
@@ -217,37 +211,26 @@ func configSetCmdF(command *cobra.Command, args []string) error {
configSetting := args[0]
newVal := args[1:]
// Update the config
// first disable the watchers
app.DisableConfigWatch()
// create the function to update config
oldConfig := app.Config()
newConfig := app.Config()
f := updateConfigValue(configSetting, newVal, oldConfig, newConfig)
// update the config
app.UpdateConfig(f)
// Verify new config
if err := newConfig.IsValid(); err != nil {
return err
}
if err := config.ValidateLocales(app.Config()); err != nil {
// UpdateConfig above would have already fixed these invalid locales, but we check again
// in the context of an explicit change to these parameters to avoid saving the fixed
// settings in the first place.
if changed := config.FixInvalidLocales(newConfig); changed {
return errors.New("Invalid locale configuration")
}
// make the changes persist
app.PersistConfig()
// reload config
app.ReloadConfig()
// Enable config watchers
app.EnableConfigWatch()
return nil
}

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

@@ -31,14 +31,16 @@ func TestPlugin(t *testing.T) {
th.CheckCommand(t, "plugin", "add", filepath.Join(path, "testplugin.tar.gz"))
th.CheckCommand(t, "plugin", "enable", "testplugin")
cfg, _, _, err := config.LoadConfig(th.ConfigPath())
fs, err := config.NewFileStore(th.ConfigPath(), false)
require.Nil(t, err)
assert.Equal(t, cfg.PluginSettings.PluginStates["testplugin"].Enable, true)
assert.True(t, fs.Get().PluginSettings.PluginStates["testplugin"].Enable)
fs.Close()
th.CheckCommand(t, "plugin", "disable", "testplugin")
cfg, _, _, err = config.LoadConfig(th.ConfigPath())
fs, err = config.NewFileStore(th.ConfigPath(), false)
require.Nil(t, err)
assert.Equal(t, cfg.PluginSettings.PluginStates["testplugin"].Enable, false)
assert.False(t, fs.Get().PluginSettings.PluginStates["testplugin"].Enable)
fs.Close()
th.CheckCommand(t, "plugin", "list")