mirror of https://github.com/docker/cli.git
Merge pull request #2559 from tiborvass/sshfix
ssh: avoid setting flags through hostname
This commit is contained in:
commit
82de74a5e3
|
@ -34,7 +34,7 @@ func GetConnectionHelper(daemonURL string) (*ConnectionHelper, error) {
|
||||||
}
|
}
|
||||||
return &ConnectionHelper{
|
return &ConnectionHelper{
|
||||||
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
return commandconn.New(ctx, "ssh", append(sp.Args(), []string{"--", "docker", "system", "dial-stdio"}...)...)
|
return commandconn.New(ctx, "ssh", sp.Args("docker", "system", "dial-stdio")...)
|
||||||
},
|
},
|
||||||
Host: "http://docker",
|
Host: "http://docker",
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -49,8 +49,8 @@ type Spec struct {
|
||||||
Port string
|
Port string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Args returns args except "ssh" itself and "-- ..."
|
// Args returns args except "ssh" itself combined with optional additional command args
|
||||||
func (sp *Spec) Args() []string {
|
func (sp *Spec) Args(add ...string) []string {
|
||||||
var args []string
|
var args []string
|
||||||
if sp.User != "" {
|
if sp.User != "" {
|
||||||
args = append(args, "-l", sp.User)
|
args = append(args, "-l", sp.User)
|
||||||
|
@ -58,6 +58,7 @@ func (sp *Spec) Args() []string {
|
||||||
if sp.Port != "" {
|
if sp.Port != "" {
|
||||||
args = append(args, "-p", sp.Port)
|
args = append(args, "-p", sp.Port)
|
||||||
}
|
}
|
||||||
args = append(args, sp.Host)
|
args = append(args, "--", sp.Host)
|
||||||
|
args = append(args, add...)
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ func TestParseURL(t *testing.T) {
|
||||||
{
|
{
|
||||||
url: "ssh://foo",
|
url: "ssh://foo",
|
||||||
expectedArgs: []string{
|
expectedArgs: []string{
|
||||||
"foo",
|
"--", "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,7 @@ func TestParseURL(t *testing.T) {
|
||||||
expectedArgs: []string{
|
expectedArgs: []string{
|
||||||
"-l", "me",
|
"-l", "me",
|
||||||
"-p", "10022",
|
"-p", "10022",
|
||||||
"foo",
|
"--", "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -53,12 +53,14 @@ func TestParseURL(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
sp, err := ParseURL(tc.url)
|
t.Run(tc.url, func(t *testing.T) {
|
||||||
if tc.expectedError == "" {
|
sp, err := ParseURL(tc.url)
|
||||||
assert.NilError(t, err)
|
if tc.expectedError == "" {
|
||||||
assert.Check(t, is.DeepEqual(tc.expectedArgs, sp.Args()))
|
assert.NilError(t, err)
|
||||||
} else {
|
assert.Check(t, is.DeepEqual(tc.expectedArgs, sp.Args()))
|
||||||
assert.ErrorContains(t, err, tc.expectedError)
|
} else {
|
||||||
}
|
assert.ErrorContains(t, err, tc.expectedError)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue