2023-04-12 07:24:17 -07:00
|
|
|
import type {
|
|
|
|
ICredentialDataDecryptedObject,
|
|
|
|
ICredentialsDecrypted,
|
|
|
|
ICredentialTestFunctions,
|
|
|
|
INodeCredentialTestResult,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import { Client } from 'ssh2';
|
2023-10-27 05:15:02 -07:00
|
|
|
import { createPool } from '../transport';
|
2023-04-12 07:24:17 -07:00
|
|
|
|
|
|
|
export async function mysqlConnectionTest(
|
|
|
|
this: ICredentialTestFunctions,
|
|
|
|
credential: ICredentialsDecrypted,
|
|
|
|
): Promise<INodeCredentialTestResult> {
|
|
|
|
const credentials = credential.data as ICredentialDataDecryptedObject;
|
|
|
|
|
|
|
|
let sshClient: Client | undefined = undefined;
|
|
|
|
|
|
|
|
if (credentials.sshTunnel) {
|
|
|
|
sshClient = new Client();
|
|
|
|
}
|
|
|
|
const pool = await createPool(credentials, {}, sshClient);
|
|
|
|
|
|
|
|
try {
|
|
|
|
const connection = await pool.getConnection();
|
|
|
|
connection.release();
|
|
|
|
} catch (error) {
|
|
|
|
return {
|
|
|
|
status: 'Error',
|
|
|
|
message: error.message,
|
|
|
|
};
|
|
|
|
} finally {
|
|
|
|
if (sshClient) {
|
|
|
|
sshClient.end();
|
|
|
|
}
|
|
|
|
await pool.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
status: 'OK',
|
|
|
|
message: 'Connection successful!',
|
|
|
|
};
|
|
|
|
}
|