Skip to content

Commit

Permalink
ugly refactor for golang platform builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mikew committed Nov 10, 2024
1 parent 4b68304 commit 7cfd20f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
12 changes: 12 additions & 0 deletions src/go_ssh_ext/conn_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !windows
// +build !windows

package go_ssh_ext

import (
"net"
)

func getConnectionForAgent(sshAuthSock string) (net.Conn, error) {
return net.Dial("unix", sshAuthSock)
}
14 changes: 14 additions & 0 deletions src/go_ssh_ext/conn_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build windows
// +build windows

package go_ssh_ext

import (
"net"

"github.com/Microsoft/go-winio"
)

func getConnectionForAgent(sshAuthSock string) (net.Conn, error) {
return winio.DialPipe(sshAuthSock, nil)
}
22 changes: 4 additions & 18 deletions src/go_ssh_ext/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"runtime"
"syscall"

"github.com/Microsoft/go-winio"
"github.com/kevinburke/ssh_config"
"github.com/skeema/knownhosts"
"golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -182,23 +181,10 @@ func getSignersForIdentityAgent(hostname string) ([]ssh.Signer, error) {

sshAuthSock = CleanupSshConfigValue(sshAuthSock)

var conn net.Conn
if runtime.GOOS == "windows" {
//inner_conn, err := namedpipe.DialContext(context.Background(), sshAuthSock)
// inner_conn, err := npipe.Dial(sshAuthSock)
inner_conn, err := winio.DialPipe(sshAuthSock, nil)
if err != nil {
slog.Error("Failed to open SSH auth socket", "err", err)
return nil, err
}
conn = inner_conn
} else {
inner_conn, err := net.Dial("unix", sshAuthSock)
if err != nil {
slog.Error("Failed to open SSH auth socket", "err", err)
return nil, err
}
conn = inner_conn
conn, err := getConnectionForAgent(sshAuthSock)
if err != nil {
slog.Error("Failed to open SSH auth socket", "err", err)
return nil, err
}

slog.Info("Using ssh agent", "socket", sshAuthSock)
Expand Down

0 comments on commit 7cfd20f

Please sign in to comment.