Skip to content

Commit 31d3fb7

Browse files
committed
lfsapi: move SSHTransfer instantiation to lfsapi client
The lfsapi client is used to perform operations for SSH authentication already, so we know we'll have one wherever SSH operations might be done. Let's move the instantiation to the client so that we can reuse it both in the transfer queue code and in the locking code as well.
1 parent c07c98a commit 31d3fb7

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

lfsapi/lfsapi.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/git-lfs/git-lfs/creds"
77
"github.com/git-lfs/git-lfs/errors"
88
"github.com/git-lfs/git-lfs/lfshttp"
9+
"github.com/git-lfs/git-lfs/ssh"
10+
"github.com/rubyist/tracerx"
911
)
1012

1113
type Client struct {
@@ -44,3 +46,21 @@ func NewClient(ctx lfshttp.Context) (*Client, error) {
4446
func (c *Client) Context() lfshttp.Context {
4547
return c.context
4648
}
49+
50+
// SSHTransfer returns either an suitable transfer object or nil if the
51+
// server is not using an SSH remote or the git-lfs-transfer style of SSH
52+
// remote.
53+
func (c *Client) SSHTransfer(operation, remote string) *ssh.SSHTransfer {
54+
endpoint := c.Endpoints.Endpoint(operation, remote)
55+
if len(endpoint.SSHMetadata.UserAndHost) > 0 {
56+
ctx := c.Context()
57+
tracerx.Printf("attempting pure SSH protocol connection")
58+
sshTransfer, err := ssh.NewSSHTransfer(ctx.OSEnv(), ctx.GitEnv(), &endpoint.SSHMetadata, operation)
59+
if err != nil {
60+
tracerx.Printf("pure SSH protocol connection failed: %s", err)
61+
return nil
62+
}
63+
return sshTransfer
64+
}
65+
return nil
66+
}

tq/manifest.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,7 @@ func NewManifest(f *fs.Filesystem, apiClient *lfsapi.Client, operation, remote s
7373
apiClient = cli
7474
}
7575

76-
var sshTransfer *ssh.SSHTransfer
77-
var err error
78-
endpoint := apiClient.Endpoints.RemoteEndpoint(operation, remote)
79-
if len(endpoint.SSHMetadata.UserAndHost) > 0 {
80-
ctx := apiClient.Context()
81-
tracerx.Printf("attempting pure SSH protocol connection")
82-
sshTransfer, err = ssh.NewSSHTransfer(ctx.OSEnv(), ctx.GitEnv(), &endpoint.SSHMetadata, operation)
83-
if err != nil {
84-
tracerx.Printf("pure SSH protocol connection failed: %s", err)
85-
}
86-
}
76+
sshTransfer := apiClient.SSHTransfer(operation, remote)
8777

8878
m := &Manifest{
8979
fs: f,

0 commit comments

Comments
 (0)