Skip to content

Commit

Permalink
auth: add AuthCheckWithContext method (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
alebcay authored Oct 14, 2022
1 parent d637d8c commit 5047ae1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package docker

import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"errors"
Expand Down Expand Up @@ -262,11 +263,21 @@ type AuthStatus struct {
//
// See https://goo.gl/6nsZkH for more details.
func (c *Client) AuthCheck(conf *AuthConfiguration) (AuthStatus, error) {
return c.AuthCheckWithContext(conf, context.TODO())
}

// AuthCheckWithContext validates the given credentials. It returns nil if successful. The context object
// can be used to cancel the request.
//
// For Docker API versions >= 1.23, the AuthStatus struct will be populated, otherwise it will be empty.
//
// See https://goo.gl/6nsZkH for more details.
func (c *Client) AuthCheckWithContext(conf *AuthConfiguration, ctx context.Context) (AuthStatus, error) {
var authStatus AuthStatus
if conf == nil {
return authStatus, errors.New("conf is nil")
}
resp, err := c.do(http.MethodPost, "/auth", doOptions{data: conf})
resp, err := c.do(http.MethodPost, "/auth", doOptions{data: conf, context: ctx})
if err != nil {
return authStatus, err
}
Expand Down

0 comments on commit 5047ae1

Please sign in to comment.