Feature: Allow to install plugins through configuration (#91790)

This commit is contained in:
Andres Martinez Gotor
2024-08-13 16:57:55 +02:00
committed by GitHub
parent b03a709500
commit 9067797eb4
5 changed files with 226 additions and 13 deletions

View File

@@ -198,6 +198,7 @@ type Cfg struct {
HideAngularDeprecation []string
PluginInstallToken string
ForwardHostEnvVars []string
InstallPlugins []InstallPlugin
PluginsCDNURLTemplate string
PluginLogBackendRequests bool
@@ -526,6 +527,11 @@ type Cfg struct {
UnifiedStorage map[string]grafanarest.DualWriterMode
}
type InstallPlugin struct {
ID string
Version string
}
// AddChangePasswordLink returns if login form is disabled or not since
// the same intention can be used to hide both features.
func (cfg *Cfg) AddChangePasswordLink() bool {

View File

@@ -39,6 +39,17 @@ func (cfg *Cfg) readPluginSettings(iniFile *ini.File) error {
cfg.DisablePlugins = util.SplitString(pluginsSection.Key("disable_plugins").MustString(""))
cfg.HideAngularDeprecation = util.SplitString(pluginsSection.Key("hide_angular_deprecation").MustString(""))
cfg.ForwardHostEnvVars = util.SplitString(pluginsSection.Key("forward_host_env_vars").MustString(""))
rawInstallPlugins := util.SplitString(pluginsSection.Key("install").MustString(""))
cfg.InstallPlugins = make([]InstallPlugin, len(rawInstallPlugins))
for i, plugin := range rawInstallPlugins {
parts := strings.Split(plugin, "@")
id := parts[0]
v := ""
if len(parts) == 2 {
v = parts[1]
}
cfg.InstallPlugins[i] = InstallPlugin{id, v}
}
cfg.PluginCatalogURL = pluginsSection.Key("plugin_catalog_url").MustString("https://grafana.com/grafana/plugins/")
cfg.PluginAdminEnabled = pluginsSection.Key("plugin_admin_enabled").MustBool(true)