2023-05-24 07:02:14 -05:00
|
|
|
package envvars
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2023-12-14 05:48:22 -06:00
|
|
|
"slices"
|
2023-09-22 06:56:48 -05:00
|
|
|
"sort"
|
2023-05-24 07:02:14 -05:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana-aws-sdk/pkg/awsds"
|
|
|
|
"github.com/grafana/grafana-azure-sdk-go/azsettings"
|
2023-11-02 07:26:16 -05:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
2023-05-24 07:02:14 -05:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/proxy"
|
2023-09-21 04:33:31 -05:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/experimental/featuretoggles"
|
2024-02-01 04:58:24 -06:00
|
|
|
|
2023-05-24 07:02:14 -05:00
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
2023-09-28 05:18:09 -05:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/auth"
|
2023-05-24 07:02:14 -05:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/config"
|
2024-01-10 05:25:54 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
2023-09-21 04:33:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
customConfigPrefix = "GF_PLUGIN"
|
2023-05-24 07:02:14 -05:00
|
|
|
)
|
|
|
|
|
2023-11-15 11:09:14 -06:00
|
|
|
// allowedHostEnvVarNames is the list of environment variables that can be passed from Grafana's process to the
|
|
|
|
// plugin's process
|
|
|
|
var allowedHostEnvVarNames = []string{
|
|
|
|
// Env vars used by net/http (Go stdlib) for http/https proxy
|
|
|
|
// https://github.com/golang/net/blob/fbaf41277f28102c36926d1368dafbe2b54b4c1d/http/httpproxy/proxy.go#L91-L93
|
|
|
|
"HTTP_PROXY",
|
|
|
|
"http_proxy",
|
|
|
|
"HTTPS_PROXY",
|
|
|
|
"https_proxy",
|
|
|
|
"NO_PROXY",
|
|
|
|
"no_proxy",
|
|
|
|
}
|
|
|
|
|
2023-05-24 07:02:14 -05:00
|
|
|
type Provider interface {
|
2023-08-14 07:17:54 -05:00
|
|
|
Get(ctx context.Context, p *plugins.Plugin) []string
|
2023-05-24 07:02:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type Service struct {
|
|
|
|
cfg *config.Cfg
|
|
|
|
license plugins.Licensing
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewProvider(cfg *config.Cfg, license plugins.Licensing) *Service {
|
|
|
|
return &Service{
|
|
|
|
cfg: cfg,
|
|
|
|
license: license,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-25 08:01:54 -05:00
|
|
|
func (s *Service) Get(ctx context.Context, p *plugins.Plugin) []string {
|
2023-05-24 07:02:14 -05:00
|
|
|
hostEnv := []string{
|
|
|
|
fmt.Sprintf("GF_VERSION=%s", s.cfg.BuildVersion),
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.license != nil {
|
|
|
|
hostEnv = append(
|
|
|
|
hostEnv,
|
|
|
|
fmt.Sprintf("GF_EDITION=%s", s.license.Edition()),
|
|
|
|
fmt.Sprintf("GF_ENTERPRISE_LICENSE_PATH=%s", s.license.Path()),
|
|
|
|
fmt.Sprintf("GF_ENTERPRISE_APP_URL=%s", s.license.AppURL()),
|
|
|
|
)
|
|
|
|
hostEnv = append(hostEnv, s.license.Environment()...)
|
|
|
|
}
|
|
|
|
|
2023-06-26 09:38:43 -05:00
|
|
|
if p.ExternalService != nil {
|
|
|
|
hostEnv = append(
|
|
|
|
hostEnv,
|
|
|
|
fmt.Sprintf("GF_APP_URL=%s", s.cfg.GrafanaAppURL),
|
|
|
|
fmt.Sprintf("GF_PLUGIN_APP_CLIENT_ID=%s", p.ExternalService.ClientID),
|
|
|
|
fmt.Sprintf("GF_PLUGIN_APP_CLIENT_SECRET=%s", p.ExternalService.ClientSecret),
|
|
|
|
)
|
2023-10-17 09:21:23 -05:00
|
|
|
if p.ExternalService.PrivateKey != "" {
|
|
|
|
hostEnv = append(hostEnv, fmt.Sprintf("GF_PLUGIN_APP_PRIVATE_KEY=%s", p.ExternalService.PrivateKey))
|
|
|
|
}
|
2023-06-26 09:38:43 -05:00
|
|
|
}
|
|
|
|
|
2023-08-25 08:01:54 -05:00
|
|
|
hostEnv = append(hostEnv, s.featureToggleEnableVar(ctx)...)
|
2023-05-24 07:02:14 -05:00
|
|
|
hostEnv = append(hostEnv, s.awsEnvVars()...)
|
|
|
|
hostEnv = append(hostEnv, s.secureSocksProxyEnvVars()...)
|
|
|
|
hostEnv = append(hostEnv, azsettings.WriteToEnvStr(s.cfg.Azure)...)
|
|
|
|
hostEnv = append(hostEnv, s.tracingEnvVars(p)...)
|
|
|
|
|
2023-11-17 08:12:05 -06:00
|
|
|
// If SkipHostEnvVars is enabled, get some allowed variables from the current process and pass
|
|
|
|
// them down to the plugin. If the flag is not set, do not add anything else because ALL env vars
|
2023-11-15 11:09:14 -06:00
|
|
|
// from the current process (os.Environ()) will be forwarded to the plugin's process by go-plugin
|
2023-11-17 08:12:05 -06:00
|
|
|
if p.SkipHostEnvVars {
|
2023-11-15 11:09:14 -06:00
|
|
|
hostEnv = append(hostEnv, s.allowedHostEnvVars()...)
|
|
|
|
}
|
|
|
|
|
2023-09-21 04:33:31 -05:00
|
|
|
ev := getPluginSettings(p.ID, s.cfg).asEnvVar(customConfigPrefix, hostEnv...)
|
2023-11-15 11:09:14 -06:00
|
|
|
|
2023-08-14 07:17:54 -05:00
|
|
|
return ev
|
2023-05-24 07:02:14 -05:00
|
|
|
}
|
|
|
|
|
2023-09-21 04:33:31 -05:00
|
|
|
// GetConfigMap returns a map of configuration that should be passed in a plugin request.
|
2024-02-21 04:32:10 -06:00
|
|
|
//
|
|
|
|
//nolint:gocyclo
|
2023-12-14 05:48:22 -06:00
|
|
|
func (s *Service) GetConfigMap(ctx context.Context, pluginID string, _ *auth.ExternalService) map[string]string {
|
2023-09-21 04:33:31 -05:00
|
|
|
m := make(map[string]string)
|
|
|
|
|
2023-11-02 07:26:16 -05:00
|
|
|
if s.cfg.GrafanaAppURL != "" {
|
|
|
|
m[backend.AppURL] = s.cfg.GrafanaAppURL
|
|
|
|
}
|
2024-02-01 04:58:24 -06:00
|
|
|
if s.cfg.ConcurrentQueryCount != 0 {
|
|
|
|
m[backend.ConcurrentQueryCount] = strconv.Itoa(s.cfg.ConcurrentQueryCount)
|
|
|
|
}
|
2023-11-02 07:26:16 -05:00
|
|
|
|
2024-02-21 04:32:10 -06:00
|
|
|
if s.cfg.UserFacingDefaultError != "" {
|
|
|
|
m[backend.UserFacingDefaultError] = s.cfg.UserFacingDefaultError
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.cfg.DataProxyRowLimit != 0 {
|
|
|
|
m[backend.SQLRowLimit] = strconv.FormatInt(s.cfg.DataProxyRowLimit, 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
m[backend.SQLMaxOpenConnsDefault] = strconv.Itoa(s.cfg.SQLDatasourceMaxOpenConnsDefault)
|
|
|
|
m[backend.SQLMaxIdleConnsDefault] = strconv.Itoa(s.cfg.SQLDatasourceMaxIdleConnsDefault)
|
|
|
|
m[backend.SQLMaxConnLifetimeSecondsDefault] = strconv.Itoa(s.cfg.SQLDatasourceMaxConnLifetimeDefault)
|
|
|
|
|
2023-09-21 04:33:31 -05:00
|
|
|
// TODO add support via plugin SDK
|
2024-02-01 04:58:24 -06:00
|
|
|
// if externalService != nil {
|
2023-09-21 04:33:31 -05:00
|
|
|
// m[oauthtokenretriever.AppURL] = s.cfg.GrafanaAppURL
|
|
|
|
// m[oauthtokenretriever.AppClientID] = externalService.ClientID
|
|
|
|
// m[oauthtokenretriever.AppClientSecret] = externalService.ClientSecret
|
|
|
|
// m[oauthtokenretriever.AppPrivateKey] = externalService.PrivateKey
|
2024-02-01 04:58:24 -06:00
|
|
|
// }
|
2023-09-21 04:33:31 -05:00
|
|
|
|
|
|
|
if s.cfg.Features != nil {
|
|
|
|
enabledFeatures := s.cfg.Features.GetEnabled(ctx)
|
|
|
|
if len(enabledFeatures) > 0 {
|
|
|
|
features := make([]string, 0, len(enabledFeatures))
|
|
|
|
for feat := range enabledFeatures {
|
|
|
|
features = append(features, feat)
|
|
|
|
}
|
2023-09-22 06:56:48 -05:00
|
|
|
sort.Strings(features)
|
2023-09-21 04:33:31 -05:00
|
|
|
m[featuretoggles.EnabledFeatures] = strings.Join(features, ",")
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 12:59:32 -06:00
|
|
|
|
|
|
|
if slices.Contains[[]string, string](s.cfg.AWSForwardSettingsPlugins, pluginID) {
|
|
|
|
if !s.cfg.AWSAssumeRoleEnabled {
|
|
|
|
m[awsds.AssumeRoleEnabledEnvVarKeyName] = "false"
|
|
|
|
}
|
|
|
|
if len(s.cfg.AWSAllowedAuthProviders) > 0 {
|
|
|
|
m[awsds.AllowedAuthProvidersEnvVarKeyName] = strings.Join(s.cfg.AWSAllowedAuthProviders, ",")
|
|
|
|
}
|
|
|
|
if s.cfg.AWSExternalId != "" {
|
|
|
|
m[awsds.GrafanaAssumeRoleExternalIdKeyName] = s.cfg.AWSExternalId
|
|
|
|
}
|
|
|
|
if s.cfg.AWSSessionDuration != "" {
|
|
|
|
m[awsds.SessionDurationEnvVarKeyName] = s.cfg.AWSSessionDuration
|
|
|
|
}
|
|
|
|
if s.cfg.AWSListMetricsPageLimit != "" {
|
|
|
|
m[awsds.ListMetricsPageLimitKeyName] = s.cfg.AWSListMetricsPageLimit
|
|
|
|
}
|
|
|
|
}
|
2023-09-21 04:33:31 -05:00
|
|
|
|
|
|
|
if s.cfg.ProxySettings.Enabled {
|
|
|
|
m[proxy.PluginSecureSocksProxyEnabled] = "true"
|
|
|
|
m[proxy.PluginSecureSocksProxyClientCert] = s.cfg.ProxySettings.ClientCert
|
|
|
|
m[proxy.PluginSecureSocksProxyClientKey] = s.cfg.ProxySettings.ClientKey
|
|
|
|
m[proxy.PluginSecureSocksProxyRootCACert] = s.cfg.ProxySettings.RootCA
|
|
|
|
m[proxy.PluginSecureSocksProxyProxyAddress] = s.cfg.ProxySettings.ProxyAddress
|
|
|
|
m[proxy.PluginSecureSocksProxyServerName] = s.cfg.ProxySettings.ServerName
|
2023-12-14 09:16:32 -06:00
|
|
|
m[proxy.PluginSecureSocksProxyAllowInsecure] = strconv.FormatBool(s.cfg.ProxySettings.AllowInsecure)
|
2023-09-21 04:33:31 -05:00
|
|
|
}
|
|
|
|
|
2023-12-14 05:48:22 -06:00
|
|
|
// Settings here will be extracted by grafana-azure-sdk-go from the plugin context
|
2024-02-05 06:36:33 -06:00
|
|
|
if s.cfg.AzureAuthEnabled {
|
|
|
|
m[azsettings.AzureAuthEnabled] = strconv.FormatBool(s.cfg.AzureAuthEnabled)
|
|
|
|
}
|
2023-12-14 05:48:22 -06:00
|
|
|
azureSettings := s.cfg.Azure
|
|
|
|
if azureSettings != nil && slices.Contains[[]string, string](azureSettings.ForwardSettingsPlugins, pluginID) {
|
|
|
|
if azureSettings.Cloud != "" {
|
|
|
|
m[azsettings.AzureCloud] = azureSettings.Cloud
|
|
|
|
}
|
|
|
|
|
|
|
|
if azureSettings.ManagedIdentityEnabled {
|
|
|
|
m[azsettings.ManagedIdentityEnabled] = "true"
|
|
|
|
|
|
|
|
if azureSettings.ManagedIdentityClientId != "" {
|
|
|
|
m[azsettings.ManagedIdentityClientID] = azureSettings.ManagedIdentityClientId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if azureSettings.UserIdentityEnabled {
|
|
|
|
m[azsettings.UserIdentityEnabled] = "true"
|
|
|
|
|
|
|
|
if azureSettings.UserIdentityTokenEndpoint != nil {
|
|
|
|
if azureSettings.UserIdentityTokenEndpoint.TokenUrl != "" {
|
|
|
|
m[azsettings.UserIdentityTokenURL] = azureSettings.UserIdentityTokenEndpoint.TokenUrl
|
|
|
|
}
|
|
|
|
if azureSettings.UserIdentityTokenEndpoint.ClientId != "" {
|
|
|
|
m[azsettings.UserIdentityClientID] = azureSettings.UserIdentityTokenEndpoint.ClientId
|
|
|
|
}
|
|
|
|
if azureSettings.UserIdentityTokenEndpoint.ClientSecret != "" {
|
|
|
|
m[azsettings.UserIdentityClientSecret] = azureSettings.UserIdentityTokenEndpoint.ClientSecret
|
|
|
|
}
|
|
|
|
if azureSettings.UserIdentityTokenEndpoint.UsernameAssertion {
|
|
|
|
m[azsettings.UserIdentityAssertion] = "username"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if azureSettings.WorkloadIdentityEnabled {
|
|
|
|
m[azsettings.WorkloadIdentityEnabled] = "true"
|
|
|
|
|
|
|
|
if azureSettings.WorkloadIdentitySettings != nil {
|
|
|
|
if azureSettings.WorkloadIdentitySettings.ClientId != "" {
|
|
|
|
m[azsettings.WorkloadIdentityClientID] = azureSettings.WorkloadIdentitySettings.ClientId
|
|
|
|
}
|
|
|
|
if azureSettings.WorkloadIdentitySettings.TenantId != "" {
|
|
|
|
m[azsettings.WorkloadIdentityTenantID] = azureSettings.WorkloadIdentitySettings.TenantId
|
|
|
|
}
|
|
|
|
if azureSettings.WorkloadIdentitySettings.TokenFile != "" {
|
|
|
|
m[azsettings.WorkloadIdentityTokenFile] = azureSettings.WorkloadIdentitySettings.TokenFile
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-21 04:33:31 -05:00
|
|
|
|
|
|
|
// TODO add support via plugin SDK
|
2024-02-01 04:58:24 -06:00
|
|
|
// ps := getPluginSettings(pluginID, s.cfg)
|
|
|
|
// for k, v := range ps {
|
2023-09-21 04:33:31 -05:00
|
|
|
// m[fmt.Sprintf("%s_%s", customConfigPrefix, strings.ToUpper(k))] = v
|
2024-02-01 04:58:24 -06:00
|
|
|
// }
|
2023-09-21 04:33:31 -05:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2023-05-24 07:02:14 -05:00
|
|
|
func (s *Service) tracingEnvVars(plugin *plugins.Plugin) []string {
|
2024-01-10 05:25:54 -06:00
|
|
|
pluginTracingEnabled := s.cfg.Features != nil && s.cfg.Features.IsEnabledGlobally(featuremgmt.FlagEnablePluginsTracingByDefault)
|
|
|
|
if v, exists := s.cfg.PluginSettings[plugin.ID]["tracing"]; exists && !pluginTracingEnabled {
|
2023-05-24 07:02:14 -05:00
|
|
|
pluginTracingEnabled = v == "true"
|
|
|
|
}
|
|
|
|
if !s.cfg.Tracing.IsEnabled() || !pluginTracingEnabled {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-07 10:22:43 -05:00
|
|
|
vars := []string{
|
|
|
|
fmt.Sprintf("GF_INSTANCE_OTLP_ADDRESS=%s", s.cfg.Tracing.OpenTelemetry.Address),
|
|
|
|
fmt.Sprintf("GF_INSTANCE_OTLP_PROPAGATION=%s", s.cfg.Tracing.OpenTelemetry.Propagation),
|
2023-11-10 07:56:08 -06:00
|
|
|
|
|
|
|
fmt.Sprintf("GF_INSTANCE_OTLP_SAMPLER_TYPE=%s", s.cfg.Tracing.OpenTelemetry.Sampler),
|
|
|
|
fmt.Sprintf("GF_INSTANCE_OTLP_SAMPLER_PARAM=%.6f", s.cfg.Tracing.OpenTelemetry.SamplerParam),
|
|
|
|
fmt.Sprintf("GF_INSTANCE_OTLP_SAMPLER_REMOTE_URL=%s", s.cfg.Tracing.OpenTelemetry.SamplerRemoteURL),
|
2023-06-07 10:22:43 -05:00
|
|
|
}
|
2023-05-24 07:02:14 -05:00
|
|
|
if plugin.Info.Version != "" {
|
|
|
|
vars = append(vars, fmt.Sprintf("GF_PLUGIN_VERSION=%s", plugin.Info.Version))
|
|
|
|
}
|
2023-06-07 10:22:43 -05:00
|
|
|
return vars
|
2023-05-24 07:02:14 -05:00
|
|
|
}
|
|
|
|
|
2023-08-25 08:01:54 -05:00
|
|
|
func (s *Service) featureToggleEnableVar(ctx context.Context) []string {
|
|
|
|
var variables []string // an array is used for consistency and keep the logic simpler for no features case
|
|
|
|
|
2023-09-22 06:56:48 -05:00
|
|
|
if s.cfg.Features == nil {
|
|
|
|
return variables
|
|
|
|
}
|
2023-08-25 08:01:54 -05:00
|
|
|
|
2023-09-22 06:56:48 -05:00
|
|
|
enabledFeatures := s.cfg.Features.GetEnabled(ctx)
|
|
|
|
if len(enabledFeatures) > 0 {
|
|
|
|
features := make([]string, 0, len(enabledFeatures))
|
|
|
|
for feat := range enabledFeatures {
|
|
|
|
features = append(features, feat)
|
2023-08-25 08:01:54 -05:00
|
|
|
}
|
2023-09-22 06:56:48 -05:00
|
|
|
variables = append(variables, fmt.Sprintf("GF_INSTANCE_FEATURE_TOGGLES_ENABLE=%s", strings.Join(features, ",")))
|
2023-08-25 08:01:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return variables
|
|
|
|
}
|
|
|
|
|
2023-05-24 07:02:14 -05:00
|
|
|
func (s *Service) awsEnvVars() []string {
|
|
|
|
var variables []string
|
2024-02-05 12:59:32 -06:00
|
|
|
if !s.cfg.AWSAssumeRoleEnabled {
|
|
|
|
variables = append(variables, awsds.AssumeRoleEnabledEnvVarKeyName+"=false")
|
2023-05-24 07:02:14 -05:00
|
|
|
}
|
|
|
|
if len(s.cfg.AWSAllowedAuthProviders) > 0 {
|
|
|
|
variables = append(variables, awsds.AllowedAuthProvidersEnvVarKeyName+"="+strings.Join(s.cfg.AWSAllowedAuthProviders, ","))
|
|
|
|
}
|
2023-08-04 15:06:01 -05:00
|
|
|
if s.cfg.AWSExternalId != "" {
|
|
|
|
variables = append(variables, awsds.GrafanaAssumeRoleExternalIdKeyName+"="+s.cfg.AWSExternalId)
|
|
|
|
}
|
2024-02-05 12:59:32 -06:00
|
|
|
if s.cfg.AWSSessionDuration != "" {
|
|
|
|
variables = append(variables, awsds.SessionDurationEnvVarKeyName+"="+s.cfg.AWSSessionDuration)
|
|
|
|
}
|
|
|
|
if s.cfg.AWSListMetricsPageLimit != "" {
|
|
|
|
variables = append(variables, awsds.ListMetricsPageLimitKeyName+"="+s.cfg.AWSListMetricsPageLimit)
|
|
|
|
}
|
2023-05-24 07:02:14 -05:00
|
|
|
|
|
|
|
return variables
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) secureSocksProxyEnvVars() []string {
|
|
|
|
if s.cfg.ProxySettings.Enabled {
|
2023-06-07 10:22:43 -05:00
|
|
|
return []string{
|
|
|
|
proxy.PluginSecureSocksProxyClientCert + "=" + s.cfg.ProxySettings.ClientCert,
|
|
|
|
proxy.PluginSecureSocksProxyClientKey + "=" + s.cfg.ProxySettings.ClientKey,
|
|
|
|
proxy.PluginSecureSocksProxyRootCACert + "=" + s.cfg.ProxySettings.RootCA,
|
|
|
|
proxy.PluginSecureSocksProxyProxyAddress + "=" + s.cfg.ProxySettings.ProxyAddress,
|
|
|
|
proxy.PluginSecureSocksProxyServerName + "=" + s.cfg.ProxySettings.ServerName,
|
|
|
|
proxy.PluginSecureSocksProxyEnabled + "=" + strconv.FormatBool(s.cfg.ProxySettings.Enabled),
|
2023-12-14 09:16:32 -06:00
|
|
|
proxy.PluginSecureSocksProxyAllowInsecure + "=" + strconv.FormatBool(s.cfg.ProxySettings.AllowInsecure),
|
2023-06-07 10:22:43 -05:00
|
|
|
}
|
2023-05-24 07:02:14 -05:00
|
|
|
}
|
2023-06-07 10:22:43 -05:00
|
|
|
return nil
|
2023-05-24 07:02:14 -05:00
|
|
|
}
|
|
|
|
|
2023-11-15 11:09:14 -06:00
|
|
|
// allowedHostEnvVars returns the variables that can be passed from Grafana's process
|
|
|
|
// (current process, also known as: "host") to the plugin process.
|
|
|
|
// A string in format "k=v" is returned for each variable in allowedHostEnvVarNames, if it's set.
|
|
|
|
func (s *Service) allowedHostEnvVars() []string {
|
|
|
|
var r []string
|
|
|
|
for _, envVarName := range allowedHostEnvVarNames {
|
|
|
|
if envVarValue, ok := os.LookupEnv(envVarName); ok {
|
|
|
|
r = append(r, envVarName+"="+envVarValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2023-05-24 07:02:14 -05:00
|
|
|
type pluginSettings map[string]string
|
|
|
|
|
|
|
|
func getPluginSettings(pluginID string, cfg *config.Cfg) pluginSettings {
|
|
|
|
ps := pluginSettings{}
|
|
|
|
for k, v := range cfg.PluginSettings[pluginID] {
|
|
|
|
if k == "path" || strings.ToLower(k) == "id" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ps[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return ps
|
|
|
|
}
|
|
|
|
|
2023-09-21 04:33:31 -05:00
|
|
|
func (ps pluginSettings) asEnvVar(prefix string, hostEnv ...string) []string {
|
2023-05-24 07:02:14 -05:00
|
|
|
env := make([]string, 0, len(ps))
|
|
|
|
for k, v := range ps {
|
|
|
|
key := fmt.Sprintf("%s_%s", prefix, strings.ToUpper(k))
|
|
|
|
if value := os.Getenv(key); value != "" {
|
|
|
|
v = value
|
|
|
|
}
|
|
|
|
|
|
|
|
env = append(env, fmt.Sprintf("%s=%s", key, v))
|
|
|
|
}
|
|
|
|
|
|
|
|
env = append(env, hostEnv...)
|
|
|
|
|
|
|
|
return env
|
|
|
|
}
|