github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/util/clissh/secure_dialer.go (about)

     1  package clissh
     2  
     3  import (
     4  	"golang.org/x/crypto/ssh"
     5  	"golang.org/x/net/proxy"
     6  )
     7  
     8  //go:generate counterfeiter . SecureDialer
     9  
    10  type SecureDialer interface {
    11  	Dial(network, address string, config *ssh.ClientConfig) (SecureClient, error)
    12  }
    13  
    14  type secureDialer struct{}
    15  
    16  func DefaultSecureDialer() secureDialer {
    17  	return secureDialer{}
    18  }
    19  
    20  func (secureDialer) Dial(network string, address string, config *ssh.ClientConfig) (SecureClient, error) {
    21  	conn, err := proxy.FromEnvironment().Dial(network, address)
    22  	if err != nil {
    23  		return secureClient{}, err
    24  	}
    25  
    26  	c, chans, reqs, err := ssh.NewClientConn(conn, address, config)
    27  	if err != nil {
    28  		return secureClient{}, err
    29  	}
    30  	client := ssh.NewClient(c, chans, reqs)
    31  
    32  	return secureClient{client: client}, nil
    33  }