Repository: containerd/containerd
File: core/remotes/docker/authorizer.go (Go)

Code before:
	credentials         func(string) (string, string, error)
	client              *http.Client
	header              http.Header
	onFetchRefreshToken OnFetchRefreshToken
}

// AuthorizerOpt configures an authorizer
type AuthorizerOpt func(*authorizerConfig)

// WithAuthClient provides the HTTP client for the authorizer
func WithAuthClient(client *http.Client) AuthorizerOpt {
	return func(opt *authorizerConfig) {
		opt.client = client
	}
}

// WithAuthCreds provides a credential function to the authorizer
func WithAuthCreds(creds func(string) (string, string, error)) AuthorizerOpt {
	return func(opt *authorizerConfig) {
		opt.credentials = creds
	}
}

// WithAuthHeader provides HTTP headers for authorization
//
// We nee to merge instead of replacing because header may be set by
// a per-host hosts.toml or/AND by a global header config (e.g., cri.config.headers)
func WithAuthHeader(hdr http.Header) AuthorizerOpt {
	return func(opt *authorizerConfig) {
		if opt.header == nil {
			opt.header = hdr.Clone()
		} else {
			for k, v := range hdr {
				opt.header[k] = append(opt.header[k], v...)
			}
		}
	}
}

// OnFetchRefreshToken is called on fetching request token.
type OnFetchRefreshToken func(ctx context.Context, refreshToken string, req *http.Request)

// WithFetchRefreshToken enables fetching "refresh token" (aka "identity token", "offline token").
func WithFetchRefreshToken(f OnFetchRefreshToken) AuthorizerOpt {
	return func(opt *authorizerConfig) {
		opt.onFetchRefreshToken = f
	}
}

// NewDockerAuthorizer creates an authorizer using Docker's registry
// authentication spec.

Review comment (suggestion):
Minor spelling error in the comment: 'nee' should be 'need'.
```suggestion
// We need to merge instead of replacing because header may be set by
```

Code after:
	credentials         func(string) (string, string, error)
	client              *http.Client
	header              http.Header
	onFetchRefreshToken OnFetchRefreshToken
}

// AuthorizerOpt configures an authorizer
type AuthorizerOpt func(*authorizerConfig)

// WithAuthClient provides the HTTP client for the authorizer
func WithAuthClient(client *http.Client) AuthorizerOpt {
	return func(opt *authorizerConfig) {
		opt.client = client
	}
}

// WithAuthCreds provides a credential function to the authorizer
func WithAuthCreds(creds func(string) (string, string, error)) AuthorizerOpt {
	return func(opt *authorizerConfig) {
		opt.credentials = creds
	}
}

// WithAuthHeader provides HTTP headers for authorization
//
// We need to merge instead of replacing because header may be set by
// a per-host hosts.toml or/AND by a global header config (e.g., cri.config.headers)
func WithAuthHeader(hdr http.Header) AuthorizerOpt {
	return func(opt *authorizerConfig) {
		if opt.header == nil {
			opt.header = hdr.Clone()
		} else {
			for k, v := range hdr {
				opt.header[k] = append(opt.header[k], v...)
			}
		}
	}
}

// OnFetchRefreshToken is called on fetching request token.
type OnFetchRefreshToken func(ctx context.Context, refreshToken string, req *http.Request)

// WithFetchRefreshToken enables fetching "refresh token" (aka "identity token", "offline token").
func WithFetchRefreshToken(f OnFetchRefreshToken) AuthorizerOpt {
	return func(opt *authorizerConfig) {
		opt.onFetchRefreshToken = f
	}
}

// NewDockerAuthorizer creates an authorizer using Docker's registry
// authentication spec.