1 | var util = require('util');
|
2 | var defaults = require('lodash.defaults');
|
3 |
|
4 | var ConfigError = function ConfigError(message, extra) {
|
5 | Error.captureStackTrace(this, this.constructor);
|
6 | this.name = this.constructor.name;
|
7 | this.message = message;
|
8 | this.extra = extra;
|
9 | };
|
10 |
|
11 | util.inherits(ConfigError, Error);
|
12 |
|
13 | function createConfig(config) {
|
14 | var env = process.env;
|
15 |
|
16 | defaults(config || {}, {
|
17 | username: env.TUNNELSSH_USER || env.USER || env.USERNAME || 'root',
|
18 | port: 22,
|
19 | host: null,
|
20 | srcPort: 0,
|
21 | srcHost: '127.0.0.1',
|
22 | dstPort: null,
|
23 | dstHost: '127.0.0.1',
|
24 | localHost: '127.0.0.1',
|
25 | localPort: config.dstPort,
|
26 | agent: process.env.SSH_AUTH_SOCK
|
27 | });
|
28 |
|
29 | if (!config.host) {
|
30 | throw new ConfigError('host not set');
|
31 | }
|
32 |
|
33 | if (!config.dstPort) {
|
34 | throw new ConfigError('dstPort not set');
|
35 | }
|
36 |
|
37 | return config;
|
38 | }
|
39 |
|
40 | module.exports = createConfig;
|