Add default remote socket path if empty

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
This commit is contained in:
Anders F Björklund
2024-09-01 22:30:19 +02:00
parent 48a8a9c22c
commit b455f94ca8

View File

@ -1,6 +1,7 @@
package bindings
import (
"bytes"
"context"
"errors"
"fmt"
@ -210,6 +211,22 @@ func sshClient(_url *url.URL, uri string, identity string, machine bool) (Connec
if err != nil {
return connection, newConnectError(err)
}
if _url.Path == "" {
session, err := conn.NewSession()
if err != nil {
return connection, err
}
defer session.Close()
var b bytes.Buffer
session.Stdout = &b
if err := session.Run(
"podman info --format '{{.Host.RemoteSocket.Path}}'"); err != nil {
return connection, err
}
val := strings.TrimSuffix(b.String(), "\n")
_url.Path = val
}
dialContext := func(ctx context.Context, _, _ string) (net.Conn, error) {
return ssh.DialNet(conn, "unix", _url)
}