Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit c97bd89

Browse files
committed
ssh: leverage proxy from environment
Signed-off-by: Jacob Blain Christen <[email protected]>
1 parent 948b0c9 commit c97bd89

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

plumbing/transport/ssh/common.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/kevinburke/ssh_config"
1313
"golang.org/x/crypto/ssh"
14+
"golang.org/x/net/proxy"
1415
)
1516

1617
// DefaultClient is the default SSH client.
@@ -115,7 +116,7 @@ func (c *command) connect() error {
115116

116117
overrideConfig(c.config, config)
117118

118-
c.client, err = ssh.Dial("tcp", c.getHostWithPort(), config)
119+
c.client, err = dial("tcp", c.getHostWithPort(), config)
119120
if err != nil {
120121
return err
121122
}
@@ -130,6 +131,19 @@ func (c *command) connect() error {
130131
return nil
131132
}
132133

134+
func dial(network, addr string, config *ssh.ClientConfig) (*ssh.Client, error) {
135+
dialer := proxy.FromEnvironment()
136+
conn, err := dialer.Dial(network, addr)
137+
if err != nil {
138+
return nil, err
139+
}
140+
c, chans, reqs, err := ssh.NewClientConn(conn, addr, config)
141+
if err != nil {
142+
return nil, err
143+
}
144+
return ssh.NewClient(c, chans, reqs), nil
145+
}
146+
133147
func (c *command) getHostWithPort() string {
134148
if addr, found := c.doGetHostWithPortFromSSHConfig(); found {
135149
return addr

0 commit comments

Comments
 (0)