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

transport: ssh, new DefaultAuthBuilder variable #356

Merged
merged 2 commits into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ before_script:
- make build-git

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

# we only decrypt the SSH key when we aren't in a pull request
- >
if [ "$TRAVIS_PULL_REQUEST" = "false" ] ; then \
bash .travis/install_key.sh; \
SSH_TEST_PRIVATE_KEY=$HOME/.travis/deploy.pem; \
else \
export SSH_AUTH_SOCK=""; \
fi

install:
- go get -v -t ./...

Expand Down
12 changes: 10 additions & 2 deletions .travis/install_key.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
openssl aes-256-cbc -K $encrypted_1477e58fe67a_key -iv $encrypted_1477e58fe67a_iv -in .travis/deploy.pem.enc -out .travis/deploy.pem -d
#!/bin/bash
export SSH_TEST_PRIVATE_KEY=$PWD/.travis/deploy.pem

openssl aes-256-cbc \
-K $encrypted_1477e58fe67a_key \
-iv $encrypted_1477e58fe67a_iv \
-in .travis/deploy.pem.enc \
-out .travis/deploy.pem -d

chmod 600 .travis/deploy.pem
ssh-add .travis/deploy.pem

8 changes: 7 additions & 1 deletion plumbing/transport/ssh/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
// DefaultClient is the default SSH client.
var DefaultClient = common.NewClient(&runner{})

// DefaultAuthBuilder is the function used to create a default AuthMethod, when
// the user doesn't provide any.
var DefaultAuthBuilder = func(user string) (AuthMethod, error) {
return NewSSHAgentAuth(user)
}

type runner struct{}

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

var err error
c.auth, err = NewSSHAgentAuth(u)
c.auth, err = DefaultAuthBuilder(u)
return err
}

Expand Down
19 changes: 15 additions & 4 deletions plumbing/transport/ssh/upload_pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ type UploadPackSuite struct {
var _ = Suite(&UploadPackSuite{})

func (s *UploadPackSuite) SetUpSuite(c *C) {
if os.Getenv("SSH_AUTH_SOCK") == "" {
c.Skip("SSH_AUTH_SOCK is not set")
}

s.setAuthBuilder(c)
s.UploadPackSuite.Client = DefaultClient

ep, err := transport.NewEndpoint("[email protected]:git-fixtures/basic.git")
Expand All @@ -34,3 +31,17 @@ func (s *UploadPackSuite) SetUpSuite(c *C) {
c.Assert(err, IsNil)
s.UploadPackSuite.NonExistentEndpoint = ep
}

func (s *UploadPackSuite) setAuthBuilder(c *C) {
privateKey := os.Getenv("SSH_TEST_PRIVATE_KEY")
if privateKey != "" {
DefaultAuthBuilder = func(user string) (AuthMethod, error) {
return NewPublicKeysFromFile(user, privateKey)
}
}

if privateKey == "" && os.Getenv("SSH_AUTH_SOCK") == "" {
c.Skip("SSH_AUTH_SOCK or SSH_TEST_PRIVATE_KEY are required")
return
}
}