2017-01-04 18:16:07 +00:00
|
|
|
// +build testtools
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
2017-04-05 19:59:52 +00:00
|
|
|
"time"
|
2017-01-04 18:16:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type sshResponse struct {
|
2017-04-05 19:59:52 +00:00
|
|
|
Href string `json:"href"`
|
|
|
|
Header map[string]string `json:"header"`
|
|
|
|
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
2017-04-05 20:46:45 +00:00
|
|
|
ExpiresIn int `json:"expires_in,omitempty"`
|
2017-01-04 18:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// expect args:
|
|
|
|
// ssh-echo -p PORT git@127.0.0.1 git-lfs-authenticate REPO OPERATION
|
|
|
|
if len(os.Args) != 5 {
|
|
|
|
fmt.Fprintf(os.Stderr, "got %d args: %v", len(os.Args), os.Args)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// just "git-lfs-authenticate REPO OPERATION"
|
|
|
|
authLine := strings.Split(os.Args[4], " ")
|
|
|
|
if len(authLine) < 13 {
|
|
|
|
fmt.Fprintf(os.Stderr, "bad git-lfs-authenticate line: %s\nargs: %v", authLine, os.Args)
|
|
|
|
}
|
|
|
|
|
2017-04-05 19:59:52 +00:00
|
|
|
repo := authLine[1]
|
|
|
|
|
|
|
|
r := &sshResponse{
|
|
|
|
Href: fmt.Sprintf("http://127.0.0.1:%s/%s.git/info/lfs", os.Args[2], repo),
|
|
|
|
}
|
|
|
|
switch repo {
|
|
|
|
case "ssh-expired-absolute":
|
|
|
|
r.ExpiresAt = time.Now().Add(-5 * time.Minute)
|
|
|
|
case "ssh-expired-relative":
|
2017-04-05 20:32:37 +00:00
|
|
|
r.ExpiresIn = -5
|
2017-04-05 19:59:52 +00:00
|
|
|
case "ssh-expired-both":
|
|
|
|
r.ExpiresAt = time.Now().Add(-5 * time.Minute)
|
2017-04-05 20:32:37 +00:00
|
|
|
r.ExpiresIn = -5
|
2017-04-05 19:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
json.NewEncoder(os.Stdout).Encode(r)
|
2017-01-04 18:16:07 +00:00
|
|
|
}
|