2018-02-05 16:05:59 -05:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-06 14:46:37 -04:00
|
|
|
|
|
|
|
import (
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2016-09-06 14:46:37 -04:00
|
|
|
"encoding/json"
|
|
|
|
"net/url"
|
|
|
|
|
2016-10-18 20:52:46 -04:00
|
|
|
"github.com/docker/docker/api/types/registry"
|
2016-09-06 14:46:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// RegistryLogin authenticates the docker server with a given docker registry.
|
2016-12-01 15:18:02 -05:00
|
|
|
// It returns unauthorizedError when the authentication fails.
|
2022-03-03 04:27:23 -05:00
|
|
|
func (cli *Client) RegistryLogin(ctx context.Context, auth registry.AuthConfig) (registry.AuthenticateOKBody, error) {
|
2016-09-06 14:46:37 -04:00
|
|
|
resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil)
|
2019-02-11 07:26:12 -05:00
|
|
|
defer ensureReaderClosed(resp)
|
2016-09-06 14:46:37 -04:00
|
|
|
|
|
|
|
if err != nil {
|
2016-10-18 20:52:46 -04:00
|
|
|
return registry.AuthenticateOKBody{}, err
|
2016-09-06 14:46:37 -04:00
|
|
|
}
|
|
|
|
|
2016-10-18 20:52:46 -04:00
|
|
|
var response registry.AuthenticateOKBody
|
2016-09-06 14:46:37 -04:00
|
|
|
err = json.NewDecoder(resp.body).Decode(&response)
|
|
|
|
return response, err
|
|
|
|
}
|