mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-17 10:04:08 -08:00
ca9a155c69
* ✨ Create Elastic Security node * 🔨 Place Elastic nodes in Elastic dir * ⚡ Improvements * 🔨 Split credentials * 🎨 Fix formatting * ⚡ Tolerate trailing slash * 👕 Fix lint * 👕 Fix lint * 🐛 Fix tags filter in case:getAll * 🔨 Refactor sort options in case:getAll * ✏️ Reword param descriptions * 🔥 Remove descriptions per feedback * 🐛 Fix case:getStatus operation * ✏️ Reword param and error message * ✏️ Reword param descriptions * 🔨 Account for empty string in owner * ✏️ Reword param description * ✏️ Add more tooltip descriptions * ⚡ Add cred test * ✏️ Add param description * ✏️ Add comment dividers * ⚡ Improve UX for third-party service params * 🔨 Minor tweaks per feedback * 🔨 Make getStatus naming consistent * ⚡ Fix operation Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Mutasem <mutdmour@gmail.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
59 lines
1 KiB
TypeScript
59 lines
1 KiB
TypeScript
import {
|
|
OptionsWithUri,
|
|
} from 'request';
|
|
|
|
import {
|
|
IExecuteFunctions,
|
|
} from 'n8n-core';
|
|
|
|
import {
|
|
IDataObject,
|
|
NodeApiError,
|
|
} from 'n8n-workflow';
|
|
|
|
import {
|
|
ElasticsearchApiCredentials,
|
|
} from './types';
|
|
|
|
export async function elasticsearchApiRequest(
|
|
this: IExecuteFunctions,
|
|
method: 'GET' | 'PUT' | 'POST' | 'DELETE',
|
|
endpoint: string,
|
|
body: IDataObject = {},
|
|
qs: IDataObject = {},
|
|
) {
|
|
const {
|
|
username,
|
|
password,
|
|
baseUrl,
|
|
} = await this.getCredentials('elasticsearchApi') as ElasticsearchApiCredentials;
|
|
|
|
const token = Buffer.from(`${username}:${password}`).toString('base64');
|
|
|
|
const options: OptionsWithUri = {
|
|
headers: {
|
|
Authorization: `Basic ${token}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
method,
|
|
body,
|
|
qs,
|
|
uri: `${baseUrl}${endpoint}`,
|
|
json: true,
|
|
};
|
|
|
|
if (!Object.keys(body).length) {
|
|
delete options.body;
|
|
}
|
|
|
|
if (!Object.keys(qs).length) {
|
|
delete options.qs;
|
|
}
|
|
|
|
try {
|
|
return await this.helpers.request(options);
|
|
} catch (error) {
|
|
throw new NodeApiError(this.getNode(), error);
|
|
}
|
|
}
|