mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
expose azure settings as env variables (#34484)
This commit is contained in:
parent
a8fa5f1796
commit
92ac2c40d3
@ -81,6 +81,8 @@ func (m *manager) Register(pluginID string, factory backendplugin.PluginFactoryF
|
|||||||
}
|
}
|
||||||
|
|
||||||
hostEnv = append(hostEnv, m.getAWSEnvironmentVariables()...)
|
hostEnv = append(hostEnv, m.getAWSEnvironmentVariables()...)
|
||||||
|
hostEnv = append(hostEnv, m.getAzureEnvironmentVariables()...)
|
||||||
|
|
||||||
pluginSettings := getPluginSettings(pluginID, m.Cfg)
|
pluginSettings := getPluginSettings(pluginID, m.Cfg)
|
||||||
env := pluginSettings.ToEnv("GF_PLUGIN", hostEnv)
|
env := pluginSettings.ToEnv("GF_PLUGIN", hostEnv)
|
||||||
|
|
||||||
@ -164,6 +166,21 @@ func (m *manager) getAWSEnvironmentVariables() []string {
|
|||||||
return variables
|
return variables
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *manager) getAzureEnvironmentVariables() []string {
|
||||||
|
variables := []string{}
|
||||||
|
if m.Cfg.Azure.Cloud != "" {
|
||||||
|
variables = append(variables, "AZURE_CLOUD="+m.Cfg.Azure.Cloud)
|
||||||
|
}
|
||||||
|
if m.Cfg.Azure.ManagedIdentityClientId != "" {
|
||||||
|
variables = append(variables, "AZURE_MANAGED_IDENTITY_CLIENT_ID="+m.Cfg.Azure.ManagedIdentityClientId)
|
||||||
|
}
|
||||||
|
if m.Cfg.Azure.ManagedIdentityEnabled {
|
||||||
|
variables = append(variables, "AZURE_MANAGED_IDENTITY_ENABLED=true")
|
||||||
|
}
|
||||||
|
|
||||||
|
return variables
|
||||||
|
}
|
||||||
|
|
||||||
//nolint: staticcheck // plugins.DataPlugin deprecated
|
//nolint: staticcheck // plugins.DataPlugin deprecated
|
||||||
func (m *manager) GetDataPlugin(pluginID string) interface{} {
|
func (m *manager) GetDataPlugin(pluginID string) interface{} {
|
||||||
p, _ := m.Get(pluginID)
|
p, _ := m.Get(pluginID)
|
||||||
|
@ -63,8 +63,16 @@ func TestManager(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should provide expected host environment variables", func(t *testing.T) {
|
t.Run("Should provide expected host environment variables", func(t *testing.T) {
|
||||||
require.Len(t, ctx.env, 4)
|
require.Len(t, ctx.env, 7)
|
||||||
require.EqualValues(t, []string{"GF_VERSION=7.0.0", "GF_EDITION=Open Source", fmt.Sprintf("%s=true", awsds.AssumeRoleEnabledEnvVarKeyName), fmt.Sprintf("%s=keys,credentials", awsds.AllowedAuthProvidersEnvVarKeyName)}, ctx.env)
|
require.EqualValues(t, []string{
|
||||||
|
"GF_VERSION=7.0.0",
|
||||||
|
"GF_EDITION=Open Source",
|
||||||
|
fmt.Sprintf("%s=true", awsds.AssumeRoleEnabledEnvVarKeyName),
|
||||||
|
fmt.Sprintf("%s=keys,credentials", awsds.AllowedAuthProvidersEnvVarKeyName),
|
||||||
|
"AZURE_CLOUD=AzureCloud",
|
||||||
|
"AZURE_MANAGED_IDENTITY_CLIENT_ID=client-id",
|
||||||
|
"AZURE_MANAGED_IDENTITY_ENABLED=true"},
|
||||||
|
ctx.env)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("When manager runs should start and stop plugin", func(t *testing.T) {
|
t.Run("When manager runs should start and stop plugin", func(t *testing.T) {
|
||||||
@ -282,8 +290,18 @@ func TestManager(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("Should provide expected host environment variables", func(t *testing.T) {
|
t.Run("Should provide expected host environment variables", func(t *testing.T) {
|
||||||
require.Len(t, ctx.env, 6)
|
require.Len(t, ctx.env, 9)
|
||||||
require.EqualValues(t, []string{"GF_VERSION=7.0.0", "GF_EDITION=Enterprise", "GF_ENTERPRISE_LICENSE_PATH=/license.txt", "GF_ENTERPRISE_LICENSE_TEXT=testtoken", fmt.Sprintf("%s=true", awsds.AssumeRoleEnabledEnvVarKeyName), fmt.Sprintf("%s=keys,credentials", awsds.AllowedAuthProvidersEnvVarKeyName)}, ctx.env)
|
require.EqualValues(t, []string{
|
||||||
|
"GF_VERSION=7.0.0",
|
||||||
|
"GF_EDITION=Enterprise",
|
||||||
|
"GF_ENTERPRISE_LICENSE_PATH=/license.txt",
|
||||||
|
"GF_ENTERPRISE_LICENSE_TEXT=testtoken",
|
||||||
|
fmt.Sprintf("%s=true", awsds.AssumeRoleEnabledEnvVarKeyName),
|
||||||
|
fmt.Sprintf("%s=keys,credentials", awsds.AllowedAuthProvidersEnvVarKeyName),
|
||||||
|
"AZURE_CLOUD=AzureCloud",
|
||||||
|
"AZURE_MANAGED_IDENTITY_CLIENT_ID=client-id",
|
||||||
|
"AZURE_MANAGED_IDENTITY_ENABLED=true"},
|
||||||
|
ctx.env)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -304,6 +322,10 @@ func newManagerScenario(t *testing.T, managed bool, fn func(t *testing.T, ctx *m
|
|||||||
cfg.AWSAllowedAuthProviders = []string{"keys", "credentials"}
|
cfg.AWSAllowedAuthProviders = []string{"keys", "credentials"}
|
||||||
cfg.AWSAssumeRoleEnabled = true
|
cfg.AWSAssumeRoleEnabled = true
|
||||||
|
|
||||||
|
cfg.Azure.ManagedIdentityEnabled = true
|
||||||
|
cfg.Azure.Cloud = "AzureCloud"
|
||||||
|
cfg.Azure.ManagedIdentityClientId = "client-id"
|
||||||
|
|
||||||
license := &testLicensingService{}
|
license := &testLicensingService{}
|
||||||
validator := &testPluginRequestValidator{}
|
validator := &testPluginRequestValidator{}
|
||||||
ctx := &managerScenarioCtx{
|
ctx := &managerScenarioCtx{
|
||||||
|
Loading…
Reference in New Issue
Block a user