mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08:00
62c096710f
- Fix autofixable violations - Remove unused directives - Allow for PascalCased variables - needed for dynamically imported or assigned classes, decorators, routers, etc.
44 lines
932 B
TypeScript
44 lines
932 B
TypeScript
import type {
|
|
ICredentialDataDecryptedObject,
|
|
ICredentialsDecrypted,
|
|
ICredentialTestFunctions,
|
|
INodeCredentialTestResult,
|
|
} from 'n8n-workflow';
|
|
|
|
import { Client } from 'ssh2';
|
|
import { createPool } from '../transport';
|
|
|
|
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!',
|
|
};
|
|
}
|