-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
49 lines (40 loc) · 978 Bytes
/
main.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
package main
import (
"fmt"
"os"
"github.com/apex/log"
"github.com/z0mbix/essh/internal/aws"
"github.com/z0mbix/essh/internal/config"
"github.com/z0mbix/essh/internal/menu"
"github.com/z0mbix/essh/internal/ssh"
)
var (
version = "dev"
)
func main() {
if config.ShowVersion {
fmt.Println(version)
os.Exit(0)
}
sess, err := aws.NewSession(config.Region)
if err != nil {
log.Fatalf("could not get instance/session: %s", err)
}
instance, err := menu.GetInstance(sess)
if err != nil {
log.Fatalf("%s", err)
}
log.Debugf("host: %s", instance.ConnectIP)
comment := fmt.Sprintf("%s:%s", config.UserName, instance.ID)
essh, err := ssh.NewSession(comment, config.PrivateKeyLifetime)
if err != nil {
log.Fatalf("%s", err)
}
sshArgs := []string{"-l", config.UserName}
sshArgs = append(sshArgs, instance.ConnectIP)
sshArgs = append(sshArgs, config.ExtraArgs...)
err = essh.Connect(instance, sshArgs)
if err != nil {
log.Fatal(err.Error())
}
}