Skip to content

Commit f24ed37

Browse files
committed
- add prettier
- add ability to pass private key contents as well as file path - add password as an option - add passphrase as an option for protected private keys
1 parent 1f60b5a commit f24ed37

File tree

2 files changed

+52
-24
lines changed

2 files changed

+52
-24
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: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,47 @@
11
'use strict';
22

3-
var RSVP = require('rsvp');
4-
var fs = require('fs');
5-
var { createTunnel } = 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-
17-
createDeployPlugin: function(options) {
18-
var DeployPlugin = DeployPluginBase.extend({
16+
createDeployPlugin: function (options) {
17+
const DeployPlugin = DeployPluginBase.extend({
1918
name: options.name,
2019
defaultConfig: {
21-
dstPort: 6379,
22-
port: 22,
23-
dstHost: 'localhost',
24-
srcPort: function() {
25-
var range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1;
26-
return Math.floor(Math.random() * range) + MIN_PORT_NUMBER;
27-
},
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+
}
2827
},
2928

3029
requiredConfig: ['host', 'username'],
3130

32-
setup: function(/* context */) {
33-
var srcPort = this.readConfig('srcPort');
31+
setup: function (/* context */) {
32+
const srcPort = this.readConfig('srcPort');
3433

3534
if (srcPort > MAX_PORT_NUMBER || srcPort < MIN_PORT_NUMBER) {
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 + '.';
35+
throw (
36+
'Port ' +
37+
srcPort +
38+
' is not available to open a SSH connection on.\n' +
39+
'Please choose a port between ' +
40+
MIN_PORT_NUMBER +
41+
' and ' +
42+
MAX_PORT_NUMBER +
43+
'.'
44+
);
3745
}
3846

3947
const tunnelOptions = {
@@ -44,11 +52,19 @@ module.exports = {
4452
port: srcPort
4553
};
4654

55+
let privateKey = this.readConfig('privateKey');
56+
57+
if (this.readConfig('privateKeyPath')) {
58+
privateKey = fs.readFileSync(untildify(this.readConfig('privateKeyPath')));
59+
}
60+
4761
const sshOptions = {
4862
host: this.readConfig('host'),
4963
port: this.readConfig('port'),
5064
username: this.readConfig('username'),
51-
privateKey: fs.readFileSync(untildify(this.readConfig('privateKeyPath')))
65+
password: this.readConfig('password'),
66+
privateKey,
67+
passphrase: this.readConfig('passphrase')
5268
};
5369

5470
const forwardOptions = {
@@ -58,9 +74,9 @@ module.exports = {
5874
dstPort: this.readConfig('dstPort')
5975
};
6076

61-
return new RSVP.Promise(function(resolve, reject) {
77+
return new RSVP.Promise(function (resolve, reject) {
6278
createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions)
63-
.then(([server, conn]) => {
79+
.then(([server]) => {
6480
resolve({
6581
tunnel: {
6682
handler: server,
@@ -74,7 +90,7 @@ module.exports = {
7490
});
7591
},
7692

77-
teardown: function(context) {
93+
teardown: function (context) {
7894
context.tunnel.handler.close();
7995
}
8096
});

0 commit comments

Comments
 (0)