feat: Add new credentials for the HTTP Request node (#9833)

Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com>
This commit is contained in:
Bram Kn
2024-08-23 19:19:05 +02:00
committed by GitHub
parent 6422fb33c0
commit 26f1af397b
16 changed files with 828 additions and 76 deletions

View File

@@ -1,15 +1,11 @@
import type {
IExecuteFunctions,
ICredentialsDecrypted,
ICredentialTestFunctions,
IDataObject,
ILoadOptionsFunctions,
INodeCredentialTestResult,
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
IRequestOptions,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
@@ -19,7 +15,6 @@ import {
getVersion,
handleListing,
throwOnEmptyUpdate,
tolerateTrailingSlash,
} from './GenericFunctions';
import {
@@ -33,12 +28,7 @@ import {
connectorOperations,
} from './descriptions';
import type {
Connector,
ConnectorCreatePayload,
ConnectorType,
ElasticSecurityApiCredentials,
} from './types';
import type { Connector, ConnectorCreatePayload, ConnectorType } from './types';
export class ElasticSecurity implements INodeType {
description: INodeTypeDescription = {
@@ -58,7 +48,6 @@ export class ElasticSecurity implements INodeType {
{
name: 'elasticSecurityApi',
required: true,
testedBy: 'elasticSecurityApiTest',
},
],
properties: [
@@ -115,49 +104,6 @@ export class ElasticSecurity implements INodeType {
return connectors.map(({ name, id }) => ({ name, value: id }));
},
},
credentialTest: {
async elasticSecurityApiTest(
this: ICredentialTestFunctions,
credential: ICredentialsDecrypted,
): Promise<INodeCredentialTestResult> {
const {
username,
password,
baseUrl: rawBaseUrl,
} = credential.data as ElasticSecurityApiCredentials;
const baseUrl = tolerateTrailingSlash(rawBaseUrl);
const token = Buffer.from(`${username}:${password}`).toString('base64');
const endpoint = '/cases/status';
const options: IRequestOptions = {
headers: {
Authorization: `Basic ${token}`,
'kbn-xsrf': true,
},
method: 'GET',
body: {},
qs: {},
uri: `${baseUrl}/api${endpoint}`,
json: true,
};
try {
await this.helpers.request(options);
return {
status: 'OK',
message: 'Authentication successful',
};
} catch (error) {
return {
status: 'Error',
message: error.message,
};
}
},
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {