Merge pull request #1507 from arcenik/fix/better-error-msg-for-ssh-addr

Updates ssh connhelper error messages
This commit is contained in:
Sebastiaan van Stijn 2019-01-28 13:48:14 +01:00 committed by GitHub
commit 81e7426e11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 13 deletions

View File

@ -12,7 +12,7 @@ import (
func New(daemonURL string) (string, []string, error) {
sp, err := parseSSHURL(daemonURL)
if err != nil {
return "", nil, err
return "", nil, errors.Wrap(err, "SSH host connection is not valid")
}
return "ssh", append(sp.Args(), []string{"--", "docker", "system", "dial-stdio"}...), nil
}
@ -23,7 +23,7 @@ func parseSSHURL(daemonURL string) (*sshSpec, error) {
return nil, err
}
if u.Scheme != "ssh" {
return nil, errors.Errorf("expected scheme ssh, got %s", u.Scheme)
return nil, errors.Errorf("expected scheme ssh, got %q", u.Scheme)
}
var sp sshSpec
@ -31,22 +31,22 @@ func parseSSHURL(daemonURL string) (*sshSpec, error) {
if u.User != nil {
sp.user = u.User.Username()
if _, ok := u.User.Password(); ok {
return nil, errors.New("ssh helper does not accept plain-text password")
return nil, errors.New("plain-text password is not supported")
}
}
sp.host = u.Hostname()
if sp.host == "" {
return nil, errors.Errorf("host is not specified")
return nil, errors.Errorf("no host specified")
}
sp.port = u.Port()
if u.Path != "" {
return nil, errors.Errorf("extra path: %s", u.Path)
return nil, errors.Errorf("extra path after the host: %q", u.Path)
}
if u.RawQuery != "" {
return nil, errors.Errorf("extra query: %s", u.RawQuery)
return nil, errors.Errorf("extra query after the host: %q", u.RawQuery)
}
if u.Fragment != "" {
return nil, errors.Errorf("extra fragment: %s", u.Fragment)
return nil, errors.Errorf("extra fragment after the host: %q", u.Fragment)
}
return &sp, err
}

View File

@ -29,27 +29,27 @@ func TestParseSSHURL(t *testing.T) {
},
{
url: "ssh://me:passw0rd@foo",
expectedError: "ssh helper does not accept plain-text password",
expectedError: "plain-text password is not supported",
},
{
url: "ssh://foo/bar",
expectedError: "extra path",
expectedError: `extra path after the host: "/bar"`,
},
{
url: "ssh://foo?bar",
expectedError: "extra query",
expectedError: `extra query after the host: "bar"`,
},
{
url: "ssh://foo#bar",
expectedError: "extra fragment",
expectedError: `extra fragment after the host: "bar"`,
},
{
url: "ssh://",
expectedError: "host is not specified",
expectedError: "no host specified",
},
{
url: "foo://bar",
expectedError: "expected scheme ssh",
expectedError: `expected scheme ssh, got "foo"`,
},
}
for _, tc := range testCases {