1
0
mirror of https://github.com/drone/drone-cli.git synced 2024-09-22 11:51:08 +02:00
drone-cli/vendor/github.com/docker/docker/client/login.go

30 lines
827 B
Go
Raw Normal View History

2017-05-15 13:59:26 +02:00
package client
import (
"encoding/json"
"net/http"
"net/url"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"golang.org/x/net/context"
)
// RegistryLogin authenticates the docker server with a given docker registry.
2018-02-14 22:06:05 +01:00
// It returns UnauthorizerError when the authentication fails.
2017-05-15 13:59:26 +02:00
func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) {
resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil)
if resp.statusCode == http.StatusUnauthorized {
return registry.AuthenticateOKBody{}, unauthorizedError{err}
}
if err != nil {
return registry.AuthenticateOKBody{}, err
}
var response registry.AuthenticateOKBody
err = json.NewDecoder(resp.body).Decode(&response)
ensureReaderClosed(resp)
return response, err
}