2023-05-24 07:02:14 -05:00
|
|
|
package envvars
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
2024-02-01 04:58:24 -06:00
|
|
|
|
2023-05-24 07:02:14 -05:00
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
|
|
)
|
|
|
|
|
2024-02-27 05:38:02 -06:00
|
|
|
// permittedHostEnvVarNames is the list of environment variables that can be passed from Grafana's process to the
|
2023-11-15 11:09:14 -06:00
|
|
|
// plugin's process
|
2024-02-27 05:38:02 -06:00
|
|
|
var permittedHostEnvVarNames = []string{
|
2023-11-15 11:09:14 -06:00
|
|
|
// 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 {
|
2024-02-27 05:38:02 -06:00
|
|
|
PluginEnvVars(ctx context.Context, p *plugins.Plugin) []string
|
2023-05-24 07:02:14 -05:00
|
|
|
}
|
|
|
|
|
2024-02-27 05:38:02 -06:00
|
|
|
type Service struct{}
|
2023-05-24 07:02:14 -05:00
|
|
|
|
2024-02-27 05:38:02 -06:00
|
|
|
func DefaultProvider() *Service {
|
|
|
|
return &Service{}
|
2023-05-24 07:02:14 -05:00
|
|
|
}
|
|
|
|
|
2024-02-27 05:38:02 -06:00
|
|
|
func (s *Service) PluginEnvVars(_ context.Context, _ *plugins.Plugin) []string {
|
|
|
|
return PermittedHostEnvVars()
|
2023-05-24 07:02:14 -05:00
|
|
|
}
|
|
|
|
|
2024-02-27 05:38:02 -06:00
|
|
|
// PermittedHostEnvVars returns the variables that can be passed from Grafana's process
|
2023-11-15 11:09:14 -06:00
|
|
|
// (current process, also known as: "host") to the plugin process.
|
2024-02-27 05:38:02 -06:00
|
|
|
// A string in format "k=v" is returned for each variable in PermittedHostEnvVarNames, if it's set.
|
|
|
|
func PermittedHostEnvVars() []string {
|
2023-11-15 11:09:14 -06:00
|
|
|
var r []string
|
2024-02-27 05:38:02 -06:00
|
|
|
for _, envVarName := range PermittedHostEnvVarNames() {
|
2023-11-15 11:09:14 -06:00
|
|
|
if envVarValue, ok := os.LookupEnv(envVarName); ok {
|
|
|
|
r = append(r, envVarName+"="+envVarValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2024-02-27 05:38:02 -06:00
|
|
|
func PermittedHostEnvVarNames() []string {
|
|
|
|
return permittedHostEnvVarNames
|
2023-05-24 07:02:14 -05:00
|
|
|
}
|