UNPKG

@atomist/automation-client

Version:

Atomist API for software low-level client

109 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mmh3 = require("murmurhash3js"); const uuid = require("uuid/v4"); function hideString(value) { if (!value) { return value; } if (typeof value === "string") { let newValue = ""; for (let i = 0; i < value.length; i++) { if (i === 0) { newValue = value.charAt(0); } else if (i < value.length - 1) { newValue += "*"; } else { newValue += value.slice(-1); } } return newValue; } else if (Array.isArray(value)) { return value.map(hideString); } return value; } exports.hideString = hideString; function guid() { return uuid(); } exports.guid = guid; function findLine(str, idx) { const first = str.substring(0, idx); const last = str.substring(idx); const firstNewLine = first.lastIndexOf("\n"); let secondNewLine = last.indexOf("\n"); if (secondNewLine === -1) { secondNewLine = last.length; } return str.substring(firstNewLine + 1, idx + secondNewLine); } exports.findLine = findLine; function toStringArray(strings) { if (strings) { if (Array.isArray(strings)) { return strings; } else { return [strings]; } } else { return []; } } exports.toStringArray = toStringArray; function obfuscateJson(key, value) { if (key === "keywords") { return value; } else if (/token|password|jwt|url|secret|authorization|key|cert|pass|user/i.test(key)) { return hideString(value); } else if (key === "commands") { return undefined; } else if (key === "events") { return undefined; } else if (key === "ingesters") { return undefined; } else if (key === "listeners") { return undefined; } else if (key === "customizers") { return undefined; } else if (key === "postProcessors") { return undefined; } else if (key === "goal" || key === "goals") { return undefined; } else if (key.startsWith("_")) { return undefined; } return value; } exports.obfuscateJson = obfuscateJson; function replacer(key, value) { if (key === "secrets" && value) { return value.map(v => ({ uri: v.uri, value: hideString(v.value) })); } else if (/token|password|jwt|url|secret|authorization|key|cert|pass|user/i.test(key)) { return hideString(value); } else { return value; } } exports.replacer = replacer; function generateHash(url) { return mmh3.x86.hash32(url); } exports.generateHash = generateHash; //# sourceMappingURL=string.js.map