MCPcopy Create free account
hub / github.com/containers/image / needsRetryWithUpdatedScope

Function needsRetryWithUpdatedScope

docker/docker_client.go:481–502  ·  view source on GitHub ↗

Checks if the auth headers in the response contain an indication of a failed authorization because of an "insufficient_scope" error. If that's the case, returns the required scope to be used for fetching a new token.

(res *http.Response)

Source from the content-addressed store, hash-verified

479// authorization because of an "insufficient_scope" error. If that's the case,
480// returns the required scope to be used for fetching a new token.
481func needsRetryWithUpdatedScope(res *http.Response) (bool, *authScope) {
482 if res.StatusCode == http.StatusUnauthorized {
483 for challenge := range iterateAuthHeader(res.Header) {
484 if challenge.Scheme == "bearer" {
485 if errmsg, ok := challenge.Parameters["error"]; ok && errmsg == "insufficient_scope" {
486 if scope, ok := challenge.Parameters["scope"]; ok && scope != "" {
487 if newScope, err := parseAuthScope(scope); err == nil {
488 return true, newScope
489 } else {
490 logrus.WithFields(logrus.Fields{
491 "error": err,
492 "scope": scope,
493 "challenge": challenge,
494 }).Error("Failed to parse the authentication scope from the given challenge")
495 }
496 }
497 }
498 }
499 }
500 }
501 return false, nil
502}
503
504// parseRetryAfter determines the delay required by the "Retry-After" header in res and returns it,
505// silently falling back to fallbackDelay if the header is missing or invalid.

Calls 3

iterateAuthHeaderFunction · 0.85
parseAuthScopeFunction · 0.85
ErrorMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…