grafana/pkg/plugins/backendplugin/plugin_settings.go
Marcus Efraimsson 34266cd369
Backend Plugins: Plugin configuration using Grafana config (#23451)
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,
2020-04-14 18:04:27 +02:00

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
}