Skip to content

Commit

Permalink
Merge pull request moby#3908 from crosbymichael/fix-login-prompt
Browse files Browse the repository at this point in the history
Fix login prompt on push and pull because of error message
  • Loading branch information
unclejack committed Feb 3, 2014
2 parents a9860d8 + 0fa9199 commit 4e9164f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ func (cli *DockerCli) CmdPush(args ...string) error {
}

if err := push(authConfig); err != nil {
if err.Error() == registry.ErrLoginRequired.Error() {
if strings.Contains(err.Error(), "Status 401") {
fmt.Fprintln(cli.out, "\nPlease login prior to push:")
if err := cli.CmdLogin(endpoint); err != nil {
return err
Expand Down Expand Up @@ -1106,7 +1106,7 @@ func (cli *DockerCli) CmdPull(args ...string) error {
}

if err := pull(authConfig); err != nil {
if err.Error() == registry.ErrLoginRequired.Error() {
if strings.Contains(err.Error(), "Status 401") {
fmt.Fprintln(cli.out, "\nPlease login prior to pull:")
if err := cli.CmdLogin(endpoint); err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
var (
ErrAlreadyExists = errors.New("Image already exists")
ErrInvalidRepositoryName = errors.New("Invalid repository name (ex: \"registry.domain.tld/myrepos\")")
ErrLoginRequired = errors.New("Authentication is required.")
errLoginRequired = errors.New("Authentication is required.")
)

func pingRegistryEndpoint(endpoint string) (bool, error) {
Expand Down Expand Up @@ -186,7 +186,7 @@ func (r *Registry) GetRemoteHistory(imgID, registry string, token []string) ([]s
defer res.Body.Close()
if res.StatusCode != 200 {
if res.StatusCode == 401 {
return nil, ErrLoginRequired
return nil, errLoginRequired
}
return nil, utils.NewHTTPRequestError(fmt.Sprintf("Server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res)
}
Expand Down Expand Up @@ -332,7 +332,7 @@ func (r *Registry) GetRepositoryData(remote string) (*RepositoryData, error) {
}
defer res.Body.Close()
if res.StatusCode == 401 {
return nil, ErrLoginRequired
return nil, errLoginRequired
}
// TODO: Right now we're ignoring checksums in the response body.
// In the future, we need to use them to check image validity.
Expand Down

0 comments on commit 4e9164f

Please sign in to comment.