diff options
author | Anthony Weems <amlweems@gmail.com> | 2017-01-17 11:17:11 -0600 |
---|---|---|
committer | Santiago M. Mola <santi@mola.io> | 2017-01-17 18:17:11 +0100 |
commit | 6593c757346f9817a770ff0ea091cce3e8243070 (patch) | |
tree | 6fbb72583931b0386e382177970650a9cdbca4eb /plumbing/transport/ssh | |
parent | 241e8ba00ac9533299d62dc38684305af2b6c301 (diff) | |
download | go-git-6593c757346f9817a770ff0ea091cce3e8243070.tar.gz |
transport: remove SetAuth, fixes #206 (#210)
* remove SetAuth functions, implement at NewUploadPackSession/NewReceivePackSession level.
* propagate transport.Auth from Fetch/Pull/Clone options to the transport API.
Diffstat (limited to 'plumbing/transport/ssh')
-rw-r--r-- | plumbing/transport/ssh/common.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/plumbing/transport/ssh/common.go b/plumbing/transport/ssh/common.go index 03d2fe1..7d72d26 100644 --- a/plumbing/transport/ssh/common.go +++ b/plumbing/transport/ssh/common.go @@ -1,7 +1,6 @@ package ssh import ( - "errors" "fmt" "strings" @@ -11,21 +10,20 @@ import ( "golang.org/x/crypto/ssh" ) -var ( - errAlreadyConnected = errors.New("ssh session already created") -) - // DefaultClient is the default SSH client. var DefaultClient = common.NewClient(&runner{}) type runner struct{} -func (r *runner) Command(cmd string, ep transport.Endpoint) (common.Command, error) { +func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthMethod) (common.Command, error) { c := &command{command: cmd, endpoint: ep} + if auth != nil { + c.setAuth(auth) + } + if err := c.connect(); err != nil { return nil, err } - return c, nil } @@ -38,7 +36,7 @@ type command struct { auth AuthMethod } -func (c *command) SetAuth(auth transport.AuthMethod) error { +func (c *command) setAuth(auth transport.AuthMethod) error { a, ok := auth.(AuthMethod) if !ok { return transport.ErrInvalidAuthMethod @@ -73,11 +71,13 @@ func (c *command) Close() error { // environment var. func (c *command) connect() error { if c.connected { - return errAlreadyConnected + return transport.ErrAlreadyConnected } - if err := c.setAuthFromEndpoint(); err != nil { - return err + if c.auth == nil { + if err := c.setAuthFromEndpoint(); err != nil { + return err + } } var err error |