projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
15107: Fix redirect target rewriting.
[arvados.git]
/
lib
/
dispatchcloud
/
ssh_executor
/
executor.go
diff --git
a/lib/dispatchcloud/ssh_executor/executor.go
b/lib/dispatchcloud/ssh_executor/executor.go
index 646e90f31ea8698f6b8d0df3727120cac31f4b64..d608763cf5100d46ca0b1cb2b50a6759a157b1e3 100644
(file)
--- a/
lib/dispatchcloud/ssh_executor/executor.go
+++ b/
lib/dispatchcloud/ssh_executor/executor.go
@@
-173,24
+173,34
@@
func (exr *Executor) sshClient(create bool) (*ssh.Client, error) {
return exr.client, exr.clientErr
}
return exr.client, exr.clientErr
}
-// Create a new SSH client.
-func (exr *Executor) setupSSHClient() (*ssh.Client, error) {
- target := exr.Target()
- addr := target.Address()
+func (exr *Executor) TargetHostPort() (string, string) {
+ addr := exr.Target().Address()
if addr == "" {
if addr == "" {
- return
nil, errors.New("instance has no address")
+ return
"", ""
}
}
- if h, p, err := net.SplitHostPort(addr); err != nil || p == "" {
+ h, p, err := net.SplitHostPort(addr)
+ if err != nil || p == "" {
// Target address does not specify a port. Use
// targetPort, or "ssh".
// Target address does not specify a port. Use
// targetPort, or "ssh".
+ if h == "" {
+ h = addr
+ }
if p = exr.targetPort; p == "" {
p = "ssh"
}
if p = exr.targetPort; p == "" {
p = "ssh"
}
- addr = net.JoinHostPort(h, p)
+ }
+ return h, p
+}
+
+// Create a new SSH client.
+func (exr *Executor) setupSSHClient() (*ssh.Client, error) {
+ addr := net.JoinHostPort(exr.TargetHostPort())
+ if addr == ":" {
+ return nil, errors.New("instance has no address")
}
var receivedKey ssh.PublicKey
client, err := ssh.Dial("tcp", addr, &ssh.ClientConfig{
}
var receivedKey ssh.PublicKey
client, err := ssh.Dial("tcp", addr, &ssh.ClientConfig{
- User:
target
.RemoteUser(),
+ User:
exr.Target()
.RemoteUser(),
Auth: []ssh.AuthMethod{
ssh.PublicKeys(exr.signers...),
},
Auth: []ssh.AuthMethod{
ssh.PublicKeys(exr.signers...),
},
@@
-207,7
+217,7
@@
func (exr *Executor) setupSSHClient() (*ssh.Client, error) {
}
if exr.hostKey == nil || !bytes.Equal(exr.hostKey.Marshal(), receivedKey.Marshal()) {
}
if exr.hostKey == nil || !bytes.Equal(exr.hostKey.Marshal(), receivedKey.Marshal()) {
- err =
target
.VerifyHostKey(receivedKey, client)
+ err =
exr.Target()
.VerifyHostKey(receivedKey, client)
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}