Skip to content

Commit cd39311

Browse files
authored
Merge pull request #11 from evoactivity/update-tunnel-ssh
Update tunnel-ssh client and add options
2 parents 56da1e7 + 8f65f5a commit cd39311

File tree

4 files changed

+165
-110
lines changed

4 files changed

+165
-110
lines changed

.prettierrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
module.exports = {
4+
semi: true,
5+
singleQuote: true,
6+
useTabs: false,
7+
quoteProps: 'consistent',
8+
bracketSpacing: true,
9+
arrowParens: 'always',
10+
printWidth: 120,
11+
trailingComma: 'none'
12+
};

index.js

Lines changed: 75 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,110 @@
11
'use strict';
22

3-
var RSVP = require('rsvp');
4-
var fs = require('fs');
5-
var tunnelSsh = require('tunnel-ssh');
6-
var untildify = require('untildify');
3+
const RSVP = require('rsvp');
4+
const fs = require('fs');
5+
const { createTunnel } = require('tunnel-ssh');
6+
const untildify = require('untildify');
77

8-
var DeployPluginBase = require('ember-cli-deploy-plugin');
8+
const DeployPluginBase = require('ember-cli-deploy-plugin');
99

10-
var MAX_PORT_NUMBER = 65535;
11-
var MIN_PORT_NUMBER = 49151;
10+
const MAX_PORT_NUMBER = 65535;
11+
const MIN_PORT_NUMBER = 49151;
1212

1313
module.exports = {
1414
name: 'ember-cli-deploy-ssh-tunnel',
1515

16-
createDeployPlugin: function(options) {
17-
var DeployPlugin = DeployPluginBase.extend({
16+
createDeployPlugin: function (options) {
17+
const DeployPlugin = DeployPluginBase.extend({
1818
name: options.name,
1919
defaultConfig: {
20-
dstPort: 6379,
21-
port: 22,
22-
dstHost: 'localhost',
23-
srcPort: function() {
24-
var range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1;
25-
return Math.floor(Math.random() * range) + MIN_PORT_NUMBER;
26-
},
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-
}
20+
dstPort: 6379,
21+
port: 22,
22+
dstHost: 'localhost',
23+
srcPort: function () {
24+
var range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1;
25+
return Math.floor(Math.random() * range) + MIN_PORT_NUMBER;
26+
},
27+
tunnelClient: function (context) {
28+
// if you want to provide your own ssh client to be used instead of one from this plugin,
29+
// must follow this signature
30+
// createTunnel(
31+
// tunnelOptions: TunnelOptions,
32+
// serverOptions: ServerOptions,
33+
// sshOptions: SshOptions,
34+
// forwardOptions: ForwardOptions
35+
// ): Promise<[Server, Client]>;
36+
// https://github.com/agebrock/tunnel-ssh/blob/master/types/index.d.ts
37+
return context.tunnelClient || createTunnel;
38+
}
3139
},
3240

3341
requiredConfig: ['host', 'username'],
3442

35-
setup: function(/* context */) {
36-
var srcPort = this.readConfig('srcPort');
43+
setup: function (/* context */) {
44+
const srcPort = this.readConfig('srcPort');
3745

3846
if (srcPort > MAX_PORT_NUMBER || srcPort < MIN_PORT_NUMBER) {
39-
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 + '.';
47+
throw (
48+
'Port ' +
49+
srcPort +
50+
' is not available to open a SSH connection on.\n' +
51+
'Please choose a port between ' +
52+
MIN_PORT_NUMBER +
53+
' and ' +
54+
MAX_PORT_NUMBER +
55+
'.'
56+
);
4057
}
4158

42-
var sshConfig = {
59+
const tunnel = this.readConfig('tunnelClient');
60+
61+
let privateKey = this.readConfig('privateKey');
62+
63+
if (this.readConfig('privateKeyPath')) {
64+
privateKey = fs.readFileSync(untildify(this.readConfig('privateKeyPath')));
65+
}
66+
67+
const tunnelOptions = {
68+
autoClose: true
69+
};
70+
71+
const serverOptions = {
72+
port: srcPort
73+
};
74+
75+
const sshOptions = {
4376
host: this.readConfig('host'),
4477
port: this.readConfig('port'),
45-
dstPort: this.readConfig('dstPort'),
46-
dstHost: this.readConfig('dstHost'),
4778
username: this.readConfig('username'),
48-
localPort: srcPort
79+
password: this.readConfig('password'),
80+
privateKey,
81+
passphrase: this.readConfig('passphrase')
4982
};
5083

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-
}
84+
const forwardOptions = {
85+
srcAddr: 'localhost',
86+
srcPort: this.readConfig('srcPort'),
87+
dstAddr: this.readConfig('dstHost'),
88+
dstPort: this.readConfig('dstPort')
89+
};
6090

61-
return new RSVP.Promise(function(resolve, reject) {
62-
var sshTunnel = tunnel(sshConfig, function(error /*, result */) {
63-
if (error) {
64-
reject(error);
65-
} else {
91+
return new RSVP.Promise(function (resolve, reject) {
92+
tunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions)
93+
.then(([server]) => {
6694
resolve({
6795
tunnel: {
68-
handler: sshTunnel,
96+
handler: server,
6997
srcPort: srcPort
7098
}
7199
});
72-
}
73-
});
100+
})
101+
.catch((error) => {
102+
reject(error);
103+
});
74104
});
75105
},
76106

77-
teardown: function(context) {
107+
teardown: function (context) {
78108
context.tunnel.handler.close();
79109
}
80110
});

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)