@qiwi/uniconfig-core
Advanced tools
Comparing version 3.4.0 to 3.5.0
@@ -0,1 +1,8 @@ | ||
# [@qiwi/uniconfig-core-v3.5.0](https://github.com/qiwi/uniconfig/compare/v3.4.0...v3.5.0) (2020-05-28) | ||
### Features | ||
* add masking for creds ([36187b0](https://github.com/qiwi/uniconfig/commit/36187b025c8baa9c842239361a0f215ed86d9bbe)) | ||
# [@qiwi/uniconfig-core-v3.4.0](https://github.com/qiwi/uniconfig/compare/v3.3.1...v3.4.0) (2020-05-21) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@qiwi/uniconfig-core", | ||
"version": "3.4.0", | ||
"version": "3.5.0", | ||
"description": "Core uniconfig library", | ||
@@ -5,0 +5,0 @@ "main": "target/es5/index.js", |
@@ -5,1 +5,3 @@ import { isNode, isBrowser } from 'browser-or-node'; | ||
export declare const echo: (data: any) => any; | ||
export declare const deepMap: (input: any, cb: Function, key?: string | undefined, path?: string | undefined, target?: any, refs?: WeakMap<object, any>) => any; | ||
export declare const secretMasker: (input: any) => any; |
@@ -14,2 +14,43 @@ "use strict"; | ||
exports.echo = function (data) { return data; }; | ||
var getSameTypeOfObject = function (input) { return Array.isArray(input) ? [] : {}; }; | ||
exports.deepMap = function (input, cb, key, path, target, refs) { | ||
if (target === void 0) { target = input; } | ||
if (refs === void 0) { refs = new WeakMap(); } | ||
if (typeof cb !== 'function') { | ||
return input; | ||
} | ||
if (typeof input !== 'object' || input === null) { | ||
return cb(input, key, target, path); | ||
} | ||
var ref = refs.get(input); | ||
if (ref) { | ||
return ref; | ||
} | ||
var acc = getSameTypeOfObject(input); | ||
refs.set(input, acc); | ||
Object.keys(input).forEach(function (key) { | ||
// @ts-ignore | ||
acc[key] = exports.deepMap(input[key], cb, key, (path ? path + '.' : '') + key, input, refs); | ||
}); | ||
return acc; | ||
}; | ||
var maskerFn = function (value, _key, _target, path) { | ||
var list = [ | ||
'secret', | ||
'password', | ||
'token', | ||
'cred', | ||
'credentials', | ||
'pass', | ||
]; | ||
if (path === undefined) { | ||
return value; | ||
} | ||
var chunks = path.split('.'); | ||
if (chunks.some(function (r) { return list.some(function (el) { return r.includes(el); }); })) { | ||
return !value ? '***** (empty)' : '*****'; | ||
} | ||
return value; | ||
}; | ||
exports.secretMasker = function (input) { return exports.deepMap(input, maskerFn); }; | ||
//# sourceMappingURL=util.js.map |
@@ -23,3 +23,3 @@ export declare type IAny = any; | ||
}; | ||
export declare type IInject = IInjectRule | string; | ||
export declare type IInject = IInjectRule | string | object; | ||
export declare type IInjectsMap = { | ||
@@ -26,0 +26,0 @@ [key: string]: IInject; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var handleException = function (e, name, data, opts) { | ||
console.error('Pipe exec failure', 'name=', name, 'data=', data, 'opts=', opts); | ||
console.error('Pipe exec failure', 'name=', name, 'data=', util_1.secretMasker(data), 'opts=', util_1.secretMasker(opts)); | ||
console.error(e); | ||
@@ -20,0 +20,0 @@ throw e; |
@@ -5,1 +5,3 @@ import { isNode, isBrowser } from 'browser-or-node'; | ||
export declare const echo: (data: any) => any; | ||
export declare const deepMap: (input: any, cb: Function, key?: string | undefined, path?: string | undefined, target?: any, refs?: WeakMap<object, any>) => any; | ||
export declare const secretMasker: (input: any) => any; |
@@ -5,2 +5,41 @@ import { isNode, isBrowser } from 'browser-or-node'; | ||
export const echo = (data) => data; | ||
const getSameTypeOfObject = (input) => Array.isArray(input) ? [] : {}; | ||
export const deepMap = (input, cb, key, path, target = input, refs = new WeakMap()) => { | ||
if (typeof cb !== 'function') { | ||
return input; | ||
} | ||
if (typeof input !== 'object' || input === null) { | ||
return cb(input, key, target, path); | ||
} | ||
const ref = refs.get(input); | ||
if (ref) { | ||
return ref; | ||
} | ||
const acc = getSameTypeOfObject(input); | ||
refs.set(input, acc); | ||
Object.keys(input).forEach((key) => { | ||
// @ts-ignore | ||
acc[key] = deepMap(input[key], cb, key, (path ? path + '.' : '') + key, input, refs); | ||
}); | ||
return acc; | ||
}; | ||
const maskerFn = (value, _key, _target, path) => { | ||
const list = [ | ||
'secret', | ||
'password', | ||
'token', | ||
'cred', | ||
'credentials', | ||
'pass', | ||
]; | ||
if (path === undefined) { | ||
return value; | ||
} | ||
const chunks = path.split('.'); | ||
if (chunks.some((r) => list.some(el => r.includes(el)))) { | ||
return !value ? '***** (empty)' : '*****'; | ||
} | ||
return value; | ||
}; | ||
export const secretMasker = (input) => deepMap(input, maskerFn); | ||
//# sourceMappingURL=util.js.map |
@@ -23,3 +23,3 @@ export declare type IAny = any; | ||
}; | ||
export declare type IInject = IInjectRule | string; | ||
export declare type IInject = IInjectRule | string | object; | ||
export declare type IInjectsMap = { | ||
@@ -26,0 +26,0 @@ [key: string]: IInject; |
@@ -1,2 +0,2 @@ | ||
import { reduce } from '../base/util'; | ||
import { reduce, secretMasker } from '../base/util'; | ||
export const PIPE_SEPARATOR = /[\s\r\n]*>+[\s\r\n]*/; | ||
@@ -13,3 +13,3 @@ export const DEFAULT_PIPE = { | ||
const handleException = (e, name, data, opts) => { | ||
console.error('Pipe exec failure', 'name=', name, 'data=', data, 'opts=', opts); | ||
console.error('Pipe exec failure', 'name=', name, 'data=', secretMasker(data), 'opts=', secretMasker(opts)); | ||
console.error(e); | ||
@@ -16,0 +16,0 @@ throw e; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
218520
1431