-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e8fcf3
commit 5ca286b
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package utils | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
"runtime" | ||
"strings" | ||
"time" | ||
|
||
"github.com/briandowns/spinner" | ||
) | ||
|
||
func AwsVpnInit() error { | ||
if runtime.GOOS == "linux" { | ||
return fmt.Errorf("this function is not intended to run on Linux") | ||
} | ||
|
||
s := spinner.New(spinner.CharSets[39], 100*time.Millisecond) | ||
s.Suffix = " doing woof magic to start aws vpn" | ||
|
||
for { | ||
s.Start() | ||
cmd := exec.Command("ps", "ax") | ||
var out bytes.Buffer | ||
cmd.Stdout = &out | ||
err := cmd.Run() | ||
if err != nil { | ||
s.Stop() | ||
return fmt.Errorf("failed to execute ps command: %v", err) | ||
} | ||
|
||
vpnAlive := false | ||
for _, line := range strings.Split(out.String(), "\n") { | ||
if strings.Contains(line, "AWS") && strings.Contains(line, "isAlive") { | ||
vpnAlive = true | ||
break | ||
} | ||
} | ||
|
||
if !vpnAlive { | ||
startCmd := exec.Command("open", "-a", "AWS VPN Client") | ||
if err := startCmd.Run(); err != nil { | ||
s.Stop() | ||
return fmt.Errorf("failed to start AWS VPN Client: %v", err) | ||
} | ||
|
||
s.Suffix = " Waiting for AWS VPN to start..." | ||
time.Sleep(5 * time.Second) | ||
} else { | ||
s.Stop() | ||
fmt.Println("\nAWS vpn is opened, so waiting an additional time till you login in your account") | ||
time.Sleep(10 * time.Second) | ||
break | ||
} | ||
} | ||
|
||
return nil | ||
} |