Skip to content

Commit

Permalink
Merge pull request #10 from appveen/dev
Browse files Browse the repository at this point in the history
fixed a few crashing issues
  • Loading branch information
jerrymannel authored Jan 4, 2022
2 parents a69e495 + 76d1cdc commit 43115b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
27 changes: 17 additions & 10 deletions aws_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ func (e *EC2) Init(sess *session.Session, reload bool, quickConnect int) {
server = servers[quickConnect-1]
}

cmd := exec.Command("ssh", "-i", "./av.pem", server.User+"@"+server.PublicIPAddress)
fmt.Println(cmd)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
err := cmd.Run()
Check(err)
if server.State == "stopped" || server.State == "terminated" || server.PublicIPAddress == "-" {
fmt.Printf("Cannot connect to %s(%s) (IP:%s) \n", color.YellowString(server.Name), server.State, server.PublicIPAddress)
} else {
cmd := exec.Command("ssh", "-i", "./av.pem", server.User+"@"+server.PublicIPAddress)
fmt.Println(cmd)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
err := cmd.Run()
Check(err)
}
}

func sortServers(servers []Server) []Server {
Expand Down Expand Up @@ -110,7 +114,7 @@ func setColor(status string, s string) string {
return color.RedString(s)
}
if status == "terminated" {
return color.WhiteString(s)
return color.YellowString(s)
}
return s
}
Expand Down Expand Up @@ -185,7 +189,10 @@ func fetchEC2Instances(sess *session.Session) {
server.State = *instance.State.Name
server.InstanceType = *instance.InstanceType
server.LaunchTime = *instance.LaunchTime
server.PrivateIPAddress = *instance.PrivateIpAddress
server.PrivateIPAddress = "-"
if instance.PrivateIpAddress != nil {
server.PrivateIPAddress = *instance.PrivateIpAddress
}
server.PublicIPAddress = "-"
server.InstanceID = *instance.InstanceId
if instance.PublicIpAddress != nil {
Expand All @@ -209,7 +216,7 @@ func fetchEC2Instances(sess *session.Session) {
homeDir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
serversJSON := path.Join(homeDir, "servers.json")

file, err := os.Create(serversJSON)
file, _ := os.Create(serversJSON)
defer file.Close()
file.WriteString(string(s))
file.Sync()
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/avconnect-linux-amd
echo "env GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o bin/avconnect-mac ."
env GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o bin/avconnect-mac .

cd bin
cd bin || exit

md5sum avconnect-linux-386 > md5sum.txt
md5sum avconnect-linux-amd64 >> md5sum.txt
Expand Down
2 changes: 1 addition & 1 deletion lib_credentialHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (ch *CredentialHandler) getCredentials() {
homeDir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
credentialsFile := path.Join(homeDir, "credentials")

file, err := os.Create(credentialsFile)
file, _ := os.Create(credentialsFile)
defer file.Close()
file.WriteString("[default]\n")
file.WriteString("aws_access_key_id = " + answers.AccessKey + "\n")
Expand Down

0 comments on commit 43115b7

Please sign in to comment.