Plugins: Add forward_host_env_vars setting (#79333)

* Plugins: Add forward_host_env_vars_plugins setting

* Renamed forward_host_env_vars_plugins to forward_host_env_vars

* Add readPluginIDsList

* refactoring

* lint

* Use util.SplitString
This commit is contained in:
Giuseppe Guerra
2023-12-13 10:25:17 +01:00
committed by GitHub
parent 106903b549
commit 0d1d437c86
8 changed files with 82 additions and 64 deletions

View File

@ -11,7 +11,6 @@ import (
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/setting"
)
func TestSetDefaultNavURL(t *testing.T) {
@ -172,34 +171,34 @@ func TestSkipEnvVarsDecorateFunc(t *testing.T) {
t.Run("plugin setting", func(t *testing.T) {
for _, tc := range []struct {
name string
pluginSettings setting.PluginSettings
forwardHostEnvVars []string
expSkipHostEnvVars bool
}{
{
name: "forward_host_env_vars = false should set SkipHostEnvVars to true",
pluginSettings: setting.PluginSettings{pluginID: map[string]string{"forward_host_env_vars": "false"}},
name: "plugin id not present in forwardHostEnvVars should set SkipHostEnvVars to true (empty)",
forwardHostEnvVars: []string{},
expSkipHostEnvVars: true,
},
{
name: "forward_host_env_vars = true should set SkipHostEnvVars to false",
pluginSettings: setting.PluginSettings{pluginID: map[string]string{"forward_host_env_vars": "true"}},
name: "plugin id not present in forwardHostEnvVars should set SkipHostEnvVars to true (other id)",
forwardHostEnvVars: []string{"other-id", "yet-another-id"},
expSkipHostEnvVars: true,
},
{
name: "plugin id in forwardHostEnvVars should set SkipHostEnvVars to false (only)",
forwardHostEnvVars: []string{pluginID},
expSkipHostEnvVars: false,
},
{
name: "invalid forward_host_env_vars should set SkipHostEnvVars to true",
pluginSettings: setting.PluginSettings{pluginID: map[string]string{"forward_host_env_vars": "grilled cheese sandwich with bacon"}},
expSkipHostEnvVars: true,
},
{
name: "forward_host_env_vars absent should set SkipHostEnvVars to true",
pluginSettings: setting.PluginSettings{pluginID: nil},
expSkipHostEnvVars: true,
name: "plugin id in forwardHostEnvVars should set SkipHostEnvVars to false (with other)",
forwardHostEnvVars: []string{"a-plugin", pluginID, "other-id"},
expSkipHostEnvVars: false,
},
} {
t.Run(tc.name, func(t *testing.T) {
f := SkipHostEnvVarsDecorateFunc(&config.Cfg{
Features: featuremgmt.WithFeatures(featuremgmt.FlagPluginsSkipHostEnvVars),
PluginSettings: tc.pluginSettings,
Features: featuremgmt.WithFeatures(featuremgmt.FlagPluginsSkipHostEnvVars),
ForwardHostEnvVars: tc.forwardHostEnvVars,
})
p, err := f(context.Background(), &plugins.Plugin{JSONData: plugins.JSONData{ID: pluginID}})
require.NoError(t, err)