mirror of
https://github.com/grafana/grafana.git
synced 2024-11-21 16:38:03 -06:00
Plugins: Add hide_angular_deprecation setting (#79296)
* Add plugins.hide_angular_deprecation config ini * Add more tests * Remove the ability to use [plugins.*] hide_angular_deprecation
This commit is contained in:
parent
f040a8321b
commit
f76b9f266e
@ -1533,6 +1533,8 @@ public_key_retrieval_on_startup = false
|
||||
disable_plugins =
|
||||
# Auth token for plugin installations and removal in managed instances
|
||||
install_token =
|
||||
# Comma separated list of plugin ids for which angular deprecation UI should be disabled
|
||||
hide_angular_deprecation =
|
||||
|
||||
#################################### Grafana Live ##########################################
|
||||
[live]
|
||||
|
@ -45,13 +45,14 @@ type Cfg struct {
|
||||
|
||||
Features plugins.FeatureToggles
|
||||
|
||||
AngularSupportEnabled bool
|
||||
AngularSupportEnabled bool
|
||||
HideAngularDeprecation []string
|
||||
}
|
||||
|
||||
func NewCfg(devMode bool, pluginsPath string, pluginSettings setting.PluginSettings, pluginsAllowUnsigned []string,
|
||||
awsAllowedAuthProviders []string, awsAssumeRoleEnabled bool, awsExternalId string, azure *azsettings.AzureSettings, secureSocksDSProxy setting.SecureSocksDSProxySettings,
|
||||
grafanaVersion string, logDatasourceRequests bool, pluginsCDNURLTemplate string, appURL string, appSubURL string, tracing Tracing, features plugins.FeatureToggles, angularSupportEnabled bool,
|
||||
grafanaComURL string, disablePlugins []string) *Cfg {
|
||||
grafanaComURL string, disablePlugins []string, hideAngularDeprecation []string) *Cfg {
|
||||
return &Cfg{
|
||||
log: log.New("plugin.cfg"),
|
||||
PluginsPath: pluginsPath,
|
||||
@ -73,5 +74,6 @@ func NewCfg(devMode bool, pluginsPath string, pluginSettings setting.PluginSetti
|
||||
GrafanaAppSubURL: appSubURL,
|
||||
Features: features,
|
||||
AngularSupportEnabled: angularSupportEnabled,
|
||||
HideAngularDeprecation: hideAngularDeprecation,
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package validation
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
@ -108,6 +109,6 @@ func (a *AngularDetector) Validate(ctx context.Context, p *plugins.Plugin) error
|
||||
return errors.New("angular plugins are not supported")
|
||||
}
|
||||
}
|
||||
p.Angular.HideDeprecation = a.cfg.PluginSettings[p.ID]["hide_angular_deprecation"] == "true"
|
||||
p.Angular.HideDeprecation = slices.Contains(a.cfg.HideAngularDeprecation, p.ID)
|
||||
return nil
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ func ProvideConfig(settingProvider setting.Provider, grafanaCfg *setting.Cfg, fe
|
||||
grafanaCfg.AngularSupportEnabled,
|
||||
grafanaCfg.GrafanaComURL,
|
||||
grafanaCfg.DisablePlugins,
|
||||
grafanaCfg.HideAngularDeprecation,
|
||||
), nil
|
||||
}
|
||||
|
||||
|
@ -1303,25 +1303,21 @@ func TestLoader_HideAngularDeprecation(t *testing.T) {
|
||||
cfg *config.Cfg
|
||||
expHideAngularDeprecation bool
|
||||
}{
|
||||
{name: `without "hide_angular_deprecation" setting`, cfg: &config.Cfg{
|
||||
AngularSupportEnabled: true,
|
||||
PluginSettings: setting.PluginSettings{},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
}},
|
||||
{name: `with "hide_angular_deprecation" = true`, cfg: &config.Cfg{
|
||||
AngularSupportEnabled: true,
|
||||
PluginSettings: setting.PluginSettings{
|
||||
"plugin-id": map[string]string{"hide_angular_deprecation": "true"},
|
||||
},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
}},
|
||||
{name: `with "hide_angular_deprecation" = false`, cfg: &config.Cfg{
|
||||
AngularSupportEnabled: true,
|
||||
PluginSettings: setting.PluginSettings{
|
||||
"plugin-id": map[string]string{"hide_angular_deprecation": "false"},
|
||||
},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
}},
|
||||
{name: "with plugin id in HideAngularDeprecation list", cfg: &config.Cfg{
|
||||
AngularSupportEnabled: true,
|
||||
HideAngularDeprecation: []string{"one-app", "two-panel", "test-datasource", "three-datasource"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
}, expHideAngularDeprecation: true},
|
||||
{name: "without plugin id in HideAngularDeprecation list", cfg: &config.Cfg{
|
||||
AngularSupportEnabled: true,
|
||||
HideAngularDeprecation: []string{"one-app", "two-panel", "three-datasource"},
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
}, expHideAngularDeprecation: false},
|
||||
{name: "with empty HideAngularDeprecation", cfg: &config.Cfg{
|
||||
AngularSupportEnabled: true,
|
||||
HideAngularDeprecation: nil,
|
||||
Features: featuremgmt.WithFeatures(),
|
||||
}, expHideAngularDeprecation: false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
l := newLoaderWithOpts(t, tc.cfg, loaderDepOpts{
|
||||
|
@ -246,6 +246,7 @@ type Cfg struct {
|
||||
PluginForcePublicKeyDownload bool
|
||||
PluginSkipPublicKeyDownload bool
|
||||
DisablePlugins []string
|
||||
HideAngularDeprecation []string
|
||||
PluginInstallToken string
|
||||
|
||||
PluginsCDNURLTemplate string
|
||||
|
@ -48,6 +48,15 @@ func (cfg *Cfg) readPluginSettings(iniFile *ini.File) error {
|
||||
}
|
||||
}
|
||||
|
||||
hideAngularDeprecation := pluginsSection.Key("hide_angular_deprecation").MustString("")
|
||||
for _, id := range strings.Split(hideAngularDeprecation, ",") {
|
||||
id = strings.TrimSpace(id)
|
||||
if id == "" {
|
||||
continue
|
||||
}
|
||||
cfg.HideAngularDeprecation = append(cfg.HideAngularDeprecation, id)
|
||||
}
|
||||
|
||||
cfg.PluginCatalogURL = pluginsSection.Key("plugin_catalog_url").MustString("https://grafana.com/grafana/plugins/")
|
||||
cfg.PluginAdminEnabled = pluginsSection.Key("plugin_admin_enabled").MustBool(true)
|
||||
cfg.PluginAdminExternalManageEnabled = pluginsSection.Key("plugin_admin_external_manage_enabled").MustBool(false)
|
||||
|
@ -43,18 +43,23 @@ func TestPluginSettings(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_readPluginSettings(t *testing.T) {
|
||||
t.Run("should parse disable_plugins", func(t *testing.T) {
|
||||
t.Run("should parse plugin ids", func(t *testing.T) {
|
||||
cfg := NewCfg()
|
||||
sec, err := cfg.Raw.NewSection("plugins")
|
||||
require.NoError(t, err)
|
||||
_, err = sec.NewKey("disable_plugins", "plugin1,plugin2")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = sec.NewKey("plugin_catalog_hidden_plugins", "plugin3")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = sec.NewKey("hide_angular_deprecation", "a,b,c")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = cfg.readPluginSettings(cfg.Raw)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []string{"plugin1", "plugin2"}, cfg.DisablePlugins)
|
||||
require.Equal(t, []string{"plugin3", "plugin1", "plugin2"}, cfg.PluginCatalogHiddenPlugins)
|
||||
require.Equal(t, []string{"a", "b", "c"}, cfg.HideAngularDeprecation)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user