mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-27 02:58:05 +01:00
Merge pull request #14372 from chlins/fix/registry-auth-parse-time
fix: add precheck when registry check token expired
This commit is contained in:
commit
5f0e7cfd62
@ -15,10 +15,11 @@
|
||||
package bearer
|
||||
|
||||
import (
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
)
|
||||
|
||||
func newCache(capacity int) *cache {
|
||||
@ -93,6 +94,12 @@ func (c *cache) key(scopes []*scope) string {
|
||||
|
||||
// return whether the token is expired or not and the expired time
|
||||
func (c *cache) expired(token *token) (bool, time.Time) {
|
||||
// check time whether empty
|
||||
if len(token.IssuedAt) == 0 {
|
||||
log.Warning("token issued time is empty, return expired to refresh token")
|
||||
return true, time.Time{}
|
||||
}
|
||||
|
||||
issueAt, err := time.Parse(time.RFC3339, token.IssuedAt)
|
||||
if err != nil {
|
||||
log.Errorf("failed to parse the issued at time of token %s: %v", token.IssuedAt, err)
|
||||
|
Loading…
Reference in New Issue
Block a user