/
connect.go
49 lines (38 loc) · 1.07 KB
/
connect.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
package main
import (
"io"
"net"
"os"
"path"
)
type CommandConnect struct {
}
func (x *CommandConnect) Execute(args []string) error {
// Connect to the local autobuild socket and act as gateway
var filename string
if len(args) == 1 {
filename = args[0]
} else {
filename = path.Join(options.Base, "run", "autobuild.sock")
}
cl, err := net.Dial("unix", filename)
if err != nil {
return err
}
if err := RemoteSendCredentials(cl.(*net.UnixConn)); err != nil {
return err
}
go func() {
io.Copy(cl, os.Stdin)
cl.Close()
}()
_, err = io.Copy(os.Stdout, cl)
// Wait for both to finish
return err
}
func init() {
parser.AddCommand("connect",
"Connect to a the autobuild socket and relay stdin",
"The connect command connects to a autobuild socket and then relays all data on standard in to this connection. When using a remote connection (-r, --remote) for client commands (such as stage or release), a ssh connection is made to the remote and `autobuild connect' is executed allowing the remote call with proper authentication.",
&CommandConnect{})
}