[MM-32390] Config logic refactor (#17578)
* 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> * Move FF synchronizer to its own package * Remove unidiomatic use of sync.Once * Add some comments * Rename function * More comment Co-authored-by: Christopher Speller <crspeller@gmail.com> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b810a40062
Коммит
3681cd3688
46
scripts/config_generator/main.go
Обычный файл
46
scripts/config_generator/main.go
Обычный файл
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
// generateDefaultConfig writes default config to outputFile.
|
||||
func generateDefaultConfig(outputFile *os.File) error {
|
||||
defaultCfg := &model.Config{}
|
||||
defaultCfg.SetDefaults()
|
||||
if data, err := json.MarshalIndent(defaultCfg, "", " "); err != nil {
|
||||
return err
|
||||
} else if _, err := outputFile.Write(data); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
outputFile := os.Getenv("OUTPUT_CONFIG")
|
||||
if outputFile == "" {
|
||||
fmt.Println("Output file name is missing. Please set OUTPUT_CONFIG env variable to absolute path")
|
||||
os.Exit(2)
|
||||
}
|
||||
if _, err := os.Stat(outputFile); !os.IsNotExist(err) {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "File %s already exists. Not overwriting!\n", outputFile)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if file, err := os.Create(outputFile); err == nil {
|
||||
err = generateDefaultConfig(file)
|
||||
_ = file.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
41
scripts/config_generator/main_test.go
Обычный файл
41
scripts/config_generator/main_test.go
Обычный файл
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDefaultsGenerator(t *testing.T) {
|
||||
tmpFile, err := ioutil.TempFile("", "tempconfig")
|
||||
defer os.Remove(tmpFile.Name())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, generateDefaultConfig(tmpFile))
|
||||
_ = tmpFile.Close()
|
||||
var config model.Config
|
||||
|
||||
b, err := ioutil.ReadFile(tmpFile.Name())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, json.Unmarshal(b, &config))
|
||||
require.True(t, *config.ServiceSettings.DisableLegacyMFA)
|
||||
require.Equal(t, *config.SqlSettings.AtRestEncryptKey, "")
|
||||
require.Equal(t, *config.FileSettings.PublicLinkSalt, "")
|
||||
|
||||
require.Equal(t, *config.Office365Settings.Scope, model.OFFICE365_SETTINGS_DEFAULT_SCOPE)
|
||||
require.Equal(t, *config.Office365Settings.AuthEndpoint, model.OFFICE365_SETTINGS_DEFAULT_AUTH_ENDPOINT)
|
||||
require.Equal(t, *config.Office365Settings.UserApiEndpoint, model.OFFICE365_SETTINGS_DEFAULT_USER_API_ENDPOINT)
|
||||
require.Equal(t, *config.Office365Settings.TokenEndpoint, model.OFFICE365_SETTINGS_DEFAULT_TOKEN_ENDPOINT)
|
||||
|
||||
require.Equal(t, *config.GoogleSettings.Scope, model.GOOGLE_SETTINGS_DEFAULT_SCOPE)
|
||||
require.Equal(t, *config.GoogleSettings.AuthEndpoint, model.GOOGLE_SETTINGS_DEFAULT_AUTH_ENDPOINT)
|
||||
require.Equal(t, *config.GoogleSettings.UserApiEndpoint, model.GOOGLE_SETTINGS_DEFAULT_USER_API_ENDPOINT)
|
||||
require.Equal(t, *config.GoogleSettings.TokenEndpoint, model.GOOGLE_SETTINGS_DEFAULT_TOKEN_ENDPOINT)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user