Fix replication bugs #11974, #11939

Fix replication bugs: fix #11974, fix #11939

Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
Wenkai Yin 2020-05-20 14:53:15 +08:00 committed by Ziming
parent 69fe9e9bf7
commit a31315aa36
2 changed files with 6 additions and 3 deletions

View File

@ -54,9 +54,9 @@ type authorizer struct {
}
func (a *authorizer) Modify(req *http.Request) error {
// Nil URL means this is the first time the authorizer is called
// Nil underlying authorizer means this is the first time the authorizer is called
// Try to connect to the registry and determine the auth scheme
if a.url == nil {
if a.authorizer == nil {
// to avoid concurrent issue
a.Lock()
defer a.Unlock()
@ -74,7 +74,7 @@ func (a *authorizer) Modify(req *http.Request) error {
}
func (a *authorizer) initialize(u *url.URL) error {
if a.url != nil {
if a.authorizer != nil {
return nil
}
url, err := url.Parse(u.Scheme + "://" + u.Host + "/v2/")

View File

@ -142,5 +142,8 @@ func (a *authorizer) fetchToken(scopes []*scope) (*token, error) {
if err = json.Unmarshal(body, token); err != nil {
return nil, err
}
if len(token.Token) == 0 && len(token.AccessToken) > 0 {
token.Token = token.AccessToken
}
return token, nil
}