Skip to content

Commit 28236a2

Browse files
authored
- add support for custom tunnel client
1 parent f24ed37 commit 28236a2

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

index.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ module.exports = {
2323
srcPort: function () {
2424
var range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1;
2525
return Math.floor(Math.random() * range) + MIN_PORT_NUMBER;
26+
},
27+
tunnelClient: function (context) {
28+
// if you want to provide your own ssh client to be used instead of one from this plugin,
29+
// must follow this signature
30+
// createTunnel(
31+
// tunnelOptions: TunnelOptions,
32+
// serverOptions: ServerOptions,
33+
// sshOptions: SshOptions,
34+
// forwardOptions: ForwardOptions
35+
// ): Promise<[Server, Client]>;
36+
return context.tunnelClient || createTunnel;
2637
}
2738
},
2839

@@ -44,6 +55,14 @@ module.exports = {
4455
);
4556
}
4657

58+
const tunnel = this.readConfig('tunnelClient');
59+
60+
let privateKey = this.readConfig('privateKey');
61+
62+
if (this.readConfig('privateKeyPath')) {
63+
privateKey = fs.readFileSync(untildify(this.readConfig('privateKeyPath')));
64+
}
65+
4766
const tunnelOptions = {
4867
autoClose: true
4968
};
@@ -52,12 +71,6 @@ module.exports = {
5271
port: srcPort
5372
};
5473

55-
let privateKey = this.readConfig('privateKey');
56-
57-
if (this.readConfig('privateKeyPath')) {
58-
privateKey = fs.readFileSync(untildify(this.readConfig('privateKeyPath')));
59-
}
60-
6174
const sshOptions = {
6275
host: this.readConfig('host'),
6376
port: this.readConfig('port'),
@@ -75,7 +88,7 @@ module.exports = {
7588
};
7689

7790
return new RSVP.Promise(function (resolve, reject) {
78-
createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions)
91+
tunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions)
7992
.then(([server]) => {
8093
resolve({
8194
tunnel: {

0 commit comments

Comments
 (0)