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:
agobrech
2022-09-01 14:29:15 +02:00
committed by GitHub
parent b5511e5ac7
commit d82e87979d
8 changed files with 438 additions and 3 deletions

View File

@@ -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 {