Skip to content

Commit

Permalink
feat(plugin): add hook for tunnel
Browse files Browse the repository at this point in the history
This will enable us to remove tunnel-ssh from the
core and allow developers to even place different
tunnel methods, i.e. proxies or vpns to be put in
place.

Signed-off-by: Tobias Gurtzick <magic@wizardtales.com>
  • Loading branch information
wzrdtales committed Apr 16, 2020
1 parent 2a2c964 commit 6e9e282
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/driver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var ShadowProto = {

exports.connect = function (config, intern, callback) {
var driver, req;
let plugin = false;
const { plugins } = intern;

var mod = internals.mod;
internals = intern;
Expand Down Expand Up @@ -108,9 +110,27 @@ exports.connect = function (config, intern, callback) {
if (config.tunnel) {
var tunnel = require('tunnel-ssh');
var tunnelConfig = JSON.parse(JSON.stringify(config.tunnel));
const { tunnelType } = tunnelConfig;

if (plugins) {
plugin = plugins.overwrite(
`connection:tunnel:${
tunnelType && tunnelType !== 'ssh' ? tunnelType : 'ssh'
}`
);
}

tunnelConfig.dstHost = config.host;
tunnelConfig.dstPort = config.port;

if (plugin) {
tunnel = plugin[
`connection:tunnel:${
tunnelType && tunnelType !== 'ssh' ? tunnelType : 'ssh'
}`
](tunnelConfig);
}

if (tunnelConfig.privateKeyPath) {
tunnelConfig.privateKey = require('fs').readFileSync(
tunnelConfig.privateKeyPath
Expand Down

0 comments on commit 6e9e282

Please sign in to comment.