mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
34266cd369
Enables adding a section `plugin.<plugin id>` and key/value to Grafana configuration file which will be converted and sent as environment variables to the backend plugin. Also sends some additional environment variables, Grafana version (GF_VERSION), Grafana edition (GF_EDITION) and enterprise license path (GF_ENTERPRISE_LICENSE_PATH). Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> Fixes #21515,
40 lines
731 B
Go
40 lines
731 B
Go
package backendplugin
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
type pluginSettings map[string]string
|
|
|
|
func (ps pluginSettings) ToEnv(prefix string, hostEnv []string) []string {
|
|
env := []string{}
|
|
for k, v := range ps {
|
|
env = append(env, fmt.Sprintf("%s_%s=%s", prefix, strings.ToUpper(k), v))
|
|
}
|
|
|
|
env = append(env, hostEnv...)
|
|
|
|
return env
|
|
}
|
|
|
|
func extractPluginSettings(cfg *setting.Cfg) map[string]pluginSettings {
|
|
psMap := map[string]pluginSettings{}
|
|
for pluginID, settings := range cfg.PluginSettings {
|
|
ps := pluginSettings{}
|
|
for k, v := range settings {
|
|
if k == "path" || strings.ToLower(k) == "id" {
|
|
continue
|
|
}
|
|
|
|
ps[k] = v
|
|
}
|
|
|
|
psMap[pluginID] = ps
|
|
}
|
|
|
|
return psMap
|
|
}
|