2021-05-03 07:46:32 -05:00
|
|
|
package pluginproxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-10-21 15:29:56 -05:00
|
|
|
googletokenprovider "github.com/grafana/grafana-google-sdk-go/pkg/tokenprovider"
|
2021-05-03 07:46:32 -05:00
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
|
|
)
|
|
|
|
|
|
|
|
type gceAccessTokenProvider struct {
|
2021-10-21 15:29:56 -05:00
|
|
|
source googletokenprovider.TokenProvider
|
|
|
|
ctx context.Context
|
2021-05-03 07:46:32 -05:00
|
|
|
}
|
|
|
|
|
2021-11-01 04:53:33 -05:00
|
|
|
func newGceAccessTokenProvider(ctx context.Context, ds DSInfo, pluginRoute *plugins.Route,
|
|
|
|
authParams *plugins.JWTTokenAuth) *gceAccessTokenProvider {
|
2021-10-21 15:29:56 -05:00
|
|
|
cfg := googletokenprovider.Config{
|
|
|
|
RoutePath: pluginRoute.Path,
|
|
|
|
RouteMethod: pluginRoute.Method,
|
|
|
|
DataSourceID: ds.ID,
|
|
|
|
DataSourceUpdated: ds.Updated,
|
|
|
|
Scopes: authParams.Scopes,
|
|
|
|
}
|
2021-05-03 07:46:32 -05:00
|
|
|
return &gceAccessTokenProvider{
|
2021-10-21 15:29:56 -05:00
|
|
|
source: googletokenprovider.NewGceAccessTokenProvider(cfg),
|
|
|
|
ctx: ctx,
|
2021-05-03 07:46:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 10:02:24 -05:00
|
|
|
func (provider *gceAccessTokenProvider) GetAccessToken() (string, error) {
|
2021-10-21 15:29:56 -05:00
|
|
|
return provider.source.GetAccessToken(provider.ctx)
|
2021-05-03 07:46:32 -05:00
|
|
|
}
|