Skip to content

Commit

Permalink
feat: Add new credentials for the HTTP Request node (#9833)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 23, 2024
1 parent 6422fb3 commit 26f1af3
Show file tree
Hide file tree
Showing 16 changed files with 827 additions and 75 deletions.
73 changes: 73 additions & 0 deletions packages/nodes-base/credentials/DatadogApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import type {
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';

export class DatadogApi implements ICredentialType {
name = 'datadogApi';

displayName = 'Datadog API';

documentationUrl = 'datadog';

icon = { light: 'file:icons/Datadog.svg', dark: 'file:icons/Datadog.svg' } as const;

httpRequestNode = {
name: 'Datadog',
docsUrl: 'https://docs.datadoghq.com/api/latest/',
apiBaseUrlPlaceholder: 'https://api.datadoghq.com/api/v1/metrics',
};

properties: INodeProperties[] = [
{
displayName: 'URL',
name: 'url',
required: true,
type: 'string',
default: 'https://api.datadoghq.com',
},
{
displayName: 'API Key',
name: 'apiKey',
required: true,
type: 'string',
typeOptions: { password: true },
default: '',
},
{
displayName: 'APP Key',
name: 'appKey',
required: false,
type: 'string',
default: '',
typeOptions: { password: true },
description: 'For some endpoints, you also need an Application key.',
},
];

async authenticate(
credentials: ICredentialDataDecryptedObject,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
requestOptions.headers = {
'DD-API-KEY': credentials.apiKey,
'DD-APPLICATION-KEY': credentials.appKey,
};
if (!requestOptions.headers['DD-APPLICATION-KEY']) {
delete requestOptions.headers['DD-APPLICATION-KEY'];
}

return requestOptions;
}

test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.url}}',
url: '/api/v1/validate',
method: 'GET',
},
};
}
67 changes: 67 additions & 0 deletions packages/nodes-base/credentials/DfirIrisApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';

export class DfirIrisApi implements ICredentialType {
name = 'dfirIrisApi';

displayName = 'DFIR-IRIS API';

documentationUrl = 'dfiriris';

icon = { light: 'file:icons/DfirIris.svg', dark: 'file:icons/DfirIris.svg' } as const;

httpRequestNode = {
name: 'DFIR-IRIS',
docsUrl: 'https://docs.dfir-iris.org/operations/api/',
apiBaseUrlPlaceholder: 'http://<yourserver_ip>/manage/cases/list',
};

properties: INodeProperties[] = [
{
displayName: 'Base URL',
name: 'baseUrl',
type: 'string',
default: '',
placeholder: 'e.g. https://localhost',
description:
'The API endpoints are reachable on the same Address and port as the web interface.',
required: true,
},
{
displayName: 'API Key',
name: 'apiKey',
required: true,
type: 'string',
typeOptions: { password: true },
default: '',
},
{
displayName: 'Ignore SSL Issues',
name: 'skipSslCertificateValidation',
type: 'boolean',
default: false,
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.apiKey}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.baseUrl}}',
url: '/api/ping',
method: 'GET',
skipSslCertificateValidation: '={{$credentials.skipSslCertificateValidation}}',
},
};
}
37 changes: 37 additions & 0 deletions packages/nodes-base/credentials/DynatraceApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { IAuthenticateGeneric, ICredentialType, INodeProperties } from 'n8n-workflow';

export class DynatraceApi implements ICredentialType {
name = 'dynatraceApi';

displayName = 'DynatraceAPI';

documentationUrl = 'dynatrace';

icon = { light: 'file:icons/Dynatrace.svg', dark: 'file:icons/Dynatrace.svg' } as const;

httpRequestNode = {
name: 'Dynatrace',
docsUrl: 'https://docs.dynatrace.com/docs/dynatrace-api',
apiBaseUrlPlaceholder: 'https://{your-environment-id}.live.dynatrace.com/api/v2/events',
};

properties: INodeProperties[] = [
{
displayName: 'API Key',
name: 'apiKey',
required: true,
type: 'string',
typeOptions: { password: true },
default: '',
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Api-Token {{$credentials.apiKey}}',
},
},
};
}
85 changes: 79 additions & 6 deletions packages/nodes-base/credentials/ElasticSecurityApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand All @@ -24,15 +60,52 @@ export class ElasticSecurityApi implements ICredentialType {
},
default: '',
required: true,
displayOptions: {
show: {
type: ['basicAuth'],
},
},
},
{
displayName: 'Base URL',
name: 'baseUrl',
displayName: 'API Key',
name: 'apiKey',
required: true,
type: 'string',
typeOptions: { password: true },
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,
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',
},
};
}
50 changes: 50 additions & 0 deletions packages/nodes-base/credentials/FilescanApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';

export class FilescanApi implements ICredentialType {
name = 'filescanApi';

displayName = 'Filescan API';

documentationUrl = 'filescan';

icon = { light: 'file:icons/Filescan.svg', dark: 'file:icons/Filescan.svg' } as const;

httpRequestNode = {
name: 'Filescan',
docsUrl: 'https://www.filescan.io/api/docs',
apiBaseUrlPlaceholder: 'https://www.filescan.io/api/system/do-healthcheck',
};

properties: INodeProperties[] = [
{
displayName: 'API Key',
name: 'apiKey',
required: true,
type: 'string',
typeOptions: { password: true },
default: '',
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
'X-Api-Key': '={{$credentials.apiKey}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: 'https://www.filescan.io/api',
url: '/system/do-healthcheck',
method: 'GET',
},
};
}
51 changes: 51 additions & 0 deletions packages/nodes-base/credentials/MalcoreApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';

export class MalcoreApi implements ICredentialType {
name = 'malcoreApi';

displayName = 'MalcoreAPI';

documentationUrl = 'malcore';

icon = { light: 'file:icons/Malcore.png', dark: 'file:icons/Malcore.png' } as const;

httpRequestNode = {
name: 'Malcore',
docsUrl: 'https://malcore.readme.io/reference/upload',
apiBaseUrlPlaceholder: 'https://api.malcore.io/api/urlcheck',
};

properties: INodeProperties[] = [
{
displayName: 'API Key',
name: 'apiKey',
required: true,
type: 'string',
typeOptions: { password: true },
default: '',
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
apiKey: '={{$credentials.apiKey}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.malcore.io/api',
url: '/urlcheck',
method: 'POST',
body: { url: 'google.com' },
},
};
}
1 change: 1 addition & 0 deletions packages/nodes-base/credentials/icons/Datadog.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 26f1af3

Please sign in to comment.