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

@ -8,10 +8,9 @@ const _ = require('lodash');
const debuglogs = require('./modules/debuglogs');
const Errors = require('./modules/types/errors');
const Privacy = require('./modules/privacy');
const ipc = electron.ipcRenderer;
const PHONE_REGEX = /\+\d{7,12}(\d{3})/g;
const GROUP_REGEX = /(group\()([^)]+)(\))/g;
// Default Bunyan levels: https://github.com/trentm/node-bunyan#levels
// To make it easier to visually scan logs, we make all levels the same length
@ -25,20 +24,7 @@ const LEVELS = {
10: 'trace',
};
// Backwards-compatible logging, simple strings and no level (defaulted to INFO)
function redactPhone(text) {
return text.replace(PHONE_REGEX, '+[REDACTED]$1');
}
function redactGroup(text) {
return text.replace(
GROUP_REGEX,
(match, before, id, after) => `${before}[REDACTED]${id.slice(-3)}${after}`
);
}
function now() {
const date = new Date();
return date.toJSON();
@ -61,8 +47,8 @@ function log(...args) {
return item;
});
const toSend = redactAll(str.join(' '));
ipc.send('log-info', toSend);
const logText = Privacy.redactAll(str.join(' '));
ipc.send('log-info', logText);
}
if (window.console) {
@ -96,11 +82,7 @@ function formatLine(entry) {
}
function format(entries) {
return redactAll(entries.map(formatLine).join('\n')));
}
function redactAll(string) {
return Errors.redactSensitivePaths(redactGroup(redactPhone(string)));
return Privacy.redactAll(entries.map(formatLine).join('\n'));
}
function fetch() {