Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit fd36116

Browse files
authored
Merge pull request #356 from mcuadros/ssh-default-auth
transport: ssh, new DefaultAuthBuilder variable
2 parents 9e4f992 + 63bbba6 commit fd36116

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

.travis.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ before_script:
2525
- make build-git
2626

2727
before_install:
28-
- eval "$(ssh-agent -s)"
29-
# we only decrypt the SSH key when we aren't in a pull request
30-
#- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash .travis/install_key.sh; fi'
31-
#- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export SSH_AUTH_SOCK="" ; fi'\
32-
# temporal fix skip of SSH test
33-
- export SSH_AUTH_SOCK=""
3428
- git config --global user.email "[email protected]"
3529
- git config --global user.name "Travis CI"
3630

31+
# we only decrypt the SSH key when we aren't in a pull request
32+
- >
33+
if [ "$TRAVIS_PULL_REQUEST" = "false" ] ; then \
34+
bash .travis/install_key.sh; \
35+
SSH_TEST_PRIVATE_KEY=$HOME/.travis/deploy.pem; \
36+
else \
37+
export SSH_AUTH_SOCK=""; \
38+
fi
39+
3740
install:
3841
- go get -v -t ./...
3942

.travis/install_key.sh

100644100755
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
openssl aes-256-cbc -K $encrypted_1477e58fe67a_key -iv $encrypted_1477e58fe67a_iv -in .travis/deploy.pem.enc -out .travis/deploy.pem -d
1+
#!/bin/bash
2+
export SSH_TEST_PRIVATE_KEY=$PWD/.travis/deploy.pem
3+
4+
openssl aes-256-cbc \
5+
-K $encrypted_1477e58fe67a_key \
6+
-iv $encrypted_1477e58fe67a_iv \
7+
-in .travis/deploy.pem.enc \
8+
-out .travis/deploy.pem -d
9+
210
chmod 600 .travis/deploy.pem
3-
ssh-add .travis/deploy.pem
11+

plumbing/transport/ssh/common.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import (
1414
// DefaultClient is the default SSH client.
1515
var DefaultClient = common.NewClient(&runner{})
1616

17+
// DefaultAuthBuilder is the function used to create a default AuthMethod, when
18+
// the user doesn't provide any.
19+
var DefaultAuthBuilder = func(user string) (AuthMethod, error) {
20+
return NewSSHAgentAuth(user)
21+
}
22+
1723
type runner struct{}
1824

1925
func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthMethod) (common.Command, error) {
@@ -119,7 +125,7 @@ func (c *command) setAuthFromEndpoint() error {
119125
}
120126

121127
var err error
122-
c.auth, err = NewSSHAgentAuth(u)
128+
c.auth, err = DefaultAuthBuilder(u)
123129
return err
124130
}
125131

plumbing/transport/ssh/upload_pack_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ type UploadPackSuite struct {
1616
var _ = Suite(&UploadPackSuite{})
1717

1818
func (s *UploadPackSuite) SetUpSuite(c *C) {
19-
if os.Getenv("SSH_AUTH_SOCK") == "" {
20-
c.Skip("SSH_AUTH_SOCK is not set")
21-
}
22-
19+
s.setAuthBuilder(c)
2320
s.UploadPackSuite.Client = DefaultClient
2421

2522
ep, err := transport.NewEndpoint("[email protected]:git-fixtures/basic.git")
@@ -34,3 +31,17 @@ func (s *UploadPackSuite) SetUpSuite(c *C) {
3431
c.Assert(err, IsNil)
3532
s.UploadPackSuite.NonExistentEndpoint = ep
3633
}
34+
35+
func (s *UploadPackSuite) setAuthBuilder(c *C) {
36+
privateKey := os.Getenv("SSH_TEST_PRIVATE_KEY")
37+
if privateKey != "" {
38+
DefaultAuthBuilder = func(user string) (AuthMethod, error) {
39+
return NewPublicKeysFromFile(user, privateKey)
40+
}
41+
}
42+
43+
if privateKey == "" && os.Getenv("SSH_AUTH_SOCK") == "" {
44+
c.Skip("SSH_AUTH_SOCK or SSH_TEST_PRIVATE_KEY are required")
45+
return
46+
}
47+
}

0 commit comments

Comments
 (0)