1
1
'use strict' ;
2
2
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' ) ;
7
7
8
- var DeployPluginBase = require ( 'ember-cli-deploy-plugin' ) ;
8
+ const DeployPluginBase = require ( 'ember-cli-deploy-plugin' ) ;
9
9
10
- var MAX_PORT_NUMBER = 65535 ;
11
- var MIN_PORT_NUMBER = 49151 ;
10
+ const MAX_PORT_NUMBER = 65535 ;
11
+ const MIN_PORT_NUMBER = 49151 ;
12
12
13
13
module . exports = {
14
14
name : 'ember-cli-deploy-ssh-tunnel' ,
15
15
16
-
17
- createDeployPlugin : function ( options ) {
18
- var DeployPlugin = DeployPluginBase . extend ( {
16
+ createDeployPlugin : function ( options ) {
17
+ const DeployPlugin = DeployPluginBase . extend ( {
19
18
name : options . name ,
20
19
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
+ }
28
27
} ,
29
28
30
29
requiredConfig : [ 'host' , 'username' ] ,
31
30
32
- setup : function ( /* context */ ) {
33
- var srcPort = this . readConfig ( 'srcPort' ) ;
31
+ setup : function ( /* context */ ) {
32
+ const srcPort = this . readConfig ( 'srcPort' ) ;
34
33
35
34
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
+ ) ;
37
45
}
38
46
39
47
const tunnelOptions = {
@@ -44,11 +52,19 @@ module.exports = {
44
52
port : srcPort
45
53
} ;
46
54
55
+ let privateKey = this . readConfig ( 'privateKey' ) ;
56
+
57
+ if ( this . readConfig ( 'privateKeyPath' ) ) {
58
+ privateKey = fs . readFileSync ( untildify ( this . readConfig ( 'privateKeyPath' ) ) ) ;
59
+ }
60
+
47
61
const sshOptions = {
48
62
host : this . readConfig ( 'host' ) ,
49
63
port : this . readConfig ( 'port' ) ,
50
64
username : this . readConfig ( 'username' ) ,
51
- privateKey : fs . readFileSync ( untildify ( this . readConfig ( 'privateKeyPath' ) ) )
65
+ password : this . readConfig ( 'password' ) ,
66
+ privateKey,
67
+ passphrase : this . readConfig ( 'passphrase' )
52
68
} ;
53
69
54
70
const forwardOptions = {
@@ -58,9 +74,9 @@ module.exports = {
58
74
dstPort : this . readConfig ( 'dstPort' )
59
75
} ;
60
76
61
- return new RSVP . Promise ( function ( resolve , reject ) {
77
+ return new RSVP . Promise ( function ( resolve , reject ) {
62
78
createTunnel ( tunnelOptions , serverOptions , sshOptions , forwardOptions )
63
- . then ( ( [ server , conn ] ) => {
79
+ . then ( ( [ server ] ) => {
64
80
resolve ( {
65
81
tunnel : {
66
82
handler : server ,
@@ -74,7 +90,7 @@ module.exports = {
74
90
} ) ;
75
91
} ,
76
92
77
- teardown : function ( context ) {
93
+ teardown : function ( context ) {
78
94
context . tunnel . handler . close ( ) ;
79
95
}
80
96
} ) ;
0 commit comments