* Replace config generator * Cleanup * Some renaming and docs additions to add clarity * Cleanup logging related methods * Cleanup emitter * Fix TestDefaultsGenerator * Move feature flags synchronization logic out of config package * Remove unnecessary util functions * Simplify load/set logic * Refine semantics and add some test to cover them * Remove unnecessary deep copies * Improve logic further * Fix license header * Review file store tests * Fix test * Fix test * Avoid additional write during initialization * More consistent naming * Update app/feature_flags.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> * Make ConfigStore.Set() return both old and new configs * Implement config diff function * Make app.SaveConfig return previous and current configs * Add config diff to audit record * Fix returned configs * Include high level test * Move FF synchronizer to its own package * Remove unidiomatic use of sync.Once * Add some comments * Rename function * More comment * Save config diff in audit record for local endpoints * Enable audit for config set/reset commands * Improve tests output Co-authored-by: Christopher Speller <crspeller@gmail.com> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
70 строки
1.8 KiB
Go
70 строки
1.8 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package config
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// Migrate migrates SAML keys, certificates, and other config files from one store to another given their data source names.
|
|
func Migrate(from, to string) error {
|
|
source, err := NewStoreFromDSN(from, false, false, nil)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "failed to access source config %s", from)
|
|
}
|
|
defer source.Close()
|
|
|
|
destination, err := NewStoreFromDSN(to, false, false, nil)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "failed to access destination config %s", to)
|
|
}
|
|
defer destination.Close()
|
|
|
|
sourceConfig := source.Get()
|
|
if _, _, err = destination.Set(sourceConfig); err != nil {
|
|
return errors.Wrapf(err, "failed to set config")
|
|
}
|
|
|
|
files := []string{
|
|
*sourceConfig.SamlSettings.IdpCertificateFile,
|
|
*sourceConfig.SamlSettings.PublicCertificateFile,
|
|
*sourceConfig.SamlSettings.PrivateKeyFile,
|
|
}
|
|
|
|
// Only migrate advanced logging config if it is not embedded JSON.
|
|
if !isJSONMap(*sourceConfig.LogSettings.AdvancedLoggingConfig) {
|
|
files = append(files, *sourceConfig.LogSettings.AdvancedLoggingConfig)
|
|
}
|
|
|
|
files = append(files, sourceConfig.PluginSettings.SignaturePublicKeyFiles...)
|
|
|
|
for _, file := range files {
|
|
if err := migrateFile(file, source, destination); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func migrateFile(name string, source *Store, destination *Store) error {
|
|
fileExists, err := source.HasFile(name)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "failed to check existence of %s", name)
|
|
}
|
|
|
|
if fileExists {
|
|
file, err := source.GetFile(name)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "failed to migrate %s", name)
|
|
}
|
|
err = destination.SetFile(name, file)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "failed to migrate %s", name)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|