From 12f3609e424e3535b6640420ea3da2c41e3a1a3d Mon Sep 17 00:00:00 2001 From: chlins Date: Thu, 4 Mar 2021 18:22:48 +0800 Subject: [PATCH] fix: add precheck when registry check token expired Signed-off-by: chlins --- src/pkg/registry/auth/bearer/cache.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pkg/registry/auth/bearer/cache.go b/src/pkg/registry/auth/bearer/cache.go index f1196a2df..0d17e7722 100644 --- a/src/pkg/registry/auth/bearer/cache.go +++ b/src/pkg/registry/auth/bearer/cache.go @@ -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)