diff --git a/registry/tokenpool.go b/registry/tokenpool.go index 0be1a391..a34ab80f 100644 --- a/registry/tokenpool.go +++ b/registry/tokenpool.go @@ -32,7 +32,7 @@ func (t *TokenPool) SetToken(scope, token string) { // repository:gds-eip/eip-api:pull if l := strings.Split(scope, ":"); len(l) == 3 { t.rwm.Lock() - t.tokens[l[2]] = token + t.tokens[l[1]] = token t.rwm.Unlock() } diff --git a/registry/tokentransport.go b/registry/tokentransport.go index aa673aaa..c2bdf859 100644 --- a/registry/tokentransport.go +++ b/registry/tokentransport.go @@ -29,11 +29,14 @@ func NewTokenTransport(transport http.RoundTripper, username string, password st var scopeReg = regexp.MustCompile(`^/v2/([A-Za-z0-9/-]+)/\b(tags|manifests|blobs)\b`) func (t *TokenTransport) GetScope(u string) string { + prefix := "/v2/" sc := scopeReg.Find([]byte(u)) if sc == nil { return "" } else { - return string(sc) + begin := strings.Index(string(sc), prefix) + len(prefix) + end := strings.LastIndex(string(sc), "/") + return string(sc[begin:end]) } }