Commit 43aa6603 by Mitsuhiro Tanda Committed by Erik Sundell

fetch token from GCE metadata server

parent 022a45be
......@@ -12,6 +12,7 @@ import (
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/util"
"golang.org/x/oauth2/google"
)
//ApplyRoute should use the plugin route data to set auth headers and custom headers
......@@ -61,6 +62,21 @@ func ApplyRoute(ctx context.Context, req *http.Request, proxyPath string, route
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
}
}
if req.Header.Get("Authorization") == "" && ds.Type == "stackdriver" {
tokenSrc, err := google.DefaultTokenSource(ctx, "https://www.googleapis.com/auth/monitoring.read")
if err != nil {
logger.Error("Failed to get access token", "error", err)
} else {
token, err := tokenSrc.Token()
if err != nil {
logger.Error("Failed to get access token", "error", err)
} else {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token.AccessToken))
}
}
}
logger.Info("Requesting", "url", req.URL.String())
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment