aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/ssh/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/transport/ssh/common.go')
-rw-r--r--plumbing/transport/ssh/common.go22
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