-
Notifications
You must be signed in to change notification settings - Fork 371
/
ssh.go
64 lines (49 loc) · 1.6 KB
/
ssh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2017 Gorillalabs. All rights reserved.
package backend
import (
"io"
)
// sshSession exists so we don't create a hard dependency on crypto/ssh.
type sshSession interface {
Waiter
StdinPipe() (io.WriteCloser, error)
StdoutPipe() (io.Reader, error)
StderrPipe() (io.Reader, error)
Start(string) error
}
type SSH struct {
Session sshSession
}
// func (b *SSH) StartProcess(cmd string, args ...string) (Waiter, io.Writer, io.Reader, io.Reader, error) {
// stdin, err := b.Session.StdinPipe()
// if err != nil {
// return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the SSH session's stdin stream")
// }
// stdout, err := b.Session.StdoutPipe()
// if err != nil {
// return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the SSH session's stdout stream")
// }
// stderr, err := b.Session.StderrPipe()
// if err != nil {
// return nil, nil, nil, nil, errors.Annotate(err, "Could not get hold of the SSH session's stderr stream")
// }
// err = b.Session.Start(b.createCmd(cmd, args))
// if err != nil {
// return nil, nil, nil, nil, errors.Annotate(err, "Could not spawn process via SSH")
// }
// return b.Session, stdin, stdout, stderr, nil
// }
// func (b *SSH) createCmd(cmd string, args []string) string {
// parts := []string{cmd}
// simple := regexp.MustCompile(`^[a-z0-9_/.~+-]+$`)
// for _, arg := range args {
// if !simple.MatchString(arg) {
// arg = b.quote(arg)
// }
// parts = append(parts, arg)
// }
// return strings.Join(parts, " ")
// }
// func (b *SSH) quote(s string) string {
// return fmt.Sprintf(`"%s"`, s)
// }