Skip to content

Commit

Permalink
oss: retry fetch STS token in newOSS() (#4143)
Browse files Browse the repository at this point in the history
In case Aliyun ECS meta server is not available temporarily.

Signed-off-by: Eryu Guan <[email protected]>
  • Loading branch information
eryugey authored Nov 7, 2023
1 parent 195ee22 commit 4f4b4b3
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions pkg/object/oss.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,23 @@ func newOSS(endpoint, accessKey, secretKey, token string) (ObjectStorage, error)
token = os.Getenv("SECURITY_TOKEN")

if accessKey == "" {
if cred, err := fetchStsToken(); err != nil {
return nil, fmt.Errorf("No credential provided for OSS")
} else {
accessKey = cred.AccessKeyId
secretKey = cred.AccessKeySecret
token = cred.SecurityToken
refresh = true
var err error
var cred *stsCred
maxRetry := 4
for i := 0; i < maxRetry; i++ {
time.Sleep(time.Second * time.Duration(i))
if cred, err = fetchStsToken(); err != nil {
logger.Warnf("Fetch STS Token try %d: %s", i+1, err)
} else {
accessKey = cred.AccessKeyId
secretKey = cred.AccessKeySecret
token = cred.SecurityToken
refresh = true
break
}
}
if err != nil {
return nil, fmt.Errorf("No credential provided for OSS: %s", err)
}
}
}
Expand Down

0 comments on commit 4f4b4b3

Please sign in to comment.