mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
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:
@@ -1,4 +1,10 @@
|
||||
import type { ICredentialType, INodeProperties } from 'n8n-workflow';
|
||||
import type {
|
||||
ICredentialDataDecryptedObject,
|
||||
ICredentialTestRequest,
|
||||
ICredentialType,
|
||||
IHttpRequestOptions,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class ElasticSecurityApi implements ICredentialType {
|
||||
name = 'elasticSecurityApi';
|
||||
@@ -8,12 +14,42 @@ export class ElasticSecurityApi implements ICredentialType {
|
||||
documentationUrl = 'elasticSecurity';
|
||||
|
||||
properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Base URL',
|
||||
name: 'baseUrl',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. https://mydeployment.kb.us-central1.gcp.cloud.es.io:9243',
|
||||
description: "Referred to as Kibana 'endpoint' in the Elastic deployment dashboard",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
name: 'type',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'API Key',
|
||||
value: 'apiKey',
|
||||
},
|
||||
{
|
||||
name: 'Basic Auth',
|
||||
value: 'basicAuth',
|
||||
},
|
||||
],
|
||||
default: 'basicAuth',
|
||||
},
|
||||
{
|
||||
displayName: 'Username',
|
||||
name: 'username',
|
||||
type: 'string',
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: ['basicAuth'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Password',
|
||||
@@ -24,15 +60,52 @@ export class ElasticSecurityApi implements ICredentialType {
|
||||
},
|
||||
default: '',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: ['basicAuth'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Base URL',
|
||||
name: 'baseUrl',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'e.g. https://mydeployment.kb.us-central1.gcp.cloud.es.io:9243',
|
||||
description: "Referred to as Kibana 'endpoint' in the Elastic deployment dashboard",
|
||||
displayName: 'API Key',
|
||||
name: 'apiKey',
|
||||
required: true,
|
||||
type: 'string',
|
||||
typeOptions: { password: true },
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
type: ['apiKey'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
async authenticate(
|
||||
credentials: ICredentialDataDecryptedObject,
|
||||
requestOptions: IHttpRequestOptions,
|
||||
): Promise<IHttpRequestOptions> {
|
||||
if (credentials.type === 'apiKey') {
|
||||
requestOptions.headers = {
|
||||
Authorization: `ApiKey ${credentials.apiKey}`,
|
||||
};
|
||||
} else {
|
||||
requestOptions.auth = {
|
||||
username: credentials.username as string,
|
||||
password: credentials.password as string,
|
||||
};
|
||||
requestOptions.headers = {
|
||||
'kbn-xsrf': true,
|
||||
};
|
||||
}
|
||||
return requestOptions;
|
||||
}
|
||||
|
||||
test: ICredentialTestRequest = {
|
||||
request: {
|
||||
baseURL: '={{$credentials.baseUrl}}',
|
||||
url: '/api/endpoint/metadata',
|
||||
method: 'GET',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user