forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request git-lfs#183 from github/ssh
SSH support
- Loading branch information
Showing
6 changed files
with
183 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ func TestEndpointDefaultsToOrigin(t *testing.T) { | |
remotes: []string{}, | ||
} | ||
|
||
assert.Equal(t, "abc", config.Endpoint()) | ||
endpoint := config.Endpoint() | ||
assert.Equal(t, "abc", endpoint.Url) | ||
assert.Equal(t, "", endpoint.SshUserAndHost) | ||
assert.Equal(t, "", endpoint.SshPath) | ||
} | ||
|
||
func TestEndpointOverridesOrigin(t *testing.T) { | ||
|
@@ -23,7 +26,10 @@ func TestEndpointOverridesOrigin(t *testing.T) { | |
remotes: []string{}, | ||
} | ||
|
||
assert.Equal(t, "abc", config.Endpoint()) | ||
endpoint := config.Endpoint() | ||
assert.Equal(t, "abc", endpoint.Url) | ||
assert.Equal(t, "", endpoint.SshUserAndHost) | ||
assert.Equal(t, "", endpoint.SshPath) | ||
} | ||
|
||
func TestEndpointNoOverrideDefaultRemote(t *testing.T) { | ||
|
@@ -35,7 +41,10 @@ func TestEndpointNoOverrideDefaultRemote(t *testing.T) { | |
remotes: []string{}, | ||
} | ||
|
||
assert.Equal(t, "abc", config.Endpoint()) | ||
endpoint := config.Endpoint() | ||
assert.Equal(t, "abc", endpoint.Url) | ||
assert.Equal(t, "", endpoint.SshUserAndHost) | ||
assert.Equal(t, "", endpoint.SshPath) | ||
} | ||
|
||
func TestEndpointUseAlternateRemote(t *testing.T) { | ||
|
@@ -49,61 +58,97 @@ func TestEndpointUseAlternateRemote(t *testing.T) { | |
|
||
config.CurrentRemote = "other" | ||
|
||
assert.Equal(t, "def", config.Endpoint()) | ||
endpoint := config.Endpoint() | ||
assert.Equal(t, "def", endpoint.Url) | ||
assert.Equal(t, "", endpoint.SshUserAndHost) | ||
assert.Equal(t, "", endpoint.SshPath) | ||
} | ||
|
||
func TestEndpointAddsMediaSuffix(t *testing.T) { | ||
func TestEndpointAddsLfsSuffix(t *testing.T) { | ||
config := &Configuration{ | ||
gitConfig: map[string]string{"remote.origin.url": "https://example.com/foo/bar"}, | ||
remotes: []string{}, | ||
} | ||
|
||
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", config.Endpoint()) | ||
endpoint := config.Endpoint() | ||
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", endpoint.Url) | ||
assert.Equal(t, "", endpoint.SshUserAndHost) | ||
assert.Equal(t, "", endpoint.SshPath) | ||
} | ||
|
||
func TestBareEndpointAddsMediaSuffix(t *testing.T) { | ||
func TestBareEndpointAddsLfsSuffix(t *testing.T) { | ||
config := &Configuration{ | ||
gitConfig: map[string]string{"remote.origin.url": "https://example.com/foo/bar.git"}, | ||
remotes: []string{}, | ||
} | ||
|
||
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", config.Endpoint()) | ||
endpoint := config.Endpoint() | ||
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", endpoint.Url) | ||
assert.Equal(t, "", endpoint.SshUserAndHost) | ||
assert.Equal(t, "", endpoint.SshPath) | ||
} | ||
|
||
func TestSSHEndpointAddsMediaSuffix(t *testing.T) { | ||
func TestSSHEndpointOverridden(t *testing.T) { | ||
config := &Configuration{ | ||
gitConfig: map[string]string{ | ||
"remote.origin.url": "[email protected]:foo/bar", | ||
"remote.origin.lfs_url": "lfs", | ||
}, | ||
remotes: []string{}, | ||
} | ||
|
||
endpoint := config.Endpoint() | ||
assert.Equal(t, "lfs", endpoint.Url) | ||
assert.Equal(t, "", endpoint.SshUserAndHost) | ||
assert.Equal(t, "", endpoint.SshPath) | ||
} | ||
|
||
func TestSSHEndpointAddsLfsSuffix(t *testing.T) { | ||
config := &Configuration{ | ||
gitConfig: map[string]string{"remote.origin.url": "[email protected]:foo/bar"}, | ||
remotes: []string{}, | ||
} | ||
|
||
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", config.Endpoint()) | ||
endpoint := config.Endpoint() | ||
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", endpoint.Url) | ||
assert.Equal(t, "[email protected]", endpoint.SshUserAndHost) | ||
assert.Equal(t, "foo/bar", endpoint.SshPath) | ||
} | ||
|
||
func TestBareSSHEndpointAddsMediaSuffix(t *testing.T) { | ||
func TestBareSSHEndpointAddsLfsSuffix(t *testing.T) { | ||
config := &Configuration{ | ||
gitConfig: map[string]string{"remote.origin.url": "[email protected]:foo/bar.git"}, | ||
remotes: []string{}, | ||
} | ||
|
||
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", config.Endpoint()) | ||
endpoint := config.Endpoint() | ||
assert.Equal(t, "https://example.com/foo/bar.git/info/lfs", endpoint.Url) | ||
assert.Equal(t, "[email protected]", endpoint.SshUserAndHost) | ||
assert.Equal(t, "foo/bar.git", endpoint.SshPath) | ||
} | ||
|
||
func TestHTTPEndpointAddsMediaSuffix(t *testing.T) { | ||
func TestHTTPEndpointAddsLfsSuffix(t *testing.T) { | ||
config := &Configuration{ | ||
gitConfig: map[string]string{"remote.origin.url": "http://example.com/foo/bar"}, | ||
remotes: []string{}, | ||
} | ||
|
||
assert.Equal(t, "http://example.com/foo/bar.git/info/lfs", config.Endpoint()) | ||
endpoint := config.Endpoint() | ||
assert.Equal(t, "http://example.com/foo/bar.git/info/lfs", endpoint.Url) | ||
assert.Equal(t, "", endpoint.SshUserAndHost) | ||
assert.Equal(t, "", endpoint.SshPath) | ||
} | ||
|
||
func TestBareHTTPEndpointAddsMediaSuffix(t *testing.T) { | ||
func TestBareHTTPEndpointAddsLfsSuffix(t *testing.T) { | ||
config := &Configuration{ | ||
gitConfig: map[string]string{"remote.origin.url": "http://example.com/foo/bar.git"}, | ||
remotes: []string{}, | ||
} | ||
|
||
assert.Equal(t, "http://example.com/foo/bar.git/info/lfs", config.Endpoint()) | ||
endpoint := config.Endpoint() | ||
assert.Equal(t, "http://example.com/foo/bar.git/info/lfs", endpoint.Url) | ||
assert.Equal(t, "", endpoint.SshUserAndHost) | ||
assert.Equal(t, "", endpoint.SshPath) | ||
} | ||
|
||
func TestObjectUrl(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package lfs | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/rubyist/tracerx" | ||
"net/http" | ||
"os/exec" | ||
) | ||
|
||
type sshAuthResponse struct { | ||
Message string `json:"-"` | ||
Header map[string]string `json:"header"` | ||
ExpiresAt string `json:"expires_at"` | ||
} | ||
|
||
func mergeSshHeader(header http.Header, endpoint Endpoint, operation, oid string) error { | ||
if len(endpoint.SshUserAndHost) == 0 { | ||
return nil | ||
} | ||
|
||
res, err := sshAuthenticate(endpoint, operation, oid) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if res.Header != nil { | ||
for key, value := range res.Header { | ||
header.Set(key, value) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func sshAuthenticate(endpoint Endpoint, operation, oid string) (sshAuthResponse, error) { | ||
tracerx.Printf("ssh: %s git-lfs-authenticate %s %s %s", | ||
endpoint.SshUserAndHost, endpoint.SshPath, operation, oid) | ||
cmd := exec.Command("ssh", endpoint.SshUserAndHost, | ||
"git-lfs-authenticate", | ||
endpoint.SshPath, | ||
operation, oid, | ||
) | ||
|
||
out, err := cmd.CombinedOutput() | ||
res := sshAuthResponse{} | ||
|
||
if err != nil { | ||
res.Message = string(out) | ||
} else { | ||
err = json.Unmarshal(out, &res) | ||
} | ||
|
||
return res, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters