Commit df215d9d by Erik Sundell

stackdriver: WIP - test retrieving project id from gce metadata

parent fbe0ffd1
......@@ -64,11 +64,33 @@ func ApplyRoute(ctx context.Context, req *http.Request, proxyPath string, route
}
if req.Header.Get("Authorization") == "" && ds.Type == "stackdriver" {
tokenSrc, err := google.DefaultTokenSource(ctx, "https://www.googleapis.com/auth/monitoring.read")
defaultCredentials, err := google.FindDefaultCredentials(ctx)
projectName := ds.JsonData.Get("defaultProject").MustString()
if projectName == "" {
ds.JsonData.Set("defaultProject", defaultCredentials.ProjectID)
}
if err != nil {
logger.Error("Failed to get default credentials", "error", err)
} else {
token, err := defaultCredentials.TokenSource.Token()
if err != nil {
logger.Error("Failed to get default access token", "error", err)
} else {
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token.AccessToken))
}
}
}
if req.Header.Get("Authorization") == "" && ds.Type == "stackdriver" {
credentials, err := google.FindDefaultCredentials(ctx, "https://www.googleapis.com/auth/monitoring.read")
projectName := ds.JsonData.Get("defaultProject").MustString()
if projectName == "" {
ds.JsonData.Set("defaultProject", credentials.ProjectID)
}
if err != nil {
logger.Error("Failed to get access token", "error", err)
} else {
token, err := tokenSrc.Token()
token, err := credentials.TokenSource.Token()
if err != nil {
logger.Error("Failed to get access token", "error", err)
} else {
......
......@@ -15,6 +15,8 @@ import (
"strings"
"time"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"golang.org/x/net/context/ctxhttp"
"github.com/grafana/grafana/pkg/api/pluginproxy"
......@@ -551,6 +553,7 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models.
return nil, errors.New("Unable to find datasource plugin Stackdriver")
}
projectName := dsInfo.JsonData.Get("defaultProject").MustString()
logger.Info("projectName", "projectName", projectName)
proxyPass := fmt.Sprintf("stackdriver%s", "v3/projects/"+projectName+"/timeSeries")
var stackdriverRoute *plugins.AppPluginRoute
......
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