mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-25 09:14:01 -04:00
SOCKS5 proxy support
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/net/proxy"
|
||||
)
|
||||
|
||||
// ConnectFunc is a convenience method for returning a function
|
||||
@@ -27,6 +28,25 @@ func ConnectFunc(network, addr string) func() (net.Conn, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// ConnectFunc is a convenience method for returning a function
|
||||
// that connects to a host using SOCKS5 proxy
|
||||
func ProxyConnectFunc(socksProxy string, socksAuth *proxy.Auth, network, addr string) func() (net.Conn, error) {
|
||||
return func() (net.Conn, error) {
|
||||
// create a socks5 dialer
|
||||
dialer, err := proxy.SOCKS5("tcp", socksProxy, socksAuth, proxy.Direct)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Can't connect to the proxy: %s", err)
|
||||
}
|
||||
|
||||
c, err := dialer.Dial(network, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
|
||||
// BastionConnectFunc is a convenience method for returning a function
|
||||
// that connects to a host over a bastion connection.
|
||||
func BastionConnectFunc(
|
||||
|
||||
Reference in New Issue
Block a user