UNPKG

n8n

Version:

n8n Workflow Automation Tool

146 lines 6.1 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.InfisicalProvider = void 0; const n8n_workflow_1 = require("n8n-workflow"); const types_1 = require("../types"); class InfisicalProvider extends types_1.SecretsProvider { constructor() { super(...arguments); this.properties = [ { displayName: '<h2>Important information about our infisical integration</h2><br>From the <b>30th July, 2024</b>, we will no longer be supporting new connections to inifiscal secrets vault using service tokens. Existing service tokens will remain usable until <b>July, 2025</b>. After that period, we will be removing support for Infisical from our external secrets integrations. You can find out more information about this change on <a href="https://docs.n8n.io/external-secrets/#connect-n8n-to-your-secrets-store" target="_blank">our docs</a>', name: 'notice', type: 'notice', default: '', noDataExpression: true, }, { displayName: 'Service Token', name: 'token', type: 'string', hint: 'The Infisical Service Token with read access', default: '', required: true, placeholder: 'e.g. st.64ae963e1874ea.374226a166439dce.39557e4a1b7bdd82', noDataExpression: true, typeOptions: { password: true }, }, { displayName: 'Site URL', name: 'siteURL', type: 'string', hint: "The absolute URL of the Infisical instance. Change it only if you're self-hosting Infisical.", required: true, noDataExpression: true, placeholder: 'https://app.infisical.com', default: 'https://app.infisical.com', }, ]; this.displayName = 'Infisical'; this.name = 'infisical'; this.cachedSecrets = {}; } async init(settings) { this.settings = settings.settings; } async update() { if (!this.client) { throw new n8n_workflow_1.UnexpectedError('Updated attempted on Infisical when initialization failed'); } if (!(await this.test())[0]) { throw new n8n_workflow_1.UnexpectedError('Infisical provider test failed during update'); } const secrets = (await this.client.getAllSecrets({ environment: this.environment, path: '/', attachToProcessEnv: false, includeImports: true, })); const newCache = Object.fromEntries(secrets.map((s) => [s.secretName, s.secretValue])); if (Object.keys(newCache).length === 1 && '' in newCache) { this.cachedSecrets = {}; } else { this.cachedSecrets = newCache; } } async doConnect() { const { default: InfisicalClientClass } = await Promise.resolve().then(() => __importStar(require('infisical-node'))); this.client = new InfisicalClientClass(this.settings); const [testSuccess] = await this.test(); if (!testSuccess) { throw new Error('Connection test failed'); } this.environment = await this.getEnvironment(); } async getEnvironment() { const { getServiceTokenData } = await Promise.resolve().then(() => __importStar(require('infisical-node/lib/api/serviceTokenData'))); const serviceTokenData = (await getServiceTokenData(this.client.clientConfig)); if (serviceTokenData.environment) { return serviceTokenData.environment; } if (serviceTokenData.scopes) { return serviceTokenData.scopes[0].environment; } throw new n8n_workflow_1.UnexpectedError("Couldn't find environment for Infisical"); } async test() { if (!this.client) { return [false, 'Client not initialized']; } try { const { populateClientWorkspaceConfigsHelper } = await Promise.resolve().then(() => __importStar(require('infisical-node/lib/helpers/key'))); await populateClientWorkspaceConfigsHelper(this.client.clientConfig); return [true]; } catch (e) { return [false]; } } async disconnect() { } getSecret(name) { return this.cachedSecrets[name]; } getSecretNames() { return Object.keys(this.cachedSecrets); } hasSecret(name) { return name in this.cachedSecrets; } } exports.InfisicalProvider = InfisicalProvider; //# sourceMappingURL=infisical.js.map