UNPKG

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

650 lines (649 loc) 28.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IonosCloudLogging = void 0; class IonosCloudLogging { description = { displayName: 'IONOS Cloud Logging', name: 'ionosCloudLogging', icon: 'file:ionos.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["resource"]}} - {{$parameter["operation"]}}', description: 'Manage centralized logging pipelines, keys, and configurations with IONOS Cloud Logging Service. Developped with Love by Ascenzia (ascenzia.fr)', defaults: { name: 'IONOS Cloud Logging', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'ionosCloud', required: true, }, ], properties: [ { displayName: 'Location', name: 'location', type: 'options', options: [ { name: 'Frankfurt (de-fra)', value: 'de-fra', }, { name: 'Berlin (de-txl)', value: 'de-txl', }, { name: 'Vitoria (es-vit)', value: 'es-vit', }, { name: 'Birmingham (gb-bhx)', value: 'gb-bhx', }, { name: 'London (gb-lhr)', value: 'gb-lhr', }, { name: 'Paris (fr-par)', value: 'fr-par', }, { name: 'Kansas City (us-mci)', value: 'us-mci', }, ], default: 'de-fra', description: 'The IONOS Cloud location', }, { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Pipeline', value: 'pipeline', description: 'Centralized logging pipeline', }, { name: 'Key', value: 'key', description: 'Pipeline authentication key', }, { name: 'Central Logging', value: 'centralLogging', description: 'Central logging configuration', }, ], default: 'pipeline', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['pipeline'], }, }, options: [ { name: 'Create', value: 'create', description: 'Create a new resource', action: 'Create a resource', }, { name: 'Get', value: 'get', description: 'Get a resource', action: 'Get a resource', }, { name: 'Get Many', value: 'getMany', description: 'Get many resources', action: 'Get many resources', }, { name: 'Update', value: 'update', description: 'Update a resource', action: 'Update a resource', }, { name: 'Delete', value: 'delete', description: 'Delete a resource', action: 'Delete a resource', }, ], default: 'create', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['centralLogging'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get a central logging configuration', action: 'Get a central logging configuration', }, { name: 'Get Many', value: 'getMany', description: 'Get all central logging configurations', action: 'Get many central logging configurations', }, { name: 'Update', value: 'update', description: 'Update a central logging configuration', action: 'Update a central logging configuration', }, { name: 'Delete', value: 'delete', description: 'Delete a central logging configuration', action: 'Delete a central logging configuration', }, ], default: 'getMany', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['key'], }, }, options: [ { name: 'Regenerate', value: 'regenerate', description: 'Generate a new key (invalidates the old one)', action: 'Regenerate key', }, ], default: 'regenerate', }, { displayName: 'Pipeline ID', name: 'pipelineId', type: 'string', required: true, displayOptions: { show: { resource: ['pipeline', 'key'], operation: ['get', 'update', 'delete', 'regenerate'], }, }, default: '', description: 'The ID (UUID) of the Pipeline', }, { displayName: 'Name', name: 'name', type: 'string', required: true, displayOptions: { show: { resource: ['pipeline'], operation: ['create', 'update'], }, }, default: '', placeholder: 'MyPipeline', description: 'The name of the pipeline (max 20 characters)', }, { displayName: 'Logs', name: 'logs', type: 'fixedCollection', typeOptions: { multipleValues: true, }, displayOptions: { show: { resource: ['pipeline'], operation: ['create', 'update'], }, }, default: {}, description: 'Log sources and destinations configuration', options: [ { name: 'logValues', displayName: 'Log Configuration', values: [ { displayName: 'Source', name: 'source', type: 'options', options: [ { name: 'Generic', value: 'generic', }, { name: 'Kubernetes', value: 'kubernetes', }, { name: 'Docker', value: 'docker', }, { name: 'Systemd', value: 'systemd', }, ], default: 'generic', description: 'The source of the logs', }, { displayName: 'Tag', name: 'tag', type: 'string', default: '', placeholder: 'app1', description: 'Short alphanumeric badge (3-20 characters, letters and digits only)', }, { displayName: 'Protocol', name: 'protocol', type: 'options', options: [ { name: 'HTTP', value: 'http', }, { name: 'TCP', value: 'tcp', }, ], default: 'http', description: 'The protocol used to send logs', }, { displayName: 'Destinations', name: 'destinations', type: 'fixedCollection', typeOptions: { multipleValues: true, }, default: {}, options: [ { name: 'destinationValues', displayName: 'Destination', values: [ { displayName: 'Type', name: 'type', type: 'options', options: [ { name: 'Loki', value: 'loki', }, ], default: 'loki', description: 'The type of the destination', }, { displayName: 'Retention In Days', name: 'retentionInDays', type: 'options', options: [ { name: 'No Retention (0 days)', value: 0, }, { name: '7 Days', value: 7, }, { name: '14 Days', value: 14, }, { name: '30 Days', value: 30, }, ], default: 30, description: 'The retention period of the logs in days', }, ], }, ], }, ], }, ], }, { displayName: 'Central Logging ID', name: 'centralId', type: 'string', required: true, displayOptions: { show: { resource: ['centralLogging'], operation: ['get', 'update', 'delete'], }, }, default: '', description: 'The ID (UUID) of the Central Logging configuration', }, { displayName: 'Enabled', name: 'enabled', type: 'boolean', required: true, displayOptions: { show: { resource: ['centralLogging'], operation: ['update'], }, }, default: false, description: 'Whether central logging is enabled', }, { displayName: 'Return All', name: 'returnAll', type: 'boolean', displayOptions: { show: { operation: ['getMany'], }, }, default: false, description: 'Whether to return all results or only up to a given limit', }, { displayName: 'Limit', name: 'limit', type: 'number', displayOptions: { show: { operation: ['getMany'], returnAll: [false], }, }, typeOptions: { minValue: 1, maxValue: 1000, }, default: 50, description: 'Max number of results to return', }, { displayName: 'Offset', name: 'offset', type: 'number', displayOptions: { show: { operation: ['getMany'], }, }, typeOptions: { minValue: 0, }, default: 0, description: 'Number of results to skip', }, { displayName: 'Order By', name: 'orderBy', type: 'options', displayOptions: { show: { resource: ['pipeline'], operation: ['getMany'], }, }, options: [ { name: 'Created Date (Newest First)', value: '-createdDate', }, { name: 'Created Date (Oldest First)', value: 'createdDate', }, { name: 'Last Modified Date (Newest First)', value: '-lastModifiedDate', }, { name: 'Last Modified Date (Oldest First)', value: 'lastModifiedDate', }, { name: 'Name (A-Z)', value: 'name', }, { name: 'Name (Z-A)', value: '-name', }, ], default: '-createdDate', description: 'The field to order the results by', }, ], }; async execute() { const items = this.getInputData(); const returnData = []; const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); const location = this.getNodeParameter('location', 0); const baseUrl = `https://logging.${location}.ionos.com`; for (let i = 0; i < items.length; i++) { try { let responseData = {}; if (resource === 'pipeline') { if (operation === 'create') { const name = this.getNodeParameter('name', i); const logs = this.getNodeParameter('logs', i); const logsArray = []; if (logs.logValues && Array.isArray(logs.logValues)) { for (const log of logs.logValues) { const destinations = []; if (log.destinations) { const destData = log.destinations; if (destData.destinationValues && Array.isArray(destData.destinationValues)) { for (const dest of destData.destinationValues) { destinations.push({ type: dest.type, retentionInDays: dest.retentionInDays, }); } } } logsArray.push({ source: log.source, tag: log.tag, protocol: log.protocol, destinations, }); } } const body = { properties: { name, logs: logsArray, }, }; responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'POST', url: `${baseUrl}/pipelines`, body, headers: { 'Content-Type': 'application/json' }, }); } else if (operation === 'get') { const pipelineId = this.getNodeParameter('pipelineId', i); responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/pipelines/${pipelineId}`, }); } else if (operation === 'getMany') { const returnAll = this.getNodeParameter('returnAll', i); const limit = this.getNodeParameter('limit', i, 50); const offset = this.getNodeParameter('offset', i, 0); const orderBy = this.getNodeParameter('orderBy', i, '-createdDate'); const qs = { offset: offset.toString(), orderBy, }; if (!returnAll) { qs.limit = limit.toString(); } responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/pipelines`, qs, }); responseData = responseData.items; } else if (operation === 'update') { const pipelineId = this.getNodeParameter('pipelineId', i); const name = this.getNodeParameter('name', i); const logs = this.getNodeParameter('logs', i, {}); const logsArray = []; if (logs.logValues && Array.isArray(logs.logValues)) { for (const log of logs.logValues) { const destinations = []; if (log.destinations) { const destData = log.destinations; if (destData.destinationValues && Array.isArray(destData.destinationValues)) { for (const dest of destData.destinationValues) { destinations.push({ type: dest.type, retentionInDays: dest.retentionInDays, }); } } } logsArray.push({ source: log.source, tag: log.tag, protocol: log.protocol, destinations, }); } } const properties = { name }; if (logs.logValues && Array.isArray(logs.logValues) && logs.logValues.length > 0) { properties.logs = logsArray; } const body = { properties }; responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'PATCH', url: `${baseUrl}/pipelines/${pipelineId}`, body, headers: { 'Content-Type': 'application/json' }, }); } else if (operation === 'delete') { const pipelineId = this.getNodeParameter('pipelineId', i); await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'DELETE', url: `${baseUrl}/pipelines/${pipelineId}`, }); responseData = { success: true }; } } else if (resource === 'key') { if (operation === 'regenerate') { const pipelineId = this.getNodeParameter('pipelineId', i); const body = {}; responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'POST', url: `${baseUrl}/pipelines/${pipelineId}/key`, body, headers: { 'Content-Type': 'application/json' }, }); } } else if (resource === 'centralLogging') { if (operation === 'get') { const centralId = this.getNodeParameter('centralId', i); responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/central/${centralId}`, }); } else if (operation === 'getMany') { responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'GET', url: `${baseUrl}/central`, }); responseData = responseData.items; } else if (operation === 'update') { const centralId = this.getNodeParameter('centralId', i); const enabled = this.getNodeParameter('enabled', i); const body = { properties: { enabled, }, }; responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'PUT', url: `${baseUrl}/central/${centralId}`, body, headers: { 'Content-Type': 'application/json' }, }); } else if (operation === 'delete') { const centralId = this.getNodeParameter('centralId', i); await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', { method: 'DELETE', url: `${baseUrl}/central/${centralId}`, }); responseData = { success: true }; } } const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } }); returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } }); returnData.push(...executionData); continue; } throw error; } } return [returnData]; } } exports.IonosCloudLogging = IonosCloudLogging;