mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-13 16:14:07 -08:00
26f1af397b
Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com> Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com>
112 lines
2.1 KiB
TypeScript
112 lines
2.1 KiB
TypeScript
import type {
|
|
ICredentialDataDecryptedObject,
|
|
ICredentialTestRequest,
|
|
ICredentialType,
|
|
IHttpRequestOptions,
|
|
INodeProperties,
|
|
} from 'n8n-workflow';
|
|
|
|
export class ElasticSecurityApi implements ICredentialType {
|
|
name = 'elasticSecurityApi';
|
|
|
|
displayName = 'Elastic Security API';
|
|
|
|
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',
|
|
name: 'password',
|
|
type: 'string',
|
|
typeOptions: {
|
|
password: true,
|
|
},
|
|
default: '',
|
|
required: true,
|
|
displayOptions: {
|
|
show: {
|
|
type: ['basicAuth'],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
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',
|
|
},
|
|
};
|
|
}
|