-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexternal-command.go
41 lines (35 loc) · 1.29 KB
/
external-command.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
package awssh
import (
"context"
"os"
"os/exec"
"time"
)
const (
CmdSessionManagerPlugin string = "session-manager-plugin"
CmdSessionManagerPluginOrder string = "StartSession"
CmdSsh string = "ssh"
)
func execExternalCommand(ctx context.Context, externalCommand string, args []string) (command *exec.Cmd, err error) {
command = exec.CommandContext(ctx, externalCommand, args[0:]...)
command.Stdout = os.Stdout
command.Stderr = os.Stderr
command.Stdin = os.Stdin
err = command.Start()
return command, err
}
func execSessionManagerPortForwarding(ctx context.Context, tokens, region, sessionManagerParam, url string) (command *exec.Cmd, err error) {
args := []string{tokens, region, CmdSessionManagerPluginOrder, "", sessionManagerParam, url}
command, err = execExternalCommand(ctx, CmdSessionManagerPlugin, args)
time.Sleep(1 * time.Second)
return command, err
}
func checkSessionManagerCommandIsExist() (err error) {
err = exec.Command(CmdSessionManagerPlugin, "--version").Run()
return err
}
func execSshCommand(ctx context.Context, username, host, port, identityFilePath string) (command *exec.Cmd, err error) {
args := []string{"-p", port, "-i", identityFilePath, username + "@" + host}
command, err = execExternalCommand(ctx, CmdSsh, args)
return command, err
}