github.com/kinvolk/docker@v1.13.1/client/login.go (about) 1 package client 2 3 import ( 4 "encoding/json" 5 "net/http" 6 "net/url" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/api/types/registry" 10 "golang.org/x/net/context" 11 ) 12 13 // RegistryLogin authenticates the docker server with a given docker registry. 14 // It returns UnauthorizerError when the authentication fails. 15 func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) { 16 resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil) 17 18 if resp.statusCode == http.StatusUnauthorized { 19 return registry.AuthenticateOKBody{}, unauthorizedError{err} 20 } 21 if err != nil { 22 return registry.AuthenticateOKBody{}, err 23 } 24 25 var response registry.AuthenticateOKBody 26 err = json.NewDecoder(resp.body).Decode(&response) 27 ensureReaderClosed(resp) 28 return response, err 29 }