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

Function CheckAuth

docker/docker_client.go:278–302  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
278func 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

Callers 1

TestUserAgentFunction · 0.85

Calls 4

newDockerClientFunction · 0.70
CloseMethod · 0.65
makeRequestMethod · 0.45

Tested by 1

TestUserAgentFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…