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

Commit

Permalink
ssh: leverage proxy from environment
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Blain Christen <[email protected]>
  • Loading branch information
dweomer committed Mar 20, 2019
1 parent 948b0c9 commit c97bd89
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion plumbing/transport/ssh/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/kevinburke/ssh_config"
"golang.org/x/crypto/ssh"
"golang.org/x/net/proxy"
)

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

overrideConfig(c.config, config)

c.client, err = ssh.Dial("tcp", c.getHostWithPort(), config)
c.client, err = dial("tcp", c.getHostWithPort(), config)
if err != nil {
return err
}
Expand All @@ -130,6 +131,19 @@ func (c *command) connect() error {
return nil
}

func dial(network, addr string, config *ssh.ClientConfig) (*ssh.Client, error) {
dialer := proxy.FromEnvironment()
conn, err := dialer.Dial(network, addr)
if err != nil {
return nil, err
}
c, chans, reqs, err := ssh.NewClientConn(conn, addr, config)
if err != nil {
return nil, err
}
return ssh.NewClient(c, chans, reqs), nil
}

func (c *command) getHostWithPort() string {
if addr, found := c.doGetHostWithPortFromSSHConfig(); found {
return addr
Expand Down

0 comments on commit c97bd89

Please sign in to comment.