aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/ssh
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-06-13 16:51:02 +0200
committerSantiago M. Mola <santi@mola.io>2017-06-23 19:51:42 +0200
commit93ba5104d5dfaa9ff964d5fcca4cbcb0f55402eb (patch)
tree2fb12269d1c02159476102fc60118b69c8cc03a6 /plumbing/transport/ssh
parentad02bf020460c210660db4fffda7f926b6aae95a (diff)
downloadgo-git-93ba5104d5dfaa9ff964d5fcca4cbcb0f55402eb.tar.gz
transport/ssh: allow passing SSH options
Adds the possibility of passing options to SSH transport. Options have the form of functions modifying ssh.ClientConfig.
Diffstat (limited to 'plumbing/transport/ssh')
-rw-r--r--plumbing/transport/ssh/common.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/plumbing/transport/ssh/common.go b/plumbing/transport/ssh/common.go
index d53fc12..6ab0835 100644
--- a/plumbing/transport/ssh/common.go
+++ b/plumbing/transport/ssh/common.go
@@ -11,7 +11,16 @@ import (
)
// DefaultClient is the default SSH client.
-var DefaultClient = common.NewClient(&runner{})
+var DefaultClient = NewClient()
+
+// NewClient creates a new SSH client with the given options.
+func NewClient(opts ...ClientOption) transport.Transport {
+ return common.NewClient(&runner{options: opts})
+}
+
+// ClientOption is a function that gets a standard ssh.ClientConfig and modifies
+// it.
+type ClientOption func(config *ssh.ClientConfig)
// DefaultAuthBuilder is the function used to create a default AuthMethod, when
// the user doesn't provide any.
@@ -21,10 +30,12 @@ var DefaultAuthBuilder = func(user string) (AuthMethod, error) {
const DefaultPort = 22
-type runner struct{}
+type runner struct {
+ options []ClientOption
+}
func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthMethod) (common.Command, error) {
- c := &command{command: cmd, endpoint: ep}
+ c := &command{command: cmd, endpoint: ep, options: r.options}
if auth != nil {
c.setAuth(auth)
}
@@ -42,6 +53,7 @@ type command struct {
endpoint transport.Endpoint
client *ssh.Client
auth AuthMethod
+ options []ClientOption
}
func (c *command) setAuth(auth transport.AuthMethod) error {
@@ -95,6 +107,10 @@ func (c *command) connect() error {
return err
}
+ for _, opt := range c.options {
+ opt(config)
+ }
+
c.client, err = ssh.Dial("tcp", c.getHostWithPort(), config)
if err != nil {
return err