in token_auto_update_client.go [73:122]
func (c *TokenAutoUpdateClient) fetchSTSToken() error {
nowTime := time.Now()
skip := false
sleepTime := time.Duration(0)
c.lock.Lock()
if nowTime.Sub(c.lastFetch) < c.updateTokenIntervalMin {
skip = true
} else {
c.lastFetch = nowTime
if c.lastRetryFailCount == 0 {
sleepTime = 0
} else {
c.lastRetryInterval *= 2
if c.lastRetryInterval < c.waitIntervalMin {
c.lastRetryInterval = c.waitIntervalMin
}
if c.lastRetryInterval >= c.waitIntervalMax {
c.lastRetryInterval = c.waitIntervalMax
}
sleepTime = c.lastRetryInterval
}
}
c.lock.Unlock()
if skip {
return errSTSFetchHighFrequency
}
if sleepTime > time.Duration(0) {
time.Sleep(sleepTime)
}
accessKeyID, accessKeySecret, securityToken, expireTime, err := c.tokenUpdateFunc()
if err == nil {
c.lock.Lock()
c.lastRetryFailCount = 0
c.lastRetryInterval = time.Duration(0)
c.nextExpire = expireTime
c.lock.Unlock()
c.logClient.ResetAccessKeyToken(accessKeyID, accessKeySecret, securityToken)
if IsDebugLevelMatched(1) {
level.Info(Logger).Log("msg", "fetch sts token success id : ", accessKeyID)
}
} else {
c.lock.Lock()
c.lastRetryFailCount++
c.lock.Unlock()
level.Warn(Logger).Log("msg", "fetch sts token error : ", err.Error())
}
return err
}