2020-04-22 16:59:29 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package googlecompute
|
|
|
|
|
|
|
|
import (
|
2020-04-22 17:09:19 -04:00
|
|
|
"context"
|
2020-04-22 17:26:50 -04:00
|
|
|
"log"
|
|
|
|
"os/exec"
|
2020-04-22 16:59:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewTunnelDriver() TunnelDriver {
|
|
|
|
return &TunnelDriverWindows{}
|
|
|
|
}
|
|
|
|
|
2020-04-22 17:05:38 -04:00
|
|
|
type TunnelDriverWindows struct {
|
2020-04-22 17:26:50 -04:00
|
|
|
cmd *exec.Cmd
|
2020-04-22 16:59:29 -04:00
|
|
|
}
|
|
|
|
|
2020-07-07 18:37:45 -04:00
|
|
|
func (t *TunnelDriverWindows) StartTunnel(cancelCtx context.Context, tempScriptFileName string, timeout int) error {
|
2020-04-29 15:13:22 -04:00
|
|
|
args := []string{"/C", "call", tempScriptFileName}
|
|
|
|
cmd := exec.CommandContext(cancelCtx, "cmd", args...)
|
2020-07-07 18:37:45 -04:00
|
|
|
err := RunTunnelCommand(cmd, timeout)
|
2020-04-22 17:26:50 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Store successful command on step so we can access it to cancel it
|
|
|
|
// later.
|
|
|
|
t.cmd = cmd
|
|
|
|
return nil
|
2020-04-22 16:59:29 -04:00
|
|
|
}
|
|
|
|
|
2020-04-22 17:26:50 -04:00
|
|
|
func (t *TunnelDriverWindows) StopTunnel() {
|
|
|
|
if t.cmd != nil && t.cmd.Process != nil {
|
|
|
|
err := t.cmd.Process.Kill()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Issue stopping IAP tunnel: %s", err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Printf("Couldn't find IAP tunnel process to kill. Continuing.")
|
|
|
|
}
|
|
|
|
}
|