Plugins: Fix Azure token provider cache panic and auth param nil value (#34252)

* More tests for token cache

* Safeguarding from panic and concurrency fixes

* Update Azure dependencies

* Fix interpolation of empty plugin data
This commit is contained in:
Sergey Kostrukov
2021-05-18 06:36:58 -07:00
committed by GitHub
parent 63b2dd06a5
commit c1b8a10f41
8 changed files with 363 additions and 86 deletions
+26 -10
View File
@@ -97,16 +97,7 @@ func (c *scopesCacheEntry) getAccessToken(ctx context.Context) (string, error) {
c.cond.L.Unlock()
if shouldRefresh {
accessToken, err = c.credential.GetAccessToken(ctx, c.scopes)
c.cond.L.Lock()
c.refreshing = false
c.accessToken = accessToken
c.cond.Broadcast()
c.cond.L.Unlock()
accessToken, err = c.refreshAccessToken(ctx)
if err != nil {
return "", err
}
@@ -115,6 +106,31 @@ func (c *scopesCacheEntry) getAccessToken(ctx context.Context) (string, error) {
return accessToken.Token, nil
}
func (c *scopesCacheEntry) refreshAccessToken(ctx context.Context) (*AccessToken, error) {
var accessToken *AccessToken
// Safeguarding from panic caused by credential implementation
defer func() {
c.cond.L.Lock()
c.refreshing = false
if accessToken != nil {
c.accessToken = accessToken
}
c.cond.Broadcast()
c.cond.L.Unlock()
}()
token, err := c.credential.GetAccessToken(ctx, c.scopes)
if err != nil {
return nil, err
}
accessToken = token
return accessToken, nil
}
func getKeyForScopes(scopes []string) string {
if len(scopes) > 1 {
arr := make([]string, len(scopes))