aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/ssh/auth_method.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-02-21 18:57:57 +0100
committerGitHub <noreply@github.com>2017-02-21 18:57:57 +0100
commit6430e6c694285b8f87c21bd72a766609b7dcf4a4 (patch)
tree273e4441b84d4c266ff87de12deafc357dca2352 /plumbing/transport/ssh/auth_method.go
parent4e4a85703c5ce5384a58e85bafc58cc235793ab8 (diff)
parentcd435d9a72a866f8dcb5e64d4fd0d821b8569006 (diff)
downloadgo-git-6430e6c694285b8f87c21bd72a766609b7dcf4a4.tar.gz
Merge pull request #282 from mcuadros/ssh-agent-fix
plumbing/transport: git, error on empty SSH_AUTH_SOCK
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{