-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (64 loc) · 2.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* jshint node: true */
'use strict';
const Promise = require('ember-cli/lib/ext/promise');
const DeployPluginBase = require('ember-cli-deploy-plugin');
const MAX_PORT_NUMBER = 65535;
const MIN_PORT_NUMBER = 49151;
module.exports = {
name: 'ember-cli-deploy-elasticache',
createDeployPlugin: function(options) {
const Tunnel = require('./lib/elasticache-tunnel');
const DeployPlugin = DeployPluginBase.extend({
name: options.name,
defaultConfig: {
elasticachePort: 6379,
srcPort: function() {
const range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1;
return Math.floor(Math.random() * range) + MIN_PORT_NUMBER;
}
},
requiredConfig: ['ec2Host','ec2User','ec2KeyFile','elasticacheHost'],
setup: function(/* context */) {
const srcPort = this.readConfig('srcPort');
if (srcPort > MAX_PORT_NUMBER || srcPort < MIN_PORT_NUMBER) {
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 + '.';
}
const config = {
srcPort: srcPort,
ec2User: this.readConfig('ec2User'),
ec2Host: this.readConfig('ec2Host'),
ec2KeyFile: this.readConfig('ec2KeyFile'),
elasticachePort: this.readConfig('elasticachePort'),
elasticacheHost: this.readConfig('elasticacheHost')
};
const tunnel = new Tunnel(config);
return new Promise((resolve, reject) => {
tunnel.open().then(() => {
this.log('Ssh Tunnel is running.', { verbose: true });
resolve({
tunnel: {
handler: tunnel,
srcPort: srcPort
}
});
}).catch((error) =>{
this.log(error, { color: 'red' });
reject(error);
});
});
},
teardown: function(context) {
return new Promise((resolve, reject) => {
context.tunnel.handler.close().then(() => {
this.log('Ssh Tunnel is closed.', { verbose: true });
resolve();
}).catch((error) => {
this.log(error, { color: 'red' });
reject(error);
});
});
}
});
return new DeployPlugin();
}
};