CheckAuth validates the credentials by attempting to log into the registry returns an error if an error occurred while making the http request or the status code received was 401
(ctx context.Context, sys *types.SystemContext, username, password, registry string)
| 276 | // CheckAuth validates the credentials by attempting to log into the registry |
| 277 | // returns an error if an error occurred while making the http request or the status code received was 401 |
| 278 | func CheckAuth(ctx context.Context, sys *types.SystemContext, username, password, registry string) error { |
| 279 | client, err := newDockerClient(sys, registry, registry) |
| 280 | if err != nil { |
| 281 | return fmt.Errorf("creating new docker client: %w", err) |
| 282 | } |
| 283 | defer client.Close() |
| 284 | client.auth = types.DockerAuthConfig{ |
| 285 | Username: username, |
| 286 | Password: password, |
| 287 | } |
| 288 | |
| 289 | resp, err := client.makeRequest(ctx, http.MethodGet, "/v2/", nil, nil, v2Auth, nil) |
| 290 | if err != nil { |
| 291 | return err |
| 292 | } |
| 293 | defer resp.Body.Close() |
| 294 | if resp.StatusCode != http.StatusOK { |
| 295 | err := registryHTTPResponseToError(resp) |
| 296 | if resp.StatusCode == http.StatusUnauthorized { |
| 297 | err = ErrUnauthorizedForCredentials{Err: err} |
| 298 | } |
| 299 | return err |
| 300 | } |
| 301 | return nil |
| 302 | } |
| 303 | |
| 304 | // SearchResult holds the information of each matching image |
| 305 | // It matches the output returned by the v1 endpoint |
searching dependent graphs…