2015-03-29 23:13:50 +00:00
|
|
|
package lfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os/exec"
|
2015-05-13 19:43:41 +00:00
|
|
|
|
2015-05-25 18:20:50 +00:00
|
|
|
"github.com/github/git-lfs/vendor/_nuts/github.com/rubyist/tracerx"
|
2015-03-29 23:13:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type sshAuthResponse struct {
|
|
|
|
Message string `json:"-"`
|
2015-04-22 22:51:30 +00:00
|
|
|
Href string `json:"href"`
|
2015-03-29 23:13:50 +00:00
|
|
|
Header map[string]string `json:"header"`
|
|
|
|
ExpiresAt string `json:"expires_at"`
|
|
|
|
}
|
|
|
|
|
2015-04-22 22:51:30 +00:00
|
|
|
func sshAuthenticate(endpoint Endpoint, operation, oid string) (sshAuthResponse, error) {
|
|
|
|
res := sshAuthResponse{}
|
2015-03-29 23:13:50 +00:00
|
|
|
if len(endpoint.SshUserAndHost) == 0 {
|
2015-04-22 22:51:30 +00:00
|
|
|
return res, nil
|
2015-03-29 23:13:50 +00:00
|
|
|
}
|
|
|
|
|
2015-03-30 06:00:34 +00:00
|
|
|
tracerx.Printf("ssh: %s git-lfs-authenticate %s %s %s",
|
2015-03-29 23:13:50 +00:00
|
|
|
endpoint.SshUserAndHost, endpoint.SshPath, operation, oid)
|
|
|
|
cmd := exec.Command("ssh", endpoint.SshUserAndHost,
|
|
|
|
"git-lfs-authenticate",
|
|
|
|
endpoint.SshPath,
|
|
|
|
operation, oid,
|
|
|
|
)
|
|
|
|
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
res.Message = string(out)
|
|
|
|
} else {
|
|
|
|
err = json.Unmarshal(out, &res)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, err
|
|
|
|
}
|