UNPKG

n8n-nodes-netbox

Version:

n8n community node for NetBox API integration with comprehensive DCIM, IPAM, and data center management operations

95 lines (94 loc) 4.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listConfigTemplates = listConfigTemplates; exports.getConfigTemplate = getConfigTemplate; exports.createConfigTemplate = createConfigTemplate; exports.updateConfigTemplate = updateConfigTemplate; exports.deleteConfigTemplate = deleteConfigTemplate; exports.renderConfigTemplate = renderConfigTemplate; const apiRequest_1 = require("../../../helpers/apiRequest"); const responseFormatter_1 = require("../../../helpers/responseFormatter"); async function listConfigTemplates() { const filters = this.getNodeParameter('filter', 0, {}); const endpoint = '/api/extras/config-templates/'; const response = await apiRequest_1.apiRequestAllItems.call(this, 'GET', endpoint, {}, filters); return responseFormatter_1.formatResponse.call(this, response); } async function getConfigTemplate() { const configTemplateId = this.getNodeParameter('configTemplateId', 0); const endpoint = `/api/extras/config-templates/${configTemplateId}/`; const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint); return responseFormatter_1.formatResponse.call(this, response); } async function createConfigTemplate() { const name = this.getNodeParameter('name', 0); const templateCode = this.getNodeParameter('template_code', 0); const description = this.getNodeParameter('description', 0, ''); const envParamsJson = this.getNodeParameter('environment_params', 0, '{}'); let environmentParams; try { environmentParams = JSON.parse(envParamsJson); } catch (error) { throw new Error('Invalid JSON in environment parameters field'); } const body = { name, template_code: templateCode, }; if (description) body.description = description; if (Object.keys(environmentParams).length > 0) body.environment_params = environmentParams; const endpoint = '/api/extras/config-templates/'; const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body); return responseFormatter_1.formatResponse.call(this, response); } async function updateConfigTemplate() { const configTemplateId = this.getNodeParameter('configTemplateId', 0); const name = this.getNodeParameter('name', 0); const templateCode = this.getNodeParameter('template_code', 0); const description = this.getNodeParameter('description', 0, ''); const envParamsJson = this.getNodeParameter('environment_params', 0, '{}'); let environmentParams; try { environmentParams = JSON.parse(envParamsJson); } catch (error) { throw new Error('Invalid JSON in environment parameters field'); } const body = { name, template_code: templateCode, }; if (description) body.description = description; if (Object.keys(environmentParams).length > 0) body.environment_params = environmentParams; const endpoint = `/api/extras/config-templates/${configTemplateId}/`; const response = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, body); return responseFormatter_1.formatResponse.call(this, response); } async function deleteConfigTemplate() { const configTemplateId = this.getNodeParameter('configTemplateId', 0); const endpoint = `/api/extras/config-templates/${configTemplateId}/`; await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint); return [{ json: { success: true } }]; } async function renderConfigTemplate() { const configTemplateId = this.getNodeParameter('configTemplateId', 0); const contextJson = this.getNodeParameter('context', 0, '{}'); let context; try { context = JSON.parse(contextJson); } catch (error) { throw new Error('Invalid JSON in context field'); } const body = { context, }; const endpoint = `/api/extras/config-templates/${configTemplateId}/render/`; const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body); return responseFormatter_1.formatResponse.call(this, response); }