@@ -4,6 +4,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -73,6 +74,11 @@ func applyEnvKey(key, value string, rValueSubject reflect.Value) {
|
|||||||
}
|
}
|
||||||
case reflect.SliceOf(reflect.TypeOf("")).Kind():
|
case reflect.SliceOf(reflect.TypeOf("")).Kind():
|
||||||
rFieldValue.Set(reflect.ValueOf(strings.Split(value, " ")))
|
rFieldValue.Set(reflect.ValueOf(strings.Split(value, " ")))
|
||||||
|
case reflect.Map:
|
||||||
|
target := reflect.New(rFieldValue.Type()).Interface()
|
||||||
|
if err := json.Unmarshal([]byte(value), target); err == nil {
|
||||||
|
rFieldValue.Set(reflect.ValueOf(target).Elem())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,15 +31,54 @@ func TestRemoveEnvOverrides(t *testing.T) {
|
|||||||
expectedConfig *model.Config
|
expectedConfig *model.Config
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "basic override",
|
name: "config override",
|
||||||
inputConfig: modifiedDefault(func(in *model.Config) {
|
inputConfig: modifiedDefault(func(in *model.Config) {
|
||||||
*in.ServiceSettings.TLSMinVer = "1.4"
|
*in.ServiceSettings.TLSMinVer = "1.4"
|
||||||
|
in.PluginSettings.PluginStates = map[string]*model.PluginState{
|
||||||
|
"plugin1": {
|
||||||
|
Enable: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
in.PluginSettings.Plugins = map[string]map[string]interface{}{
|
||||||
|
"com.mattermost.plugin-1": {
|
||||||
|
"key1": "value1",
|
||||||
|
},
|
||||||
|
"com_mattermost_plugin-2": {
|
||||||
|
"key2": "value2",
|
||||||
|
},
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
"MM_SERVICESETTINGS_TLSMINVER": "1.5",
|
"MM_SERVICESETTINGS_TLSMINVER": "1.5",
|
||||||
|
"MM_PLUGINSETTINGS_PLUGINSTATES": `{
|
||||||
|
"plugin1": {
|
||||||
|
"Enable": true
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
"MM_PLUGINSETTINGS_PLUGINS": `{
|
||||||
|
"com.mattermost.plugin-1": {
|
||||||
|
"key1": "other-value"
|
||||||
|
},
|
||||||
|
"com_mattermost_plugin-2": {
|
||||||
|
"key2": "other-value"
|
||||||
|
}
|
||||||
|
}`,
|
||||||
},
|
},
|
||||||
expectedConfig: modifiedDefault(func(in *model.Config) {
|
expectedConfig: modifiedDefault(func(in *model.Config) {
|
||||||
*in.ServiceSettings.TLSMinVer = "1.5"
|
*in.ServiceSettings.TLSMinVer = "1.5"
|
||||||
|
in.PluginSettings.PluginStates = map[string]*model.PluginState{
|
||||||
|
"plugin1": {
|
||||||
|
Enable: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
in.PluginSettings.Plugins = map[string]map[string]interface{}{
|
||||||
|
"com.mattermost.plugin-1": {
|
||||||
|
"key1": "other-value",
|
||||||
|
},
|
||||||
|
"com_mattermost_plugin-2": {
|
||||||
|
"key2": "other-value",
|
||||||
|
},
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -102,6 +141,41 @@ func TestRemoveEnvOverrides(t *testing.T) {
|
|||||||
in.SqlSettings.DataSourceReplicas = []string{"otherthing", "alsothis"}
|
in.SqlSettings.DataSourceReplicas = []string{"otherthing", "alsothis"}
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "complex env settings",
|
||||||
|
inputConfig: modifiedDefault(func(in *model.Config) {
|
||||||
|
}),
|
||||||
|
env: map[string]string{
|
||||||
|
"MM_PLUGINSETTINGS_PLUGINSTATES": `{
|
||||||
|
"com.mattermost.plugin-1": {
|
||||||
|
"enable": true
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
"MM_PLUGINSETTINGS_PLUGINS": `{
|
||||||
|
"com.mattermost.plugin-1": {
|
||||||
|
"key": {
|
||||||
|
"key": "(?P<key>KEY)-(?P<id>\\d{1,6})(?P<comma>[,;]*)",
|
||||||
|
"value": "[$key-$id](https://example.com/?$project-$id)$comma"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
expectedConfig: modifiedDefault(func(in *model.Config) {
|
||||||
|
in.PluginSettings.PluginStates = map[string]*model.PluginState{
|
||||||
|
"com.mattermost.plugin-1": {
|
||||||
|
Enable: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
in.PluginSettings.Plugins = map[string]map[string]interface{}{
|
||||||
|
"com.mattermost.plugin-1": {
|
||||||
|
"key": map[string]interface{}{
|
||||||
|
"key": "(?P<key>KEY)-(?P<id>\\d{1,6})(?P<comma>[,;]*)",
|
||||||
|
"value": "[$key-$id](https://example.com/?$project-$id)$comma",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "bad env",
|
name: "bad env",
|
||||||
inputConfig: modifiedDefault(func(in *model.Config) {
|
inputConfig: modifiedDefault(func(in *model.Config) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user