Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
Signed-off-by: Lixia (Sylvia) Lei <lixlei@microsoft.com>
  • Loading branch information
Wwwsylvia committed Sep 21, 2023
1 parent b132088 commit 451df3f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions registry/remote/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ func (c *Client) Do(originalReq *http.Request) (*http.Response, error) {
}
case SchemeBearer:
// merge per-host scopes with generic scopes
scopes := append(GetScopesPerHost(ctx, host), GetScopes(ctx)...)
scopes = CleanScopes(scopes)
scopes := GetScopesPerHost(ctx, host)
if moreScopes := GetScopes(ctx); len(moreScopes) > 0 {
scopes = append(scopes, moreScopes...)
scopes = CleanScopes(scopes)
}
attemptedKey = strings.Join(scopes, " ")
token, err := cache.GetToken(ctx, host, SchemeBearer, attemptedKey)
if err == nil {
Expand Down Expand Up @@ -225,13 +228,20 @@ func (c *Client) Do(originalReq *http.Request) (*http.Response, error) {
case SchemeBearer:
resp.Body.Close()

// merge per-host scopes with generic scopes
scopes := append(GetScopesPerHost(ctx, host), GetScopes(ctx)...)
scopes := GetScopesPerHost(ctx, host)
cleanScopeLen := len(scopes)
if moreScopes := GetScopes(ctx); len(moreScopes) > 0 {
// merge per-host scopes with generic scopes
scopes = append(scopes, moreScopes...)
}
if paramScope := params["scope"]; paramScope != "" {
// merge hinted scopes with challenged scopes
scopes = append(scopes, strings.Split(paramScope, " ")...)
}
scopes = CleanScopes(scopes)
if len(scopes) > cleanScopeLen {
// re-clean the scopes
scopes = CleanScopes(scopes)
}
key := strings.Join(scopes, " ")

// attempt the cache again if there is a scope change
Expand Down

0 comments on commit 451df3f

Please sign in to comment.