Stackdriver: Temporary exporting token lookup

This commit is contained in:
Erik Sundell
2018-09-09 22:49:12 +02:00
committed by Daniel Lee
parent 75c002645c
commit 71af62e741
+14 -1
View File
@@ -32,7 +32,8 @@ type jwtToken struct {
AccessToken string `json:"access_token"`
}
func newAccessTokenProvider(dsID int64, pluginRoute *plugins.AppPluginRoute) *accessTokenProvider {
// Access token provider
func NewAccessTokenProvider(dsID int64, pluginRoute *plugins.AppPluginRoute) *accessTokenProvider {
return &accessTokenProvider{
datasourceID: dsID,
route: pluginRoute,
@@ -139,9 +140,21 @@ var getTokenSource = func(conf *jwt.Config, ctx context.Context) (*oauth2.Token,
return nil, err
}
logger.Info("interpolatedVal", "token.AccessToken", token.AccessToken)
return token, nil
}
func (provider *accessTokenProvider) getAccessTokenCacheKey() string {
return fmt.Sprintf("%v_%v_%v", provider.datasourceID, provider.route.Path, provider.route.Method)
}
//Export access token lookup
func GetAccessTokenFromCache(datasourceID int64, path string, method string) (string, error) {
key := fmt.Sprintf("%v_%v_%v", datasourceID, path, method)
if cachedToken, found := oauthJwtTokenCache[key]; found {
return cachedToken.AccessToken, nil
} else {
return "", fmt.Errorf("Key doesnt exist")
}
}