mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
feat(Cloudflare Node): add Cloudflare node (#4271)
* ✨ Cloudflare node * ⚡ Add paired items * Added codex file for Cloudflare * ⚡ Improvements Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
This commit is contained in:
parent
1b320cd8c9
commit
94a02c6492
35
packages/nodes-base/credentials/CloudflareApi.credentials.ts
Normal file
35
packages/nodes-base/credentials/CloudflareApi.credentials.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import {
|
||||
IAuthenticateGeneric,
|
||||
ICredentialTestRequest,
|
||||
ICredentialType,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class CloudflareApi implements ICredentialType {
|
||||
name = 'cloudflareApi';
|
||||
displayName = 'Cloudflare API';
|
||||
documentationUrl = 'cloudflare';
|
||||
properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'API Token',
|
||||
name: 'apiToken',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
];
|
||||
|
||||
authenticate: IAuthenticateGeneric = {
|
||||
type: 'generic',
|
||||
properties: {
|
||||
headers: {
|
||||
'Authorization': '=Bearer {{$credentials.apiToken}}',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
test: ICredentialTestRequest = {
|
||||
request: {
|
||||
baseURL: 'https://api.cloudflare.com/client/v4/user/tokens/verify',
|
||||
},
|
||||
};
|
||||
}
|
18
packages/nodes-base/nodes/Cloudflare/Cloudflare.node.json
Normal file
18
packages/nodes-base/nodes/Cloudflare/Cloudflare.node.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"node": "n8n-nodes-base.cloudflare",
|
||||
"nodeVersion": "1.0",
|
||||
"codexVersion": "1.0",
|
||||
"categories": ["Development"],
|
||||
"resources": {
|
||||
"credentialDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/credentials/cloudflare"
|
||||
}
|
||||
],
|
||||
"primaryDocumentation": [
|
||||
{
|
||||
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.cloudflare/"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
179
packages/nodes-base/nodes/Cloudflare/Cloudflare.node.ts
Normal file
179
packages/nodes-base/nodes/Cloudflare/Cloudflare.node.ts
Normal file
|
@ -0,0 +1,179 @@
|
|||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodeExecutionData,
|
||||
INodePropertyOptions,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { cloudflareApiRequest, cloudflareApiRequestAllItems } from './GenericFunctions';
|
||||
|
||||
import { zoneCertificateFields, zoneCertificateOperations } from './ZoneCertificateDescription';
|
||||
|
||||
export class Cloudflare implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Cloudflare',
|
||||
name: 'cloudflare',
|
||||
icon: 'file:cloudflare.svg',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Cloudflare API',
|
||||
defaults: {
|
||||
name: 'Cloudflare',
|
||||
color: '#000000',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'cloudflareApi',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
options: [
|
||||
{
|
||||
name: 'Zone Certificate',
|
||||
value: 'zoneCertificate',
|
||||
},
|
||||
],
|
||||
default: 'zoneCertificate',
|
||||
},
|
||||
...zoneCertificateOperations,
|
||||
...zoneCertificateFields,
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
async getZones(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const { result: zones } = await cloudflareApiRequest.call(this, 'GET', '/zones');
|
||||
for (const zone of zones) {
|
||||
returnData.push({
|
||||
name: zone.name,
|
||||
value: zone.id,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const length = items.length;
|
||||
const qs: IDataObject = {};
|
||||
let responseData;
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
if (resource === 'zoneCertificate') {
|
||||
//https://api.cloudflare.com/#zone-level-authenticated-origin-pulls-delete-certificate
|
||||
if (operation === 'delete') {
|
||||
const zoneId = this.getNodeParameter('zoneId', i) as string;
|
||||
const certificateId = this.getNodeParameter('certificateId', i) as string;
|
||||
|
||||
responseData = await cloudflareApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/zones/${zoneId}/origin_tls_client_auth/${certificateId}`,
|
||||
{},
|
||||
);
|
||||
responseData = responseData.result;
|
||||
}
|
||||
//https://api.cloudflare.com/#zone-level-authenticated-origin-pulls-get-certificate-details
|
||||
if (operation === 'get') {
|
||||
const zoneId = this.getNodeParameter('zoneId', i) as string;
|
||||
const certificateId = this.getNodeParameter('certificateId', i) as string;
|
||||
|
||||
responseData = await cloudflareApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/zones/${zoneId}/origin_tls_client_auth/${certificateId}`,
|
||||
{},
|
||||
);
|
||||
responseData = responseData.result;
|
||||
}
|
||||
//https://api.cloudflare.com/#zone-level-authenticated-origin-pulls-list-certificates
|
||||
if (operation === 'getMany') {
|
||||
const zoneId = this.getNodeParameter('zoneId', i) as string;
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const filters = this.getNodeParameter('filters', i, {}) as IDataObject;
|
||||
|
||||
Object.assign(qs, filters);
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await cloudflareApiRequestAllItems.call(
|
||||
this,
|
||||
'result',
|
||||
'GET',
|
||||
`/zones/${zoneId}/origin_tls_client_auth`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
Object.assign(qs, { per_page: limit });
|
||||
responseData = await cloudflareApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/zones/${zoneId}/origin_tls_client_auth`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.result;
|
||||
}
|
||||
}
|
||||
//https://api.cloudflare.com/#zone-level-authenticated-origin-pulls-upload-certificate
|
||||
if (operation === 'upload') {
|
||||
const zoneId = this.getNodeParameter('zoneId', i) as string;
|
||||
const certificate = this.getNodeParameter('certificate', i) as string;
|
||||
const privateKey = this.getNodeParameter('privateKey', i) as string;
|
||||
|
||||
const body: IDataObject = {
|
||||
certificate,
|
||||
private_key: privateKey,
|
||||
};
|
||||
|
||||
responseData = await cloudflareApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/zones/${zoneId}/origin_tls_client_auth`,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
|
||||
responseData = responseData.result;
|
||||
}
|
||||
}
|
||||
|
||||
returnData.push(
|
||||
...this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), {
|
||||
itemData: { item: i },
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ json: { error: error.message } });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return [returnData as INodeExecutionData[]];
|
||||
}
|
||||
}
|
65
packages/nodes-base/nodes/Cloudflare/GenericFunctions.ts
Normal file
65
packages/nodes-base/nodes/Cloudflare/GenericFunctions.ts
Normal file
|
@ -0,0 +1,65 @@
|
|||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IPollFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject, NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function cloudflareApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IPollFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
method,
|
||||
body,
|
||||
qs,
|
||||
uri: `https://api.cloudflare.com/client/v4${resource}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
try {
|
||||
if (Object.keys(headers).length !== 0) {
|
||||
options.headers = Object.assign({}, options.headers, headers);
|
||||
}
|
||||
if (Object.keys(body).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
return await this.helpers.requestWithAuthentication.call(this, 'cloudflareApi', options);
|
||||
} catch (error) {
|
||||
throw new NodeApiError(this.getNode(), error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function cloudflareApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
propertyName: string,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
body: IDataObject = {},
|
||||
query: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
query.page = 1;
|
||||
|
||||
do {
|
||||
responseData = await cloudflareApiRequest.call(
|
||||
this,
|
||||
method,
|
||||
endpoint,
|
||||
body,
|
||||
query,
|
||||
);
|
||||
query.page++;
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
} while (responseData.result_info.total_pages !== responseData.result_info.page);
|
||||
return returnData;
|
||||
}
|
|
@ -0,0 +1,220 @@
|
|||
import {
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export const zoneCertificateOperations: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'Operation',
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'zoneCertificate',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a certificate',
|
||||
action: 'Delete a certificate',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a certificate',
|
||||
action: 'Get a certificate',
|
||||
},
|
||||
{
|
||||
name: 'Get Many',
|
||||
value: 'getMany',
|
||||
description: 'Get many certificates',
|
||||
action: 'Get many certificates',
|
||||
},
|
||||
{
|
||||
name: 'Upload',
|
||||
value: 'upload',
|
||||
description: 'Upload a certificate',
|
||||
action: 'Upload a certificate',
|
||||
},
|
||||
],
|
||||
default: 'upload',
|
||||
},
|
||||
];
|
||||
|
||||
export const zoneCertificateFields: INodeProperties[] = [
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* certificate:upload */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Zone Name or ID',
|
||||
name: 'zoneId',
|
||||
type: 'options',
|
||||
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getZones',
|
||||
},
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'zoneCertificate',
|
||||
],
|
||||
operation: [
|
||||
'upload',
|
||||
'getMany',
|
||||
'get',
|
||||
'delete',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Certificate Content',
|
||||
name: 'certificate',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'zoneCertificate',
|
||||
],
|
||||
operation: [
|
||||
'upload',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The zone\'s leaf certificate',
|
||||
},
|
||||
{
|
||||
displayName: 'Private Key',
|
||||
name: 'privateKey',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'zoneCertificate',
|
||||
],
|
||||
operation: [
|
||||
'upload',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* certificate:getMany */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
type: 'boolean',
|
||||
description: 'Whether to return all results or only up to a given limit',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'zoneCertificate',
|
||||
],
|
||||
operation: [
|
||||
'getMany',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Limit',
|
||||
name: 'limit',
|
||||
type: 'number',
|
||||
default: 25,
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
maxValue: 50,
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'zoneCertificate',
|
||||
],
|
||||
operation: [
|
||||
'getMany',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'Max number of results to return',
|
||||
},
|
||||
{
|
||||
displayName: 'Filters',
|
||||
name: 'filters',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'zoneCertificate',
|
||||
],
|
||||
operation: [
|
||||
'getMany',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Status',
|
||||
name: 'status',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Active',
|
||||
value: 'active',
|
||||
},
|
||||
{
|
||||
name: 'Expired',
|
||||
value: 'expired',
|
||||
},
|
||||
{
|
||||
name: 'Deleted',
|
||||
value: 'deleted',
|
||||
},
|
||||
{
|
||||
name: 'Pending',
|
||||
value: 'pending',
|
||||
},
|
||||
],
|
||||
default: '',
|
||||
description: 'Status of the zone\'s custom SSL',
|
||||
},
|
||||
],
|
||||
},
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* certificate:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Certificate ID',
|
||||
name: 'certificateId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'zoneCertificate',
|
||||
],
|
||||
operation: [
|
||||
'get',
|
||||
'delete',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
];
|
4
packages/nodes-base/nodes/Cloudflare/cloudflare.svg
Normal file
4
packages/nodes-base/nodes/Cloudflare/cloudflare.svg
Normal file
|
@ -0,0 +1,4 @@
|
|||
<svg width="1024px" height="1024px" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="512" cy="512" r="512" style="fill:#f38020"/>
|
||||
<path d="M608.2 592.4c3.1-10.8 1.9-20.7-3.3-28.1-4.8-6.7-12.9-10.6-22.6-11.1l-184.7-2.4c-1.1 0-2.2-.6-2.8-1.5-.6-.9-.7-2.1-.4-3.3.6-1.8 2.4-3.2 4.3-3.3l186.4-2.4c22.1-1 46.1-18.9 54.5-40.8l10.6-27.8c.5-1.2.6-2.4.3-3.6-12-54.3-60.5-94.8-118.4-94.8-53.4 0-98.7 34.5-114.9 82.4-10.5-7.8-23.9-12-38.3-10.6-25.7 2.5-46.2 23.1-48.8 48.8-.6 6.6-.1 13.1 1.4 19.1-41.9 1.2-75.3 35.4-75.3 77.6 0 3.7.3 7.5.8 11.2.3 1.8 1.8 3.1 3.6 3.1h340.9c1.9 0 3.8-1.4 4.3-3.3l2.4-9.2zM667 473.7c-1.6 0-3.4 0-5.1.2-1.2 0-2.2.9-2.7 2.1l-7.2 25c-3.1 10.8-2 20.7 3.3 28.1 4.8 6.7 12.9 10.6 22.7 11.1l39.3 2.4c1.2 0 2.3.6 2.8 1.5.6.9.7 2.3.5 3.3-.6 1.8-2.4 3.2-4.4 3.3l-41 2.4c-22.2 1-46 18.9-54.5 40.8l-3 7.6c-.6 1.5.5 3 2.1 3h140.8c1.6 0 3.1-1 3.6-2.7 2.4-8.7 3.7-17.9 3.7-27.3 0-55.5-45.3-100.8-101-100.8" style="fill:#fff"/>
|
||||
</svg>
|
After Width: | Height: | Size: 967 B |
|
@ -60,6 +60,7 @@
|
|||
"dist/credentials/ChargebeeApi.credentials.js",
|
||||
"dist/credentials/CircleCiApi.credentials.js",
|
||||
"dist/credentials/CiscoWebexOAuth2Api.credentials.js",
|
||||
"dist/credentials/CloudflareApi.credentials.js",
|
||||
"dist/credentials/ClearbitApi.credentials.js",
|
||||
"dist/credentials/ClickUpApi.credentials.js",
|
||||
"dist/credentials/ClickUpOAuth2Api.credentials.js",
|
||||
|
@ -384,6 +385,7 @@
|
|||
"dist/nodes/CircleCi/CircleCi.node.js",
|
||||
"dist/nodes/Cisco/Webex/CiscoWebex.node.js",
|
||||
"dist/nodes/Cisco/Webex/CiscoWebexTrigger.node.js",
|
||||
"dist/nodes/Cloudflare/Cloudflare.node.js",
|
||||
"dist/nodes/Clearbit/Clearbit.node.js",
|
||||
"dist/nodes/ClickUp/ClickUp.node.js",
|
||||
"dist/nodes/ClickUp/ClickUpTrigger.node.js",
|
||||
|
|
Loading…
Reference in a new issue