aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/ssh/auth_method.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-02-21 18:17:29 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-02-21 18:17:29 +0100
commitcd435d9a72a866f8dcb5e64d4fd0d821b8569006 (patch)
tree2914236e3e680d92db9bb6278bdd12656c257a4a /plumbing/transport/ssh/auth_method.go
parente26a605c93d8085dfff8e440838fd3c43b63cff6 (diff)
downloadgo-git-cd435d9a72a866f8dcb5e64d4fd0d821b8569006.tar.gz
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{