Fixing Edge Cases
- Add ability to specify filters from CLI options - Add test and fix for removing branch with censor - Add change regex to use strings
This commit is contained in:
parent
d47481f9ef
commit
3902c380cd
|
@ -61,7 +61,7 @@ module.exports = Joi.object({
|
||||||
|
|
||||||
events: Joi.any().default({}),
|
events: Joi.any().default({}),
|
||||||
dest: Joi.string().default('stdout'),
|
dest: Joi.string().default('stdout'),
|
||||||
|
filter: Joi.any().default({}),
|
||||||
json: Joi.boolean()
|
json: Joi.boolean()
|
||||||
.when('dest', {
|
.when('dest', {
|
||||||
is: 'stdout',
|
is: 'stdout',
|
||||||
|
|
|
@ -29,6 +29,14 @@ describe('applyFilterToKey(obj, key, action)', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should remove an entire branch with censor', function () {
|
||||||
|
var data = fixture();
|
||||||
|
applyFilterToKey(data, 'headers', 'censor');
|
||||||
|
expect(data).to.eql({
|
||||||
|
req: { }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should censor a key in an object recursivly', function () {
|
it('should censor a key in an object recursivly', function () {
|
||||||
var data = fixture();
|
var data = fixture();
|
||||||
applyFilterToKey(data, 'authorization', 'censor');
|
applyFilterToKey(data, 'authorization', 'censor');
|
||||||
|
@ -43,7 +51,7 @@ describe('applyFilterToKey(obj, key, action)', function () {
|
||||||
|
|
||||||
it('should censor key with a RegEx in an object recursivly', function () {
|
it('should censor key with a RegEx in an object recursivly', function () {
|
||||||
var data = fixture();
|
var data = fixture();
|
||||||
var regex = /([^\s]+)$/;
|
var regex = '/([^\\s]+)$/';
|
||||||
applyFilterToKey(data, 'authorization', regex);
|
applyFilterToKey(data, 'authorization', regex);
|
||||||
expect(data).to.eql({
|
expect(data).to.eql({
|
||||||
req: {
|
req: {
|
||||||
|
|
|
@ -7,13 +7,23 @@ module.exports = function applyFilterToKey(obj, key, action) {
|
||||||
if (obj.hasOwnProperty(k)) {
|
if (obj.hasOwnProperty(k)) {
|
||||||
let val = obj[k];
|
let val = obj[k];
|
||||||
if (k === key) {
|
if (k === key) {
|
||||||
val = '' + val;
|
if (action === 'remove') {
|
||||||
if (action === 'remove') delete obj[k];
|
delete obj[k];
|
||||||
if (action === 'censor') {
|
}
|
||||||
obj[k] = val.replace(/./g, 'X');
|
else if (action === 'censor' && typeof val === 'object') {
|
||||||
};
|
delete obj[key];
|
||||||
if (action instanceof RegExp) {
|
}
|
||||||
obj[k] = val.replace(action, replacer);
|
else if (action === 'censor') {
|
||||||
|
obj[k] = ('' + val).replace(/./g, 'X');
|
||||||
|
}
|
||||||
|
else if (/\/.+\//.test(action)) {
|
||||||
|
var matches = action.match(/\/(.+)\//);
|
||||||
|
try {
|
||||||
|
let regex = new RegExp(matches[1]);
|
||||||
|
obj[k] = ('' + val).replace(regex, replacer);
|
||||||
|
} catch (e) {
|
||||||
|
//meh
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (typeof val === 'object') {
|
} else if (typeof val === 'object') {
|
||||||
applyFilterToKey(val, key, action);
|
applyFilterToKey(val, key, action);
|
||||||
|
|
|
@ -43,9 +43,13 @@ module.exports = function (kbnServer, server, config) {
|
||||||
config: {
|
config: {
|
||||||
json: config.get('logging.json'),
|
json: config.get('logging.json'),
|
||||||
dest: config.get('logging.dest'),
|
dest: config.get('logging.dest'),
|
||||||
filter: {
|
// I'm adding the default here because if you add another filter
|
||||||
|
// using the commandline it will remove authorization. I want users
|
||||||
|
// to have to explicitly set --logging.filter.authorization=none to
|
||||||
|
// have it show up int he logs.
|
||||||
|
filter: _.defaults(config.get('logging.filter'), {
|
||||||
authorization: 'remove'
|
authorization: 'remove'
|
||||||
}
|
})
|
||||||
},
|
},
|
||||||
events: _.transform(events, function (filtered, val, key) {
|
events: _.transform(events, function (filtered, val, key) {
|
||||||
// provide a string compatible way to remove events
|
// provide a string compatible way to remove events
|
||||||
|
|
Loading…
Reference in a new issue