Cloudwatch: use shared library for aws auth (#29550) (#31946)

* use sdk for handling auth

* fix broken test

* lint fixes

Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
(cherry picked from commit 9dd1d5f553)

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Erik Sundell
2021-03-12 23:27:32 +01:00
committed by GitHub
co-authored by Ryan McKinley
parent 47937d8f1b
commit 44838f201c
16 changed files with 155 additions and 490 deletions
+16
View File
@@ -9,9 +9,11 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strings"
"sync"
"time"
"github.com/grafana/grafana-aws-sdk/pkg/awsds"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
@@ -108,6 +110,8 @@ func (m *manager) Register(pluginID string, factory PluginFactoryFunc) error {
}
}
hostEnv = append(hostEnv, m.getAWSEnvironmentVariables()...)
env := pluginSettings.ToEnv("GF_PLUGIN", hostEnv)
pluginLogger := m.logger.New("pluginId", pluginID)
@@ -121,6 +125,18 @@ func (m *manager) Register(pluginID string, factory PluginFactoryFunc) error {
return nil
}
func (m *manager) getAWSEnvironmentVariables() []string {
variables := []string{}
if m.Cfg.AWSAssumeRoleEnabled {
variables = append(variables, awsds.AssumeRoleEnabledEnvVarKeyName+"=true")
}
if len(m.Cfg.AWSAllowedAuthProviders) > 0 {
variables = append(variables, awsds.AllowedAuthProvidersEnvVarKeyName+"="+strings.Join(m.Cfg.AWSAllowedAuthProviders, ","))
}
return variables
}
// start starts all managed backend plugins
func (m *manager) start(ctx context.Context) {
m.pluginsMu.RLock()