refactor(core): Centralize SSH Tunnel management (#9906)
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
committed by
GitHub
parent
86018aa6e0
commit
85aa560a5d
@@ -1,25 +1,19 @@
|
||||
import type {
|
||||
ICredentialDataDecryptedObject,
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
INodeCredentialTestResult,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { Client } from 'ssh2';
|
||||
import { createPool } from '../transport';
|
||||
import type { MysqlNodeCredentials } from '../helpers/interfaces';
|
||||
|
||||
export async function mysqlConnectionTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
const credentials = credential.data as ICredentialDataDecryptedObject;
|
||||
const credentials = credential.data as MysqlNodeCredentials;
|
||||
|
||||
let sshClient: Client | undefined = undefined;
|
||||
|
||||
if (credentials.sshTunnel) {
|
||||
sshClient = new Client();
|
||||
}
|
||||
const pool = await createPool(credentials, {}, sshClient);
|
||||
const pool = await createPool.call(this, credentials);
|
||||
|
||||
try {
|
||||
const connection = await pool.getConnection();
|
||||
@@ -30,9 +24,6 @@ export async function mysqlConnectionTest(
|
||||
message: error.message,
|
||||
};
|
||||
} finally {
|
||||
if (sshClient) {
|
||||
sshClient.end();
|
||||
}
|
||||
await pool.end();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user