github.com/psexton/git-lfs@v2.1.1-0.20170517224304-289a18b2bc53+incompatible/test/cmd/ssh-echo.go (about) 1 // +build testtools 2 3 package main 4 5 import ( 6 "encoding/json" 7 "fmt" 8 "os" 9 "strings" 10 "time" 11 ) 12 13 type sshResponse struct { 14 Href string `json:"href"` 15 Header map[string]string `json:"header"` 16 ExpiresAt time.Time `json:"expires_at,omitempty"` 17 ExpiresIn int `json:"expires_in,omitempty"` 18 } 19 20 func main() { 21 // expect args: 22 // ssh-echo -p PORT git@127.0.0.1 git-lfs-authenticate REPO OPERATION 23 if len(os.Args) != 5 { 24 fmt.Fprintf(os.Stderr, "got %d args: %v", len(os.Args), os.Args) 25 os.Exit(1) 26 } 27 28 // just "git-lfs-authenticate REPO OPERATION" 29 authLine := strings.Split(os.Args[4], " ") 30 if len(authLine) < 13 { 31 fmt.Fprintf(os.Stderr, "bad git-lfs-authenticate line: %s\nargs: %v", authLine, os.Args) 32 } 33 34 repo := authLine[1] 35 36 r := &sshResponse{ 37 Href: fmt.Sprintf("http://127.0.0.1:%s/%s.git/info/lfs", os.Args[2], repo), 38 } 39 switch repo { 40 case "ssh-expired-absolute": 41 r.ExpiresAt = time.Now().Add(-5 * time.Minute) 42 case "ssh-expired-relative": 43 r.ExpiresIn = -5 44 case "ssh-expired-both": 45 r.ExpiresAt = time.Now().Add(-5 * time.Minute) 46 r.ExpiresIn = -5 47 } 48 49 json.NewEncoder(os.Stdout).Encode(r) 50 }