mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Use SDK contracts for cloudmonitoring * Get build running, tests passing and do some refactoring (#38754) * fix build+tests and refactor * remove alerting stuff * remove unused field * fix plugin fetch * end to end * resp rename * tidy annotations * reformatting * update refID * reformat imports * fix styling * clean up unmarshalling * uncomment + fix tests * appease linter * remove spaces * remove old cruft * add check for empty queries * update tests * remove pm as dep * adjust proxy route contract * fix service loading * use UNIX val * fix endpoint + resp * h@ckz for frontend * fix resp * fix interval * always set custom meta * remove unused param * fix labels fetch * fix linter * fix test + remove unused field * apply pr feedback * fix grafana-auto intervals * fix tests * resolve conflicts * fix bad merge * fix conflicts * remove bad logger import Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> Co-authored-by: Will Browne <will.browne@grafana.com>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package pluginproxy
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
"golang.org/x/oauth2/google"
|
|
)
|
|
|
|
type gceAccessTokenProvider struct {
|
|
datasourceId int64
|
|
datasourceUpdated time.Time
|
|
ctx context.Context
|
|
route *plugins.AppPluginRoute
|
|
authParams *plugins.JwtTokenAuth
|
|
}
|
|
|
|
func newGceAccessTokenProvider(ctx context.Context, ds DSInfo, pluginRoute *plugins.AppPluginRoute,
|
|
authParams *plugins.JwtTokenAuth) *gceAccessTokenProvider {
|
|
return &gceAccessTokenProvider{
|
|
datasourceId: ds.ID,
|
|
datasourceUpdated: ds.Updated,
|
|
ctx: ctx,
|
|
route: pluginRoute,
|
|
authParams: authParams,
|
|
}
|
|
}
|
|
|
|
func (provider *gceAccessTokenProvider) GetAccessToken() (string, error) {
|
|
tokenSrc, err := google.DefaultTokenSource(provider.ctx, provider.authParams.Scopes...)
|
|
if err != nil {
|
|
logger.Error("Failed to get default token from meta data server", "error", err)
|
|
return "", err
|
|
} else {
|
|
token, err := tokenSrc.Token()
|
|
if err != nil {
|
|
logger.Error("Failed to get default access token from meta data server", "error", err)
|
|
return "", err
|
|
} else {
|
|
return token.AccessToken, nil
|
|
}
|
|
}
|
|
}
|