mirror of
https://github.com/goharbor/harbor.git
synced 2024-10-01 06:47:33 +02:00
fix: add precheck when registry check token expired
Signed-off-by: chlins <chlins.zhang@gmail.com>
This commit is contained in:
parent
4c2e698af8
commit
12f3609e42
@ -15,10 +15,11 @@
|
|||||||
package bearer
|
package bearer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/lib/log"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/lib/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newCache(capacity int) *cache {
|
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
|
// return whether the token is expired or not and the expired time
|
||||||
func (c *cache) expired(token *token) (bool, time.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)
|
issueAt, err := time.Parse(time.RFC3339, token.IssuedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed to parse the issued at time of token %s: %v", token.IssuedAt, err)
|
log.Errorf("failed to parse the issued at time of token %s: %v", token.IssuedAt, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user