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,7 +1,11 @@
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
GenericValue,
|
||||
ICredentialDataDecryptedObject,
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
INodeCredentialTestResult,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
@@ -30,6 +34,7 @@ export class Redis implements INodeType {
|
||||
{
|
||||
name: 'redis',
|
||||
required: true,
|
||||
testedBy: 'redisConnectionTest',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
@@ -489,6 +494,52 @@ export class Redis implements INodeType {
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
credentialTest: {
|
||||
async redisConnectionTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
const credentials = credential.data as ICredentialDataDecryptedObject;
|
||||
const redisOptions: redis.ClientOpts = {
|
||||
host: credentials.host as string,
|
||||
port: credentials.port as number,
|
||||
db: credentials.database as number,
|
||||
};
|
||||
|
||||
if (credentials.password) {
|
||||
redisOptions.password = credentials.password as string;
|
||||
}
|
||||
try {
|
||||
const client = await redis.createClient(redisOptions);
|
||||
// tslint:disable-next-line: no-any
|
||||
const data = await new Promise((resolve, reject): any => {
|
||||
client.on('connect', async () => {
|
||||
client.ping('ping', (error, pong) => {
|
||||
if (error) reject(error);
|
||||
resolve(pong);
|
||||
client.quit();
|
||||
});
|
||||
});
|
||||
client.on('error', async (err) => {
|
||||
client.quit();
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: error.message,
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Connection successful!',
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
// Parses the given value in a number if it is one else returns a string
|
||||
function getParsedValue(value: string): string | number {
|
||||
|
||||
Reference in New Issue
Block a user