@@ -2,9 +2,9 @@ package main
2
2
3
3
import (
4
4
"encoding/binary"
5
- "github.com/docker/docker/pkg/term"
6
5
"golang.org/x/crypto/ssh"
7
6
"golang.org/x/crypto/ssh/agent"
7
+ "golang.org/x/crypto/ssh/terminal"
8
8
9
9
"fmt"
10
10
"io/ioutil"
@@ -14,21 +14,21 @@ import (
14
14
"syscall"
15
15
)
16
16
17
- func startSSH () error {
17
+ func startSSH (ipAddr , keyName string ) error {
18
18
width := 80
19
19
height := 24
20
20
sshConfig := & ssh.ClientConfig {
21
21
User : "ec2-user" ,
22
22
Auth : []ssh.AuthMethod {
23
23
SSHAgent (),
24
- PublicKeyFile ("/keys/" + * e . keyName ),
24
+ PublicKeyFile ("/keys/" + keyName ),
25
25
},
26
26
HostKeyCallback : func (hostname string , remote net.Addr , key ssh.PublicKey ) error {
27
27
return nil
28
28
},
29
29
}
30
- fmt .Printf ("Opening connection to %v:22 with key %v" , * e . ipAddr , "/keys/" + * e . keyName )
31
- connection , err := ssh .Dial ("tcp" , * e . ipAddr + ":22" , sshConfig )
30
+ fmt .Printf ("Opening connection to %v:22 with SSHAgent or key %v" , ipAddr , "/keys/" + keyName )
31
+ connection , err := ssh .Dial ("tcp" , ipAddr + ":22" , sshConfig )
32
32
if err != nil {
33
33
return fmt .Errorf ("Failed to dial: %s" , err )
34
34
}
@@ -46,24 +46,24 @@ func startSSH() error {
46
46
ssh .ECHO : 1 ,
47
47
}
48
48
49
- fd := os .Stdin .Fd ()
49
+ fd := int ( os .Stdin .Fd () )
50
50
51
- if term .IsTerminal (fd ) {
52
- oldState , err := term .MakeRaw (fd )
51
+ if terminal .IsTerminal (fd ) {
52
+ oldState , err := terminal .MakeRaw (fd )
53
53
if err != nil {
54
54
return err
55
55
}
56
56
57
- defer term . RestoreTerminal (fd , oldState )
57
+ defer terminal . Restore (fd , oldState )
58
58
59
- winsize , err := term . GetWinsize (fd )
59
+ tmpWidth , tmpHeight , err := terminal . GetSize (fd )
60
60
if err == nil {
61
- width = int ( winsize . Width )
62
- height = int ( winsize . Height )
61
+ width = tmpWidth
62
+ height = tmpHeight
63
63
}
64
64
}
65
65
66
- if err := session .RequestPty ("xterm" , width , height , modes ); err != nil {
66
+ if err := session .RequestPty ("xterm" , height , width , modes ); err != nil {
67
67
session .Close ()
68
68
return fmt .Errorf ("request for pseudo terminal failed: %s" , err )
69
69
}
@@ -114,15 +114,15 @@ func monitorChanges(session *ssh.Session, fd uintptr) {
114
114
func termSize (fd uintptr ) []byte {
115
115
size := make ([]byte , 16 )
116
116
117
- winsize , err := term . GetWinsize ( fd )
117
+ width , height , err := terminal . GetSize ( int ( fd ) )
118
118
if err != nil {
119
119
binary .BigEndian .PutUint32 (size , uint32 (80 ))
120
120
binary .BigEndian .PutUint32 (size [4 :], uint32 (24 ))
121
121
return size
122
122
}
123
123
124
- binary .BigEndian .PutUint32 (size , uint32 (winsize . Width ))
125
- binary .BigEndian .PutUint32 (size [4 :], uint32 (winsize . Height ))
124
+ binary .BigEndian .PutUint32 (size , uint32 (width ))
125
+ binary .BigEndian .PutUint32 (size [4 :], uint32 (height ))
126
126
127
127
return size
128
128
}
0 commit comments