2
2
3
3
var RSVP = require ( 'rsvp' ) ;
4
4
var fs = require ( 'fs' ) ;
5
- var tunnelSsh = require ( 'tunnel-ssh' ) ;
5
+ var { createTunnel } = require ( 'tunnel-ssh' ) ;
6
6
var untildify = require ( 'untildify' ) ;
7
7
8
8
var DeployPluginBase = require ( 'ember-cli-deploy-plugin' ) ;
@@ -13,6 +13,7 @@ var MIN_PORT_NUMBER = 49151;
13
13
module . exports = {
14
14
name : 'ember-cli-deploy-ssh-tunnel' ,
15
15
16
+
16
17
createDeployPlugin : function ( options ) {
17
18
var DeployPlugin = DeployPluginBase . extend ( {
18
19
name : options . name ,
@@ -24,10 +25,6 @@ module.exports = {
24
25
var range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1 ;
25
26
return Math . floor ( Math . random ( ) * range ) + MIN_PORT_NUMBER ;
26
27
} ,
27
- tunnelClient : function ( context ) {
28
- // if you want to provide your own ssh client to be used instead of one from this plugin
29
- return context . tunnelClient || tunnelSsh ;
30
- }
31
28
} ,
32
29
33
30
requiredConfig : [ 'host' , 'username' ] ,
@@ -39,38 +36,41 @@ module.exports = {
39
36
throw 'Port ' + srcPort + ' is not available to open a SSH connection on.\n' + 'Please choose a port between ' + MIN_PORT_NUMBER + ' and ' + MAX_PORT_NUMBER + '.' ;
40
37
}
41
38
42
- var sshConfig = {
39
+ const tunnelOptions = {
40
+ autoClose : true
41
+ } ;
42
+
43
+ const serverOptions = {
44
+ port : srcPort
45
+ } ;
46
+
47
+ const sshOptions = {
43
48
host : this . readConfig ( 'host' ) ,
44
49
port : this . readConfig ( 'port' ) ,
45
- dstPort : this . readConfig ( 'dstPort' ) ,
46
- dstHost : this . readConfig ( 'dstHost' ) ,
47
50
username : this . readConfig ( 'username' ) ,
48
- localPort : srcPort
51
+ privateKey : fs . readFileSync ( untildify ( this . readConfig ( 'privateKeyPath' ) ) )
49
52
} ;
50
53
51
- var password = this . readConfig ( 'password' ) ;
52
- var privateKey = this . readConfig ( 'privateKeyPath' ) ;
53
- var tunnel = this . readConfig ( 'tunnelClient' ) ;
54
-
55
- if ( password ) {
56
- sshConfig . password = password ;
57
- } else if ( privateKey ) {
58
- sshConfig . privateKey = fs . readFileSync ( untildify ( privateKey ) ) ;
59
- }
54
+ const forwardOptions = {
55
+ srcAddr : 'localhost' ,
56
+ srcPort : this . readConfig ( 'srcPort' ) ,
57
+ dstAddr : this . readConfig ( 'dstHost' ) ,
58
+ dstPort : this . readConfig ( 'dstPort' )
59
+ } ;
60
60
61
61
return new RSVP . Promise ( function ( resolve , reject ) {
62
- var sshTunnel = tunnel ( sshConfig , function ( error /*, result */ ) {
63
- if ( error ) {
64
- reject ( error ) ;
65
- } else {
62
+ createTunnel ( tunnelOptions , serverOptions , sshOptions , forwardOptions )
63
+ . then ( ( [ server , conn ] ) => {
66
64
resolve ( {
67
65
tunnel : {
68
- handler : sshTunnel ,
66
+ handler : server ,
69
67
srcPort : srcPort
70
68
}
71
69
} ) ;
72
- }
73
- } ) ;
70
+ } )
71
+ . catch ( ( error ) => {
72
+ reject ( error ) ;
73
+ } ) ;
74
74
} ) ;
75
75
} ,
76
76
0 commit comments