n8n
Version:
n8n Workflow Automation Tool
169 lines • 7.91 kB
JavaScript
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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTrackingInformationFromPostPushResult = exports.getTrackingInformationFromPrePushResult = exports.getTrackingInformationFromPullResult = exports.getRepoType = exports.generateSshKeyPair = exports.isSourceControlLicensed = exports.sourceControlFoldersExistCheck = exports.getTagsPath = exports.getVariablesPath = exports.getCredentialExportPath = exports.getWorkflowExportPath = exports.stringContainsExpression = void 0;
const typedi_1 = require("typedi");
const License_1 = require("../../License");
const crypto_1 = require("crypto");
const fs_1 = require("fs");
const constants_1 = require("./constants");
const path_1 = __importDefault(require("path"));
const Logger_1 = require("../../Logger");
function stringContainsExpression(testString) {
return /^=.*\{\{.*\}\}/.test(testString);
}
exports.stringContainsExpression = stringContainsExpression;
function getWorkflowExportPath(workflowId, workflowExportFolder) {
return path_1.default.join(workflowExportFolder, `${workflowId}.json`);
}
exports.getWorkflowExportPath = getWorkflowExportPath;
function getCredentialExportPath(credentialId, credentialExportFolder) {
return path_1.default.join(credentialExportFolder, `${credentialId}.json`);
}
exports.getCredentialExportPath = getCredentialExportPath;
function getVariablesPath(gitFolder) {
return path_1.default.join(gitFolder, constants_1.SOURCE_CONTROL_VARIABLES_EXPORT_FILE);
}
exports.getVariablesPath = getVariablesPath;
function getTagsPath(gitFolder) {
return path_1.default.join(gitFolder, constants_1.SOURCE_CONTROL_TAGS_EXPORT_FILE);
}
exports.getTagsPath = getTagsPath;
function sourceControlFoldersExistCheck(folders, createIfNotExists = true) {
let existed = true;
folders.forEach((folder) => {
try {
(0, fs_1.accessSync)(folder, fs_1.constants.F_OK);
}
catch {
existed = false;
if (createIfNotExists) {
try {
(0, fs_1.mkdirSync)(folder, { recursive: true });
}
catch (error) {
typedi_1.Container.get(Logger_1.Logger).error(error.message);
}
}
}
});
return existed;
}
exports.sourceControlFoldersExistCheck = sourceControlFoldersExistCheck;
function isSourceControlLicensed() {
const license = typedi_1.Container.get(License_1.License);
return license.isSourceControlLicensed();
}
exports.isSourceControlLicensed = isSourceControlLicensed;
async function generateSshKeyPair(keyType) {
const sshpk = await Promise.resolve().then(() => __importStar(require('sshpk')));
const keyPair = {
publicKey: '',
privateKey: '',
};
let generatedKeyPair;
switch (keyType) {
case 'ed25519':
generatedKeyPair = (0, crypto_1.generateKeyPairSync)('ed25519', {
privateKeyEncoding: { format: 'pem', type: 'pkcs8' },
publicKeyEncoding: { format: 'pem', type: 'spki' },
});
break;
case 'rsa':
generatedKeyPair = (0, crypto_1.generateKeyPairSync)('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
},
});
break;
}
const keyPublic = sshpk.parseKey(generatedKeyPair.publicKey, 'pem');
keyPublic.comment = constants_1.SOURCE_CONTROL_GIT_KEY_COMMENT;
keyPair.publicKey = keyPublic.toString('ssh');
const keyPrivate = sshpk.parsePrivateKey(generatedKeyPair.privateKey, 'pem');
keyPrivate.comment = constants_1.SOURCE_CONTROL_GIT_KEY_COMMENT;
keyPair.privateKey = keyPrivate.toString('ssh-private');
return {
privateKey: keyPair.privateKey,
publicKey: keyPair.publicKey,
};
}
exports.generateSshKeyPair = generateSshKeyPair;
function getRepoType(repoUrl) {
if (repoUrl.includes('github.com')) {
return 'github';
}
else if (repoUrl.includes('gitlab.com')) {
return 'gitlab';
}
return 'other';
}
exports.getRepoType = getRepoType;
function filterSourceControlledFilesUniqueIds(files) {
return (files.filter((file, index, self) => {
return self.findIndex((f) => f.id === file.id) === index;
}) || []);
}
function getTrackingInformationFromPullResult(result) {
const uniques = filterSourceControlledFilesUniqueIds(result);
return {
cred_conflicts: uniques.filter((file) => file.type === 'credential' && file.status === 'modified' && file.location === 'local').length,
workflow_conflicts: uniques.filter((file) => file.type === 'workflow' && file.status === 'modified' && file.location === 'local').length,
workflow_updates: uniques.filter((file) => file.type === 'workflow').length,
};
}
exports.getTrackingInformationFromPullResult = getTrackingInformationFromPullResult;
function getTrackingInformationFromPrePushResult(result) {
const uniques = filterSourceControlledFilesUniqueIds(result);
return {
workflows_eligible: uniques.filter((file) => file.type === 'workflow').length,
workflows_eligible_with_conflicts: uniques.filter((file) => file.type === 'workflow' && file.conflict).length,
creds_eligible: uniques.filter((file) => file.type === 'credential').length,
creds_eligible_with_conflicts: uniques.filter((file) => file.type === 'credential' && file.conflict).length,
variables_eligible: uniques.filter((file) => file.type === 'variables').length,
};
}
exports.getTrackingInformationFromPrePushResult = getTrackingInformationFromPrePushResult;
function getTrackingInformationFromPostPushResult(result) {
var _a, _b, _c, _d;
const uniques = filterSourceControlledFilesUniqueIds(result);
return {
workflows_pushed: (_a = uniques.filter((file) => file.pushed && file.type === 'workflow').length) !== null && _a !== void 0 ? _a : 0,
workflows_eligible: (_b = uniques.filter((file) => file.type === 'workflow').length) !== null && _b !== void 0 ? _b : 0,
creds_pushed: (_c = uniques.filter((file) => file.pushed && file.file.startsWith('credential_stubs')).length) !== null && _c !== void 0 ? _c : 0,
variables_pushed: (_d = uniques.filter((file) => file.pushed && file.file.startsWith('variable_stubs')).length) !== null && _d !== void 0 ? _d : 0,
};
}
exports.getTrackingInformationFromPostPushResult = getTrackingInformationFromPostPushResult;
//# sourceMappingURL=sourceControlHelper.ee.js.map
;