Settings: Use Grafana Azure SDK to pass Azure env vars for external plugins (#48954)

* Azure env vars for plugins via Grafana Azure SDK

* Remove tests
This commit is contained in:
Sergey Kostrukov 2022-05-18 06:28:40 -07:00 committed by GitHub
parent 0ae8e3bd4e
commit 7251115457
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 26 deletions

2
go.mod
View File

@ -52,7 +52,7 @@ require (
github.com/gosimple/slug v1.9.0
github.com/grafana/cuetsy v0.0.1
github.com/grafana/grafana-aws-sdk v0.10.3
github.com/grafana/grafana-azure-sdk-go v1.1.0
github.com/grafana/grafana-azure-sdk-go v1.2.0
github.com/grafana/grafana-plugin-sdk-go v0.134.0
github.com/grafana/loki v1.6.2-0.20211015002020-7832783b1caa
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0

4
go.sum
View File

@ -1444,8 +1444,8 @@ github.com/grafana/go-mssqldb v0.0.0-20210326084033-d0ce3c521036 h1:GplhUk6Xes5J
github.com/grafana/go-mssqldb v0.0.0-20210326084033-d0ce3c521036/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/grafana/grafana-aws-sdk v0.10.3 h1:nqjK8NfrUyUcAtSjGxnt17ZKjeOMCi62MNKFNagjG6g=
github.com/grafana/grafana-aws-sdk v0.10.3/go.mod h1:vFIOHEnY1u5nY0/tge1IHQjPuG6DRKr2ISf/HikUdjE=
github.com/grafana/grafana-azure-sdk-go v1.1.0 h1:Gh0fjs7jr4Lp5y+4cjn48U+MQaJeV8i9m1ds/1xszto=
github.com/grafana/grafana-azure-sdk-go v1.1.0/go.mod h1:rgrnK9m6CgKlgx4rH3FFP/6dTdyRO6LYC2mVZov35yo=
github.com/grafana/grafana-azure-sdk-go v1.2.0 h1:f/7BjCHGIU0JYOsLIt4oJztDy0fOPBRHB5R0Xe9++ew=
github.com/grafana/grafana-azure-sdk-go v1.2.0/go.mod h1:rgrnK9m6CgKlgx4rH3FFP/6dTdyRO6LYC2mVZov35yo=
github.com/grafana/grafana-google-sdk-go v0.0.0-20211104130251-b190293eaf58 h1:2ud7NNM7LrGPO4x0NFR8qLq68CqI4SmB7I2yRN2w9oE=
github.com/grafana/grafana-google-sdk-go v0.0.0-20211104130251-b190293eaf58/go.mod h1:Vo2TKWfDVmNTELBUM+3lkrZvFtBws0qSZdXhQxRdJrE=
github.com/grafana/grafana-plugin-sdk-go v0.94.0/go.mod h1:3VXz4nCv6wH5SfgB3mlW39s+c+LetqSCjFj7xxPC5+M=

View File

@ -7,6 +7,7 @@ import (
"strings"
"github.com/grafana/grafana-aws-sdk/pkg/awsds"
"github.com/grafana/grafana-azure-sdk-go/azsettings"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
@ -66,7 +67,7 @@ func (i *Initializer) envVars(plugin *plugins.Plugin) []string {
}
hostEnv = append(hostEnv, i.awsEnvVars()...)
hostEnv = append(hostEnv, i.azureEnvVars()...)
hostEnv = append(hostEnv, azsettings.WriteToEnvStr(i.cfg.Azure)...)
return getPluginSettings(plugin.ID, i.cfg).asEnvVar("GF_PLUGIN", hostEnv)
}
@ -82,24 +83,6 @@ func (i *Initializer) awsEnvVars() []string {
return variables
}
func (i *Initializer) azureEnvVars() []string {
var variables []string
if i.cfg.Azure != nil {
if i.cfg.Azure.Cloud != "" {
variables = append(variables, "AZURE_CLOUD="+i.cfg.Azure.Cloud)
}
if i.cfg.Azure.ManagedIdentityClientId != "" {
variables = append(variables, "AZURE_MANAGED_IDENTITY_CLIENT_ID="+i.cfg.Azure.ManagedIdentityClientId)
}
if i.cfg.Azure.ManagedIdentityEnabled {
variables = append(variables, "AZURE_MANAGED_IDENTITY_ENABLED=true")
}
}
return variables
}
type pluginSettings map[string]string
func (ps pluginSettings) asEnvVar(prefix string, hostEnv []string) []string {

View File

@ -146,10 +146,6 @@ func TestInitializer_getAWSEnvironmentVariables(t *testing.T) {
}
func TestInitializer_getAzureEnvironmentVariables(t *testing.T) {
}
func TestInitializer_handleModuleDefaults(t *testing.T) {
}