Extract Privacy module

Centralizes how we redact sensitive information.
This commit is contained in:
Daniel Gasienica
2018-03-06 16:20:04 -05:00
parent 0c317c5498
commit 49e0850fb2
4 changed files with 60 additions and 42 deletions

View File

@@ -1,26 +1,9 @@
/* eslint-env node */
const Path = require('path');
const ensureError = require('ensure-error');
const isString = require('lodash/isString');
const APP_ROOT_PATH = Path.join(__dirname, '..', '..', '..');
const APP_ROOT_PATH_PATTERN = new RegExp(APP_ROOT_PATH, 'g');
const Privacy = require('../privacy');
// toLogFormat :: Error -> String
exports.toLogFormat = (error) => {
const normalizedError = ensureError(error);
const stackWithRedactedPaths = exports.redactSensitivePaths(normalizedError.stack);
return stackWithRedactedPaths;
};
// redactSensitivePaths :: String -> String
exports.redactSensitivePaths = (logLine) => {
if (!isString(logLine)) {
return logLine;
}
return logLine.replace(APP_ROOT_PATH_PATTERN, '<REDACTED_PATH>');
return Privacy.redactAll(normalizedError.stack);
};