Skip to content

Commit 1f60b5a

Browse files
committed
update tunnel ssh
1 parent 56da1e7 commit 1f60b5a

File tree

3 files changed

+103
-90
lines changed

3 files changed

+103
-90
lines changed

index.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var RSVP = require('rsvp');
44
var fs = require('fs');
5-
var tunnelSsh = require('tunnel-ssh');
5+
var { createTunnel } = require('tunnel-ssh');
66
var untildify = require('untildify');
77

88
var DeployPluginBase = require('ember-cli-deploy-plugin');
@@ -13,6 +13,7 @@ var MIN_PORT_NUMBER = 49151;
1313
module.exports = {
1414
name: 'ember-cli-deploy-ssh-tunnel',
1515

16+
1617
createDeployPlugin: function(options) {
1718
var DeployPlugin = DeployPluginBase.extend({
1819
name: options.name,
@@ -24,10 +25,6 @@ module.exports = {
2425
var range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1;
2526
return Math.floor(Math.random() * range) + MIN_PORT_NUMBER;
2627
},
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-
}
3128
},
3229

3330
requiredConfig: ['host', 'username'],
@@ -39,38 +36,41 @@ module.exports = {
3936
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 + '.';
4037
}
4138

42-
var sshConfig = {
39+
const tunnelOptions = {
40+
autoClose: true
41+
};
42+
43+
const serverOptions = {
44+
port: srcPort
45+
};
46+
47+
const sshOptions = {
4348
host: this.readConfig('host'),
4449
port: this.readConfig('port'),
45-
dstPort: this.readConfig('dstPort'),
46-
dstHost: this.readConfig('dstHost'),
4750
username: this.readConfig('username'),
48-
localPort: srcPort
51+
privateKey: fs.readFileSync(untildify(this.readConfig('privateKeyPath')))
4952
};
5053

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+
};
6060

6161
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]) => {
6664
resolve({
6765
tunnel: {
68-
handler: sshTunnel,
66+
handler: server,
6967
srcPort: srcPort
7068
}
7169
});
72-
}
73-
});
70+
})
71+
.catch((error) => {
72+
reject(error);
73+
});
7474
});
7575
},
7676

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
],
3131
"dependencies": {
3232
"ember-cli-deploy-plugin": "^0.2.6",
33-
"tunnel-ssh": "^1.0.1",
33+
"tunnel-ssh": "^5.0.5",
3434
"untildify": "^2.0.0"
3535
}
3636
}

0 commit comments

Comments
 (0)