registry: loginV2: wire-up context

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-04-04 14:44:05 +02:00
parent 4642704ed7
commit 8b920b2812
2 changed files with 5 additions and 5 deletions

View File

@@ -66,11 +66,11 @@ func (scs staticCredentialStore) SetRefreshToken(*url.URL, string, string) {
// loginV2 tries to login to the v2 registry server. The given registry
// endpoint will be pinged to get authorization challenges. These challenges
// will be used to authenticate against the registry to validate credentials.
func loginV2(authConfig *registry.AuthConfig, endpoint APIEndpoint, userAgent string) (token string, _ error) {
func loginV2(ctx context.Context, authConfig *registry.AuthConfig, endpoint APIEndpoint, userAgent string) (token string, _ error) {
endpointStr := strings.TrimRight(endpoint.URL.String(), "/") + "/v2/"
log.G(context.TODO()).Debugf("attempting v2 login to registry endpoint %s", endpointStr)
log.G(ctx).WithField("endpoint", endpointStr).Debug("attempting v2 login to registry endpoint")
req, err := http.NewRequest(http.MethodGet, endpointStr, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpointStr, nil)
if err != nil {
return "", err
}

View File

@@ -82,9 +82,9 @@ func (s *Service) Auth(ctx context.Context, authConfig *registry.AuthConfig, use
var lastErr error
for _, endpoint := range endpoints {
authToken, err := loginV2(authConfig, endpoint, userAgent)
authToken, err := loginV2(ctx, authConfig, endpoint, userAgent)
if err != nil {
if errdefs.IsUnauthorized(err) {
if errdefs.IsContext(err) || errdefs.IsUnauthorized(err) {
// Failed to authenticate; don't continue with (non-TLS) endpoints.
return "", "", err
}