Skip to content

Commit

Permalink
Replace any with actual types or add types where they are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
unki2aut committed Nov 2, 2020
1 parent a93c8da commit 120935e
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 107 deletions.
22 changes: 12 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SSHConstants from './sshConstants';
import SSHUtils from './sshUtils';
import SFTP from './sftp';
import BaseSSH2Promise from './BaseSSH2Promise';
import { ClientChannel } from 'ssh2';

function isRegistered(sshConnection: SSHConnection, sshTunnel: SSH2Promise) {
return sshTunnel.deregister.filter((i) => {
Expand Down Expand Up @@ -61,10 +62,10 @@ function register(sshConnection: SSHConnection, sshTunnel: SSH2Promise, isLast:
events.forEach((event, idx) => {
sshConnection.removeListener(event, cbs[idx]);
});
Promise.resolve();
return Promise.resolve();
} else {
if(sshConnection.config.sock){
sshConnection.config.sock.kill();
if(sshConnection.config.sock) {
SSHUtils.endSocket(sshConnection.config.sock);
}
return sshConnection.close().then(() => {
events.forEach((event, idx) => {
Expand Down Expand Up @@ -116,7 +117,7 @@ class SSH2Promise extends BaseSSH2Promise {
var k = typeof m == "string"?m:Object.keys(m)[0];
(this as any)[k] = function () {
var params = arguments;
return this.connect().then((sshConnection: SSHConnection) => {
return this.connect().then((sshConnection: any) => {
return sshConnection[typeof m == "string"?m:m[k]].apply(sshConnection, params);
});
}.bind(this);
Expand All @@ -140,9 +141,10 @@ class SSH2Promise extends BaseSSH2Promise {

/**
* Get SSH if existing from cache otherwise create new one
* @param {*} sshConfig
* @param {*} sshConfig
* @param {*} isLast
*/
getSSHConnection(sshConfig: any, isLast: boolean) {
getSSHConnection(sshConfig: any, isLast: boolean): Promise<SSHConnection> {
var ret;
if (this.disableCache) {
ret = new SSHConnection(sshConfig);
Expand All @@ -163,18 +165,18 @@ class SSH2Promise extends BaseSSH2Promise {

/**
* Connect SSH connection, via single or multiple hopping connection
* @param {*} Single/Array of sshConfigs
* @param {*} Single/Array of sshConfigs
*/
connect() {
connect(): Promise<SSHConnection> {
var lastSSH;
for (var i = 0; i < this.config.length; i++) {
((sshConfig, isLast) => {
if (!lastSSH) {
lastSSH = this.getSSHConnection(sshConfig, isLast);
} else {
lastSSH = lastSSH.then((ssh: SSHConnection) => {
lastSSH = lastSSH.then((ssh) => {
return ssh.spawn(`nc ${sshConfig.host} ${sshConfig.port}`);
}).then((stream: any) => {
}).then((stream: ClientChannel) => {
sshConfig.sock = stream;
return this.getSSHConnection(sshConfig, isLast);
});
Expand Down
Loading

0 comments on commit 120935e

Please sign in to comment.