mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feature: add database and non http credentials test
Add credential testing to Postgres, MySQL, MicrosoftSQL, Redis, FTP, SFTP, IMAP, RabbitMQ and MQTT Co-authored-by: Omar Ajoue <krynble@gmail.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
ICredentialDataDecryptedObject,
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
INodeCredentialTestResult,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
@@ -10,6 +13,7 @@ import {
|
||||
import mysql2 from 'mysql2/promise';
|
||||
|
||||
import { copyInputItems } from './GenericFunctions';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
export class MySql implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -28,6 +32,7 @@ export class MySql implements INodeType {
|
||||
{
|
||||
name: 'mySql',
|
||||
required: true,
|
||||
testedBy: 'mysqlConnectionTest',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
@@ -204,6 +209,46 @@ export class MySql implements INodeType {
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
credentialTest: {
|
||||
async mysqlConnectionTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
const credentials = credential.data as ICredentialDataDecryptedObject;
|
||||
try {
|
||||
const { ssl, caCertificate, clientCertificate, clientPrivateKey, ...baseCredentials } =
|
||||
credentials;
|
||||
|
||||
if (ssl) {
|
||||
baseCredentials.ssl = {};
|
||||
|
||||
if (caCertificate) {
|
||||
baseCredentials.ssl.ca = caCertificate;
|
||||
}
|
||||
|
||||
if (clientCertificate || clientPrivateKey) {
|
||||
baseCredentials.ssl.cert = clientCertificate;
|
||||
baseCredentials.ssl.key = clientPrivateKey;
|
||||
}
|
||||
}
|
||||
|
||||
const connection = await mysql2.createConnection(baseCredentials);
|
||||
connection.end();
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: error.message,
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Connection successful!',
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const credentials = await this.getCredentials('mySql');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user