* replace interface{} with any
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2022-07-05 09:46:50 +03:00
коммит произвёл GitHub
родитель b45ff0be5d
Коммит 717a4d04a9
258 изменённых файлов: 1286 добавлений и 1286 удалений

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

@@ -278,7 +278,7 @@ func (ds *DatabaseStore) persist(cfg *model.Config) error {
return errors.Wrap(err, "failed to query active configuration")
}
if oldId != "" {
if _, err := tx.NamedExec("UPDATE Configurations SET Active = NULL WHERE Id = :id", map[string]interface{}{"id": oldId}); err != nil {
if _, err := tx.NamedExec("UPDATE Configurations SET Active = NULL WHERE Id = :id", map[string]any{"id": oldId}); err != nil {
return errors.Wrap(err, "failed to deactivate current configuration")
}
}
@@ -288,7 +288,7 @@ func (ds *DatabaseStore) persist(cfg *model.Config) error {
}
}
params := map[string]interface{}{
params := map[string]any{
"id": model.NewId(),
"value": value,
"create_at": model.GetMillis(),
@@ -329,7 +329,7 @@ func (ds *DatabaseStore) Load() ([]byte, error) {
// GetFile fetches the contents of a previously persisted configuration file.
func (ds *DatabaseStore) GetFile(name string) ([]byte, error) {
query, args, err := sqlx.Named("SELECT Data FROM ConfigurationFiles WHERE Name = :name", map[string]interface{}{
query, args, err := sqlx.Named("SELECT Data FROM ConfigurationFiles WHERE Name = :name", map[string]any{
"name": name,
})
if err != nil {
@@ -351,7 +351,7 @@ func (ds *DatabaseStore) SetFile(name string, data []byte) error {
if err != nil {
return errors.Wrap(err, "file data failed length check")
}
params := map[string]interface{}{
params := map[string]any{
"name": name,
"data": data,
"create_at": model.GetMillis(),
@@ -380,7 +380,7 @@ func (ds *DatabaseStore) SetFile(name string, data []byte) error {
// HasFile returns true if the given file was previously persisted.
func (ds *DatabaseStore) HasFile(name string) (bool, error) {
query, args, err := sqlx.Named("SELECT COUNT(*) FROM ConfigurationFiles WHERE Name = :name", map[string]interface{}{
query, args, err := sqlx.Named("SELECT COUNT(*) FROM ConfigurationFiles WHERE Name = :name", map[string]any{
"name": name,
})
if err != nil {
@@ -398,7 +398,7 @@ func (ds *DatabaseStore) HasFile(name string) (bool, error) {
// RemoveFile remoevs a previously persisted configuration file.
func (ds *DatabaseStore) RemoveFile(name string) error {
_, err := ds.db.NamedExec("DELETE FROM ConfigurationFiles WHERE Name = :name", map[string]interface{}{
_, err := ds.db.NamedExec("DELETE FROM ConfigurationFiles WHERE Name = :name", map[string]any{
"name": name,
})
if err != nil {
@@ -420,7 +420,7 @@ func (ds *DatabaseStore) Close() error {
// removes configurations from database if they are older than threshold.
func (ds *DatabaseStore) cleanUp(thresholdCreatAt int) error {
if _, err := ds.db.NamedExec("DELETE FROM Configurations Where CreateAt < :timestamp", map[string]interface{}{"timestamp": thresholdCreatAt}); err != nil {
if _, err := ds.db.NamedExec("DELETE FROM Configurations Where CreateAt < :timestamp", map[string]any{"timestamp": thresholdCreatAt}); err != nil {
return errors.Wrap(err, "unable to clean Configurations table")
}

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

@@ -47,7 +47,7 @@ func setupConfigDatabase(t *testing.T, cfg *model.Config, files map[string][]byt
require.NoError(t, err)
id := model.NewId()
_, err = ds.db.NamedExec("INSERT INTO Configurations (Id, Value, CreateAt, Active) VALUES(:Id, :Value, :CreateAt, TRUE)", map[string]interface{}{
_, err = ds.db.NamedExec("INSERT INTO Configurations (Id, Value, CreateAt, Active) VALUES(:Id, :Value, :CreateAt, TRUE)", map[string]any{
"Id": id,
"Value": cfgData,
"CreateAt": model.GetMillis(),
@@ -55,7 +55,7 @@ func setupConfigDatabase(t *testing.T, cfg *model.Config, files map[string][]byt
require.NoError(t, err)
for name, data := range files {
params := map[string]interface{}{
params := map[string]any{
"name": name,
"data": data,
"create_at": model.GetMillis(),
@@ -268,7 +268,7 @@ func TestDatabaseStoreGetEnvironmentOverrides(t *testing.T) {
defer ds.Close()
assert.Equal(t, "http://override", *ds.Get().ServiceSettings.SiteURL)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"SiteURL": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"SiteURL": true}}, ds.GetEnvironmentOverrides())
})
t.Run("get override for a string variable with a custom default value", func(t *testing.T) {
@@ -291,7 +291,7 @@ func TestDatabaseStoreGetEnvironmentOverrides(t *testing.T) {
// environment override should take priority over the custom default value
assert.Equal(t, "http://override", *ds.Get().ServiceSettings.SiteURL)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"SiteURL": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"SiteURL": true}}, ds.GetEnvironmentOverrides())
})
t.Run("get override for a bool variable", func(t *testing.T) {
@@ -313,7 +313,7 @@ func TestDatabaseStoreGetEnvironmentOverrides(t *testing.T) {
defer ds.Close()
assert.Equal(t, true, *ds.Get().PluginSettings.EnableUploads)
assert.Equal(t, map[string]interface{}{"PluginSettings": map[string]interface{}{"EnableUploads": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"PluginSettings": map[string]any{"EnableUploads": true}}, ds.GetEnvironmentOverrides())
})
t.Run("get override for an int variable", func(t *testing.T) {
@@ -335,7 +335,7 @@ func TestDatabaseStoreGetEnvironmentOverrides(t *testing.T) {
defer ds.Close()
assert.Equal(t, 3000, *ds.Get().TeamSettings.MaxUsersPerTeam)
assert.Equal(t, map[string]interface{}{"TeamSettings": map[string]interface{}{"MaxUsersPerTeam": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"TeamSettings": map[string]any{"MaxUsersPerTeam": true}}, ds.GetEnvironmentOverrides())
})
t.Run("get override for an int64 variable", func(t *testing.T) {
@@ -357,7 +357,7 @@ func TestDatabaseStoreGetEnvironmentOverrides(t *testing.T) {
defer ds.Close()
assert.Equal(t, int64(123456), *ds.Get().ServiceSettings.TLSStrictTransportMaxAge)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"TLSStrictTransportMaxAge": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"TLSStrictTransportMaxAge": true}}, ds.GetEnvironmentOverrides())
})
t.Run("get override for a slice variable - one value", func(t *testing.T) {
@@ -379,7 +379,7 @@ func TestDatabaseStoreGetEnvironmentOverrides(t *testing.T) {
defer ds.Close()
assert.Equal(t, []string{"user:pwd@db:5432/test-db"}, ds.Get().SqlSettings.DataSourceReplicas)
assert.Equal(t, map[string]interface{}{"SqlSettings": map[string]interface{}{"DataSourceReplicas": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"SqlSettings": map[string]any{"DataSourceReplicas": true}}, ds.GetEnvironmentOverrides())
})
t.Run("get override for a slice variable - three values", func(t *testing.T) {
@@ -404,7 +404,7 @@ func TestDatabaseStoreGetEnvironmentOverrides(t *testing.T) {
defer ds.Close()
assert.Equal(t, []string{"user:pwd@db:5432/test-db", "user:pwd@db2:5433/test-db2", "user:pwd@db3:5434/test-db3"}, ds.Get().SqlSettings.DataSourceReplicas)
assert.Equal(t, map[string]interface{}{"SqlSettings": map[string]interface{}{"DataSourceReplicas": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"SqlSettings": map[string]any{"DataSourceReplicas": true}}, ds.GetEnvironmentOverrides())
})
}
@@ -679,7 +679,7 @@ func TestDatabaseStoreLoad(t *testing.T) {
err = ds.Load()
require.NoError(t, err)
assert.Equal(t, "http://override", *ds.Get().ServiceSettings.SiteURL)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"SiteURL": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"SiteURL": true}}, ds.GetEnvironmentOverrides())
})
t.Run("do not persist environment variables - string", func(t *testing.T) {
@@ -697,7 +697,7 @@ func TestDatabaseStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "http://overridePersistEnvVariables", *ds.Get().ServiceSettings.SiteURL)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"SiteURL": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"SiteURL": true}}, ds.GetEnvironmentOverrides())
// check that in DB config does not include overwritten variable
_, actualConfig := getActualDatabaseConfig(t)
assert.Equal(t, "http://minimal", *actualConfig.ServiceSettings.SiteURL)
@@ -720,7 +720,7 @@ func TestDatabaseStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, true, *ds.Get().PluginSettings.EnableUploads)
assert.Equal(t, map[string]interface{}{"PluginSettings": map[string]interface{}{"EnableUploads": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"PluginSettings": map[string]any{"EnableUploads": true}}, ds.GetEnvironmentOverrides())
// check that in DB config does not include overwritten variable
_, actualConfig := getActualDatabaseConfig(t)
assert.Equal(t, false, *actualConfig.PluginSettings.EnableUploads)
@@ -743,7 +743,7 @@ func TestDatabaseStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, 3000, *ds.Get().TeamSettings.MaxUsersPerTeam)
assert.Equal(t, map[string]interface{}{"TeamSettings": map[string]interface{}{"MaxUsersPerTeam": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"TeamSettings": map[string]any{"MaxUsersPerTeam": true}}, ds.GetEnvironmentOverrides())
// check that in DB config does not include overwritten variable
_, actualConfig := getActualDatabaseConfig(t)
assert.Equal(t, model.TeamSettingsDefaultMaxUsersPerTeam, *actualConfig.TeamSettings.MaxUsersPerTeam)
@@ -766,7 +766,7 @@ func TestDatabaseStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, int64(123456), *ds.Get().ServiceSettings.TLSStrictTransportMaxAge)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"TLSStrictTransportMaxAge": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"TLSStrictTransportMaxAge": true}}, ds.GetEnvironmentOverrides())
// check that in DB config does not include overwritten variable
_, actualConfig := getActualDatabaseConfig(t)
assert.Equal(t, int64(63072000), *actualConfig.ServiceSettings.TLSStrictTransportMaxAge)
@@ -789,7 +789,7 @@ func TestDatabaseStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, []string{"user:pwd@db:5432/test-db"}, ds.Get().SqlSettings.DataSourceReplicas)
assert.Equal(t, map[string]interface{}{"SqlSettings": map[string]interface{}{"DataSourceReplicas": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"SqlSettings": map[string]any{"DataSourceReplicas": true}}, ds.GetEnvironmentOverrides())
// check that in DB config does not include overwritten variable
_, actualConfig := getActualDatabaseConfig(t)
assert.Equal(t, []string{}, actualConfig.SqlSettings.DataSourceReplicas)
@@ -814,7 +814,7 @@ func TestDatabaseStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, []string{"user:pwd@db:5432/test-db"}, ds.Get().SqlSettings.DataSourceReplicas)
assert.Equal(t, map[string]interface{}{"SqlSettings": map[string]interface{}{"DataSourceReplicas": true}}, ds.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"SqlSettings": map[string]any{"DataSourceReplicas": true}}, ds.GetEnvironmentOverrides())
// check that in DB config does not include overwritten variable
_, actualConfig := getActualDatabaseConfig(t)
assert.Equal(t, []string{"user:pwd@db:5432/test-db", "user:pwd@db2:5433/test-db2", "user:pwd@db3:5434/test-db3"}, actualConfig.SqlSettings.DataSourceReplicas)
@@ -833,7 +833,7 @@ func TestDatabaseStoreLoad(t *testing.T) {
truncateTables(t)
id := model.NewId()
_, err = mainHelper.GetSQLStore().GetMasterX().NamedExec("INSERT INTO Configurations (Id, Value, CreateAt, Active) VALUES(:id, :value, :createat, TRUE)", map[string]interface{}{
_, err = mainHelper.GetSQLStore().GetMasterX().NamedExec("INSERT INTO Configurations (Id, Value, CreateAt, Active) VALUES(:id, :value, :createat, TRUE)", map[string]any{
"id": id,
"value": cfgData,
"createat": model.GetMillis(),
@@ -1140,7 +1140,7 @@ func TestCleanUp(t *testing.T) {
// first 2 (0 and 1) will be within a month constraint, others will be older than
// a month hence we expect 3 configurations to be removed from the database.
m := -1 * i * 24 * 20
params := map[string]interface{}{
params := map[string]any{
"id": model.NewId(),
"value": string(b),
"create_at": model.GetMillisForTime(now.Add(time.Duration(m) * time.Hour)),

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

@@ -13,9 +13,9 @@ import (
type ConfigDiffs []ConfigDiff
type ConfigDiff struct {
Path string `json:"path"`
BaseVal interface{} `json:"base_val"`
ActualVal interface{} `json:"actual_val"`
Path string `json:"path"`
BaseVal any `json:"base_val"`
ActualVal any `json:"actual_val"`
}
var configSensitivePaths = map[string]bool{

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

@@ -511,7 +511,7 @@ func TestDiffSanitized(t *testing.T) {
defaultConfigGen(),
func() *model.Config {
cfg := defaultConfigGen()
cfg.PluginSettings.Plugins = map[string]map[string]interface{}{
cfg.PluginSettings.Plugins = map[string]map[string]any{
"com.mattermost.newplugin": {
"key": true,
},
@@ -915,7 +915,7 @@ func TestDiff(t *testing.T) {
"map type change",
func() *model.Config {
cfg := defaultConfigGen()
cfg.PluginSettings.Plugins = map[string]map[string]interface{}{
cfg.PluginSettings.Plugins = map[string]map[string]any{
"com.mattermost.newplugin": {
"key": true,
},
@@ -924,7 +924,7 @@ func TestDiff(t *testing.T) {
}(),
func() *model.Config {
cfg := defaultConfigGen()
cfg.PluginSettings.Plugins = map[string]map[string]interface{}{
cfg.PluginSettings.Plugins = map[string]map[string]any{
"com.mattermost.newplugin": {
"key": "string",
},
@@ -934,15 +934,15 @@ func TestDiff(t *testing.T) {
ConfigDiffs{
{
Path: "PluginSettings.Plugins",
BaseVal: func() interface{} {
return map[string]map[string]interface{}{
BaseVal: func() any {
return map[string]map[string]any{
"com.mattermost.newplugin": {
"key": true,
},
}
}(),
ActualVal: func() interface{} {
return map[string]map[string]interface{}{
ActualVal: func() any {
return map[string]map[string]any{
"com.mattermost.newplugin": {
"key": "string",
},

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

@@ -32,7 +32,7 @@ func (e *emitter) RemoveListener(id string) {
// invokeConfigListeners synchronously notifies all listeners about the configuration change.
func (e *emitter) invokeConfigListeners(oldCfg, newCfg *model.Config) {
e.listeners.Range(func(key, value interface{}) bool {
e.listeners.Range(func(key, value any) bool {
listener := value.(Listener)
listener(oldCfg, newCfg)
return true
@@ -58,7 +58,7 @@ func (e *logSrcEmitter) RemoveListener(id string) {
// invokeConfigListeners synchronously notifies all listeners about the configuration change.
func (e *logSrcEmitter) invokeConfigListeners(oldCfg, newCfg mlog.LoggerConfiguration) {
e.listeners.Range(func(key, value interface{}) bool {
e.listeners.Range(func(key, value any) bool {
listener := value.(LogSrcListener)
listener(oldCfg, newCfg)
return true

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

@@ -87,19 +87,19 @@ func applyEnvironmentMap(inputConfig *model.Config, env map[string]string) *mode
return appliedConfig
}
// generateEnvironmentMap creates a map[string]interface{} containing true at the leaves mirroring the
// generateEnvironmentMap creates a map[string]any containing true at the leaves mirroring the
// configuration structure so the client can know which env variables are overridden
func generateEnvironmentMap(env map[string]string, filter func(reflect.StructField) bool) map[string]interface{} {
func generateEnvironmentMap(env map[string]string, filter func(reflect.StructField) bool) map[string]any {
rType := reflect.TypeOf(model.Config{})
return generateEnvironmentMapWithBaseKey(env, rType, "MM", filter)
}
func generateEnvironmentMapWithBaseKey(env map[string]string, rType reflect.Type, base string, filter func(reflect.StructField) bool) map[string]interface{} {
func generateEnvironmentMapWithBaseKey(env map[string]string, rType reflect.Type, base string, filter func(reflect.StructField) bool) map[string]any {
if rType.Kind() != reflect.Struct {
return nil
}
mapRepresentation := make(map[string]interface{})
mapRepresentation := make(map[string]any)
for i := 0; i < rType.NumField(); i++ {
rField := rType.Field(i)
if filter != nil && !filter(rField) {
@@ -126,7 +126,7 @@ func generateEnvironmentMapWithBaseKey(env map[string]string, rType reflect.Type
// removeEnvOverrides returns a new config without the given environment overrides.
// If a config variable has an environment override, that variable is set to the value that was
// read from the store.
func removeEnvOverrides(cfg, cfgWithoutEnv *model.Config, envOverrides map[string]interface{}) *model.Config {
func removeEnvOverrides(cfg, cfgWithoutEnv *model.Config, envOverrides map[string]any) *model.Config {
paths := getPaths(envOverrides)
newCfg := cfg.Clone()
for _, path := range paths {
@@ -142,13 +142,13 @@ func removeEnvOverrides(cfg, cfgWithoutEnv *model.Config, envOverrides map[strin
// getPaths turns a nested map into a slice of paths describing the keys of the map. Eg:
// map[string]map[string]map[string]bool{"this":{"is first":{"path":true}, "is second":{"path":true}))) is turned into:
// [][]string{{"this", "is first", "path"}, {"this", "is second", "path"}}
func getPaths(m map[string]interface{}) [][]string {
func getPaths(m map[string]any) [][]string {
return getPathsRec(m, nil)
}
// getPathsRec assembles the paths (see `getPaths` above)
func getPathsRec(src interface{}, curPath []string) [][]string {
if srcMap, ok := src.(map[string]interface{}); ok {
func getPathsRec(src any, curPath []string) [][]string {
if srcMap, ok := src.(map[string]any); ok {
paths := [][]string{}
for k, v := range srcMap {
paths = append(paths, getPathsRec(v, append(curPath, k))...)
@@ -161,10 +161,10 @@ func getPathsRec(src interface{}, curPath []string) [][]string {
// getVal walks `src` (here it starts with a model.Config, then recurses into its leaves)
// and returns the reflect.Value of the leaf at the end `path`
func getVal(src interface{}, path []string) reflect.Value {
func getVal(src any, path []string) reflect.Value {
var val reflect.Value
// If we recursed on a Value, we already have it. If we're calling on an interface{}, get the Value.
// If we recursed on a Value, we already have it. If we're calling on an any, get the Value.
switch v := src.(type) {
case reflect.Value:
val = v

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

@@ -295,7 +295,7 @@ func TestFileStoreGetEnvironmentOverrides(t *testing.T) {
defer fs.Close()
assert.Equal(t, "http://override", *fs.Get().ServiceSettings.SiteURL)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"SiteURL": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"SiteURL": true}}, fs.GetEnvironmentOverrides())
})
t.Run("get override for a string variable, with custom defaults", func(t *testing.T) {
@@ -322,7 +322,7 @@ func TestFileStoreGetEnvironmentOverrides(t *testing.T) {
// environment override should take priority over the custom default value
assert.Equal(t, "http://override", *fs.Get().ServiceSettings.SiteURL)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"SiteURL": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"SiteURL": true}}, fs.GetEnvironmentOverrides())
})
t.Run("get override for a bool variable", func(t *testing.T) {
@@ -348,7 +348,7 @@ func TestFileStoreGetEnvironmentOverrides(t *testing.T) {
defer fs.Close()
assert.Equal(t, true, *fs.Get().PluginSettings.EnableUploads)
assert.Equal(t, map[string]interface{}{"PluginSettings": map[string]interface{}{"EnableUploads": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"PluginSettings": map[string]any{"EnableUploads": true}}, fs.GetEnvironmentOverrides())
})
t.Run("get override for an int variable", func(t *testing.T) {
@@ -374,7 +374,7 @@ func TestFileStoreGetEnvironmentOverrides(t *testing.T) {
defer fs.Close()
assert.Equal(t, 3000, *fs.Get().TeamSettings.MaxUsersPerTeam)
assert.Equal(t, map[string]interface{}{"TeamSettings": map[string]interface{}{"MaxUsersPerTeam": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"TeamSettings": map[string]any{"MaxUsersPerTeam": true}}, fs.GetEnvironmentOverrides())
})
t.Run("get override for an int64 variable", func(t *testing.T) {
@@ -400,7 +400,7 @@ func TestFileStoreGetEnvironmentOverrides(t *testing.T) {
defer fs.Close()
assert.Equal(t, int64(123456), *fs.Get().ServiceSettings.TLSStrictTransportMaxAge)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"TLSStrictTransportMaxAge": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"TLSStrictTransportMaxAge": true}}, fs.GetEnvironmentOverrides())
})
t.Run("get override for a slice variable - one value", func(t *testing.T) {
@@ -426,7 +426,7 @@ func TestFileStoreGetEnvironmentOverrides(t *testing.T) {
defer fs.Close()
assert.Equal(t, []string{"user:pwd@db:5432/test-db"}, fs.Get().SqlSettings.DataSourceReplicas)
assert.Equal(t, map[string]interface{}{"SqlSettings": map[string]interface{}{"DataSourceReplicas": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"SqlSettings": map[string]any{"DataSourceReplicas": true}}, fs.GetEnvironmentOverrides())
})
t.Run("get override for a slice variable - three values", func(t *testing.T) {
@@ -452,7 +452,7 @@ func TestFileStoreGetEnvironmentOverrides(t *testing.T) {
defer fs.Close()
assert.Equal(t, []string{"user:pwd@db:5432/test-db", "user:pwd@db2:5433/test-db2", "user:pwd@db3:5434/test-db3"}, fs.Get().SqlSettings.DataSourceReplicas)
assert.Equal(t, map[string]interface{}{"SqlSettings": map[string]interface{}{"DataSourceReplicas": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"SqlSettings": map[string]any{"DataSourceReplicas": true}}, fs.GetEnvironmentOverrides())
})
}
@@ -647,7 +647,7 @@ func TestFileStoreLoad(t *testing.T) {
err := configStore.Load()
require.NoError(t, err)
assert.Equal(t, "http://override", *configStore.Get().ServiceSettings.SiteURL)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"SiteURL": true}}, configStore.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"SiteURL": true}}, configStore.GetEnvironmentOverrides())
})
t.Run("do not persist environment variables - string", func(t *testing.T) {
@@ -669,7 +669,7 @@ func TestFileStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "http://overridePersistEnvVariables", *fs.Get().ServiceSettings.SiteURL)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"SiteURL": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"SiteURL": true}}, fs.GetEnvironmentOverrides())
// check that on disk config does not include overwritten variable
actualConfig := getActualFileConfig(t, path)
assert.Equal(t, "http://minimal", *actualConfig.ServiceSettings.SiteURL)
@@ -694,7 +694,7 @@ func TestFileStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, true, *fs.Get().PluginSettings.EnableUploads)
assert.Equal(t, map[string]interface{}{"PluginSettings": map[string]interface{}{"EnableUploads": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"PluginSettings": map[string]any{"EnableUploads": true}}, fs.GetEnvironmentOverrides())
// check that on disk config does not include overwritten variable
actualConfig := getActualFileConfig(t, path)
assert.Equal(t, false, *actualConfig.PluginSettings.EnableUploads)
@@ -719,7 +719,7 @@ func TestFileStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, 3000, *fs.Get().TeamSettings.MaxUsersPerTeam)
assert.Equal(t, map[string]interface{}{"TeamSettings": map[string]interface{}{"MaxUsersPerTeam": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"TeamSettings": map[string]any{"MaxUsersPerTeam": true}}, fs.GetEnvironmentOverrides())
// check that on disk config does not include overwritten variable
actualConfig := getActualFileConfig(t, path)
assert.Equal(t, model.TeamSettingsDefaultMaxUsersPerTeam, *actualConfig.TeamSettings.MaxUsersPerTeam)
@@ -744,7 +744,7 @@ func TestFileStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, int64(123456), *fs.Get().ServiceSettings.TLSStrictTransportMaxAge)
assert.Equal(t, map[string]interface{}{"ServiceSettings": map[string]interface{}{"TLSStrictTransportMaxAge": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"ServiceSettings": map[string]any{"TLSStrictTransportMaxAge": true}}, fs.GetEnvironmentOverrides())
// check that on disk config does not include overwritten variable
actualConfig := getActualFileConfig(t, path)
assert.Equal(t, int64(63072000), *actualConfig.ServiceSettings.TLSStrictTransportMaxAge)
@@ -769,7 +769,7 @@ func TestFileStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, []string{"user:pwd@db:5432/test-db"}, fs.Get().SqlSettings.DataSourceReplicas)
assert.Equal(t, map[string]interface{}{"SqlSettings": map[string]interface{}{"DataSourceReplicas": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"SqlSettings": map[string]any{"DataSourceReplicas": true}}, fs.GetEnvironmentOverrides())
// check that on disk config does not include overwritten variable
actualConfig := getActualFileConfig(t, path)
assert.Equal(t, []string{}, actualConfig.SqlSettings.DataSourceReplicas)
@@ -796,7 +796,7 @@ func TestFileStoreLoad(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, []string{"user:pwd@db:5432/test-db"}, fs.Get().SqlSettings.DataSourceReplicas)
assert.Equal(t, map[string]interface{}{"SqlSettings": map[string]interface{}{"DataSourceReplicas": true}}, fs.GetEnvironmentOverrides())
assert.Equal(t, map[string]any{"SqlSettings": map[string]any{"DataSourceReplicas": true}}, fs.GetEnvironmentOverrides())
// check that on disk config does not include overwritten variable
actualConfig := getActualFileConfig(t, path)
assert.Equal(t, []string{"user:pwd@db:5432/test-db", "user:pwd@db2:5433/test-db2", "user:pwd@db3:5434/test-db3"}, actualConfig.SqlSettings.DataSourceReplicas)

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

@@ -38,13 +38,13 @@ func TestMloggerConfigFromAuditConfig(t *testing.T) {
assert.ElementsMatch(t, targetCfg.Levels, []mlog.Level{mlog.LvlAuditAPI, mlog.LvlAuditContent, mlog.LvlAuditPerms, mlog.LvlAuditCLI})
// check format options
optionsExpected := map[string]interface{}{
optionsExpected := map[string]any{
"disable_timestamp": false,
"disable_msg": true,
"disable_stacktrace": true,
"disable_level": true,
}
var optionsReceived map[string]interface{}
var optionsReceived map[string]any
err = json.Unmarshal(targetCfg.FormatOptions, &optionsReceived)
require.NoError(t, err, "unmarshal should not fail")
assert.Equal(t, optionsExpected, optionsReceived)

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

@@ -137,13 +137,13 @@ func (s *Store) GetNoEnv() *model.Config {
}
// GetEnvironmentOverrides fetches the configuration fields overridden by environment variables.
func (s *Store) GetEnvironmentOverrides() map[string]interface{} {
func (s *Store) GetEnvironmentOverrides() map[string]any {
return generateEnvironmentMap(GetEnvironment(), nil)
}
// GetEnvironmentOverridesWithFilter fetches the configuration fields overridden by environment variables.
// If filter is not nil and returns false for a struct field, that field will be omitted.
func (s *Store) GetEnvironmentOverridesWithFilter(filter func(reflect.StructField) bool) map[string]interface{} {
func (s *Store) GetEnvironmentOverridesWithFilter(filter func(reflect.StructField) bool) map[string]any {
return generateEnvironmentMap(GetEnvironment(), filter)
}

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

@@ -201,11 +201,11 @@ func stripPassword(dsn, schema string) string {
}
func isJSONMap(data string) bool {
var m map[string]interface{}
var m map[string]any
return json.Unmarshal([]byte(data), &m) == nil
}
func GetValueByPath(path []string, obj interface{}) (interface{}, bool) {
func GetValueByPath(path []string, obj any) (any, bool) {
r := reflect.ValueOf(obj)
var val reflect.Value
if r.Kind() == reflect.Map {