aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/ssh/auth_method.go
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/transport/ssh/auth_method.go')
-rw-r--r--plumbing/transport/ssh/auth_method.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/plumbing/transport/ssh/auth_method.go b/plumbing/transport/ssh/auth_method.go
index 9c3d6f3..f53e510 100644
--- a/plumbing/transport/ssh/auth_method.go
+++ b/plumbing/transport/ssh/auth_method.go
@@ -1,6 +1,7 @@
package ssh
import (
+ "errors"
"fmt"
"net"
"os"
@@ -9,6 +10,8 @@ import (
"golang.org/x/crypto/ssh/agent"
)
+var ErrEmptySSHAgentAddr = errors.New("SSH_AUTH_SOCK env variable is required")
+
// AuthMethod is the interface all auth methods for the ssh client
// must implement. The clientConfig method returns the ssh client
// configuration needed to establish an ssh connection.
@@ -138,16 +141,21 @@ func (a *PublicKeysCallback) clientConfig() *ssh.ClientConfig {
const DefaultSSHUsername = "git"
-// Opens a pipe with the ssh agent and uses the pipe
+// NewSSHAgentAuth opens a pipe with the SSH agent and uses the pipe
// as the implementer of the public key callback function.
func NewSSHAgentAuth(user string) (*PublicKeysCallback, error) {
if user == "" {
user = DefaultSSHUsername
}
- pipe, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
+ sshAgentAddr := os.Getenv("SSH_AUTH_SOCK")
+ if sshAgentAddr == "" {
+ return nil, ErrEmptySSHAgentAddr
+ }
+
+ pipe, err := net.Dial("unix", sshAgentAddr)
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("error connecting to SSH agent: %q", err)
}
return &PublicKeysCallback{