n8n-nodes-ionos
Version:
n8n nodes for IONOS DNS, Domain, SSL/Certificate management, Cloud AI, Cloud Infrastructure, Container Registry, Database as a Service, CDN, VPN Gateway, Activity Log, Billing, Logging, Monitoring, Object Storage Management, Network File Storage, Identity
666 lines (665 loc) • 25.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IonosDns = void 0;
const n8n_workflow_1 = require("n8n-workflow");
class IonosDns {
description = {
displayName: 'IONOS DNS',
name: 'ionosDns',
icon: 'file:ionos.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Manage DNS zones and records with IONOS. Developped with Love by Ascenzia (ascenzia.fr)',
defaults: {
name: 'IONOS DNS',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'ionosApi',
required: true,
},
],
requestDefaults: {
baseURL: '={{$credentials.baseUrl}}',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
},
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Zone',
value: 'zone',
},
{
name: 'Record',
value: 'record',
},
],
default: 'zone',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['zone'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new DNS zone',
action: 'Create a zone',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a DNS zone',
action: 'Delete a zone',
},
{
name: 'Get',
value: 'get',
description: 'Get a DNS zone',
action: 'Get a zone',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get all DNS zones',
action: 'Get many zones',
},
{
name: 'Update',
value: 'update',
description: 'Update a DNS zone',
action: 'Update a zone',
},
],
default: 'getAll',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['record'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new DNS record',
action: 'Create a record',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a DNS record',
action: 'Delete a record',
},
{
name: 'Get',
value: 'get',
description: 'Get a DNS record',
action: 'Get a record',
},
{
name: 'Get Many',
value: 'getAll',
description: 'Get all DNS records in a zone',
action: 'Get many records',
},
{
name: 'Update',
value: 'update',
description: 'Update a DNS record',
action: 'Update a record',
},
],
default: 'getAll',
},
{
displayName: 'Zone Name',
name: 'zoneName',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['zone'],
operation: ['create'],
},
},
default: '',
placeholder: 'example.com',
description: 'The name of the DNS zone to create',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
displayOptions: {
show: {
resource: ['zone'],
operation: ['create'],
},
},
options: [
{
name: 'Native',
value: 'NATIVE',
},
{
name: 'Master',
value: 'MASTER',
},
{
name: 'Slave',
value: 'SLAVE',
},
],
default: 'NATIVE',
description: 'The type of the DNS zone',
},
{
displayName: 'Zone ID',
name: 'zoneId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['zone'],
operation: ['get', 'update', 'delete'],
},
},
default: '',
description: 'The ID of the DNS zone',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['zone'],
operation: ['update'],
},
},
options: [
{
displayName: 'Zone Name',
name: 'name',
type: 'string',
default: '',
description: 'The new name of the DNS zone',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
options: [
{
name: 'Native',
value: 'NATIVE',
},
{
name: 'Master',
value: 'MASTER',
},
{
name: 'Slave',
value: 'SLAVE',
},
],
default: 'NATIVE',
description: 'The type of the DNS zone',
},
],
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['zone'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['zone'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 50,
description: 'Max number of results to return',
},
{
displayName: 'Zone ID',
name: 'zoneId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['record'],
},
},
default: '',
description: 'The ID of the DNS zone',
},
{
displayName: 'Record Name',
name: 'recordName',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['record'],
operation: ['create'],
},
},
default: '',
placeholder: 'www',
description: 'The name of the DNS record',
},
{
displayName: 'Record Type',
name: 'recordType',
type: 'options',
required: true,
displayOptions: {
show: {
resource: ['record'],
operation: ['create'],
},
},
options: [
{
name: 'A',
value: 'A',
},
{
name: 'AAAA',
value: 'AAAA',
},
{
name: 'CNAME',
value: 'CNAME',
},
{
name: 'MX',
value: 'MX',
},
{
name: 'TXT',
value: 'TXT',
},
{
name: 'SRV',
value: 'SRV',
},
{
name: 'NS',
value: 'NS',
},
{
name: 'CAA',
value: 'CAA',
},
],
default: 'A',
description: 'The type of the DNS record',
},
{
displayName: 'Content',
name: 'content',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['record'],
operation: ['create'],
},
},
default: '',
placeholder: '192.168.1.1',
description: 'The content/value of the DNS record',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['record'],
operation: ['create'],
},
},
options: [
{
displayName: 'TTL',
name: 'ttl',
type: 'number',
default: 3600,
description: 'Time to live in seconds',
},
{
displayName: 'Priority',
name: 'priority',
type: 'number',
default: 10,
description: 'Priority of the record (for MX and SRV records)',
},
{
displayName: 'Disabled',
name: 'disabled',
type: 'boolean',
default: false,
description: 'Whether the record is disabled',
},
],
},
{
displayName: 'Record ID',
name: 'recordId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['record'],
operation: ['get', 'update', 'delete'],
},
},
default: '',
description: 'The ID of the DNS record',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['record'],
operation: ['update'],
},
},
options: [
{
displayName: 'Record Name',
name: 'name',
type: 'string',
default: '',
description: 'The new name of the DNS record',
},
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
description: 'The new content/value of the DNS record',
},
{
displayName: 'TTL',
name: 'ttl',
type: 'number',
default: 3600,
description: 'Time to live in seconds',
},
{
displayName: 'Priority',
name: 'priority',
type: 'number',
default: 10,
description: 'Priority of the record',
},
{
displayName: 'Disabled',
name: 'disabled',
type: 'boolean',
default: false,
description: 'Whether the record is disabled',
},
],
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: ['record'],
operation: ['getAll'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: ['record'],
operation: ['getAll'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 50,
description: 'Max number of results to return',
},
],
};
async execute() {
const items = this.getInputData();
const returnData = [];
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
for (let i = 0; i < items.length; i++) {
try {
if (resource === 'zone') {
if (operation === 'create') {
const zoneName = this.getNodeParameter('zoneName', i);
const type = this.getNodeParameter('type', i);
const body = {
name: zoneName,
type,
};
const options = {
method: 'POST',
url: '/dns/v1/zones',
body,
};
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosApi', options);
returnData.push({ json: response });
}
if (operation === 'get') {
const zoneId = this.getNodeParameter('zoneId', i);
const options = {
method: 'GET',
url: `/dns/v1/zones/${zoneId}`,
};
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosApi', options);
returnData.push({ json: response });
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i);
const limit = this.getNodeParameter('limit', i, 50);
const options = {
method: 'GET',
url: '/dns/v1/zones',
qs: {
limit: returnAll ? 1000 : limit,
},
};
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosApi', options);
const zones = response.items;
zones.forEach((zone) => {
returnData.push({ json: zone });
});
}
if (operation === 'update') {
const zoneId = this.getNodeParameter('zoneId', i);
const updateFields = this.getNodeParameter('updateFields', i);
const body = {};
if (updateFields.name)
body.name = updateFields.name;
if (updateFields.type)
body.type = updateFields.type;
const options = {
method: 'PATCH',
url: `/dns/v1/zones/${zoneId}`,
body,
};
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosApi', options);
returnData.push({ json: response });
}
if (operation === 'delete') {
const zoneId = this.getNodeParameter('zoneId', i);
const options = {
method: 'DELETE',
url: `/dns/v1/zones/${zoneId}`,
};
await this.helpers.httpRequestWithAuthentication.call(this, 'ionosApi', options);
returnData.push({ json: { success: true, zoneId } });
}
}
if (resource === 'record') {
const zoneId = this.getNodeParameter('zoneId', i);
if (operation === 'create') {
const recordName = this.getNodeParameter('recordName', i);
const recordType = this.getNodeParameter('recordType', i);
const content = this.getNodeParameter('content', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const body = {
name: recordName,
type: recordType,
content,
ttl: additionalFields.ttl || 3600,
};
if (additionalFields.priority !== undefined) {
body.priority = additionalFields.priority;
}
if (additionalFields.disabled !== undefined) {
body.disabled = additionalFields.disabled;
}
const options = {
method: 'POST',
url: `/dns/v1/zones/${zoneId}/records`,
body,
};
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosApi', options);
returnData.push({ json: response });
}
if (operation === 'get') {
const recordId = this.getNodeParameter('recordId', i);
const options = {
method: 'GET',
url: `/dns/v1/zones/${zoneId}/records/${recordId}`,
};
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosApi', options);
returnData.push({ json: response });
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i);
const limit = this.getNodeParameter('limit', i, 50);
const options = {
method: 'GET',
url: `/dns/v1/zones/${zoneId}/records`,
qs: {
limit: returnAll ? 1000 : limit,
},
};
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosApi', options);
const records = response.items;
records.forEach((record) => {
returnData.push({ json: record });
});
}
if (operation === 'update') {
const recordId = this.getNodeParameter('recordId', i);
const updateFields = this.getNodeParameter('updateFields', i);
const body = {};
if (updateFields.name)
body.name = updateFields.name;
if (updateFields.content)
body.content = updateFields.content;
if (updateFields.ttl)
body.ttl = updateFields.ttl;
if (updateFields.priority !== undefined)
body.priority = updateFields.priority;
if (updateFields.disabled !== undefined)
body.disabled = updateFields.disabled;
const options = {
method: 'PATCH',
url: `/dns/v1/zones/${zoneId}/records/${recordId}`,
body,
};
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosApi', options);
returnData.push({ json: response });
}
if (operation === 'delete') {
const recordId = this.getNodeParameter('recordId', i);
const options = {
method: 'DELETE',
url: `/dns/v1/zones/${zoneId}/records/${recordId}`,
};
await this.helpers.httpRequestWithAuthentication.call(this, 'ionosApi', options);
returnData.push({ json: { success: true, recordId } });
}
}
}
catch (error) {
if (this.continueOnFail()) {
const errorMessage = error instanceof Error ? error.message : String(error);
returnData.push({ json: { error: errorMessage } });
continue;
}
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, {
itemIndex: i,
});
}
}
return [returnData];
}
}
exports.IonosDns = IonosDns;