mirror of https://github.com/docker/cli.git
ssh: avoid setting flags through hostname
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit d30970e3b1
)
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
fd7874f16d
commit
2ee7981985
|
@ -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,6 +53,7 @@ func TestParseURL(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.url, func(t *testing.T) {
|
||||||
sp, err := ParseURL(tc.url)
|
sp, err := ParseURL(tc.url)
|
||||||
if tc.expectedError == "" {
|
if tc.expectedError == "" {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
@ -60,5 +61,6 @@ func TestParseURL(t *testing.T) {
|
||||||
} else {
|
} else {
|
||||||
assert.ErrorContains(t, err, tc.expectedError)
|
assert.ErrorContains(t, err, tc.expectedError)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue