-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
connect.go
61 lines (46 loc) · 1.33 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
50
51
52
53
54
55
56
57
58
59
60
61
package actions
import (
"drawbridge/pkg/config"
"drawbridge/pkg/utils"
"path/filepath"
"syscall"
"os"
"os/exec"
)
type ConnectAction struct {
Config config.Interface
}
func (e *ConnectAction) Start(answerData map[string]interface{}) error {
//"-c", "command1; command2; command3; ..."
tmplData, err := e.Config.GetActiveConfigTemplate()
if err != nil {
return nil
}
tmplConfigFilepath, err := utils.PopulateTemplate(tmplData.FilePath, answerData)
if err != nil {
return nil
}
tmplConfigFilepath, err = utils.ExpandPath(filepath.Join(e.Config.GetString("options.config_dir"), tmplConfigFilepath))
if err != nil {
return nil
}
tmplPemFilepath, err := utils.PopulateTemplate(tmplData.PemFilePath, answerData)
if err != nil {
return nil
}
tmplPemFilepath, err = utils.ExpandPath(filepath.Join(e.Config.GetString("options.pem_dir"), tmplPemFilepath))
if err != nil {
return nil
}
//TODO: Print the lines we're running.
//TODO: Check that the bastion host is accessible.
//TODO: add the ssh/pem key to the ssh-agent (if its running).
//https://gobyexample.com/execing-processes
//https://groob.io/posts/golang-execve/
binary, lookErr := exec.LookPath("ssh")
if lookErr != nil {
panic(lookErr)
}
args := []string{"ssh", "bastion", "-F", tmplConfigFilepath}
return syscall.Exec(binary, args, os.Environ())
}