kui-shell
Version:
This is the monorepo for Kui, the hybrid command-line/GUI electron-based Kubernetes tool
34 lines • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = require("debug");
const debug = debug_1.default('k8s/formatters/redact');
const MAX_REDACT_LENGTH = 40;
const pattern = (key) => {
const pat = `(\\s+)(${key}:)(\\s*)([>|][-+]?\\n)?(.+)`;
debug('pat', pat);
return new RegExp(pat, 'g');
};
const patterns = [
pattern('auth'),
pattern('insecure'),
pattern('password'),
pattern('token'),
pattern('user'),
pattern('user_name'),
pattern('username')
];
const keyValueRedactor = (_, precedingWhitespace, key, interstitialWhitespace, maybeContinuation, value) => {
return `${precedingWhitespace}${key}${interstitialWhitespace}${maybeContinuation || ''}${new Array(Math.min(MAX_REDACT_LENGTH, value.length))
.fill('\u2588')
.join('')}`;
};
const redactWithPattern = (str, pattern) => {
return str.replace(pattern, keyValueRedactor);
};
exports.redactYAML = (str) => {
return patterns.reduce(redactWithPattern, str);
};
exports.redactJSON = (obj) => {
return obj;
};
//# sourceMappingURL=redact.js.map