refactor(core): Centralize SSH Tunnel management (#9906)

Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-07-04 12:29:44 +02:00
committed by GitHub
parent 86018aa6e0
commit 85aa560a5d
25 changed files with 525 additions and 630 deletions

View File

@@ -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();
}