1 | const {escapeRegExp, size, isString} = require('lodash');
|
2 | const {SECRET_REPLACEMENT, SECRET_MIN_SIZE} = require('./definitions/constants');
|
3 |
|
4 | module.exports = env => {
|
5 | const toReplace = Object.keys(env).filter(
|
6 | envVar => /token|password|credential|secret|private/i.test(envVar) && size(env[envVar].trim()) >= SECRET_MIN_SIZE
|
7 | );
|
8 |
|
9 | const regexp = new RegExp(toReplace.map(envVar => escapeRegExp(env[envVar])).join('|'), 'g');
|
10 | return output =>
|
11 | output && isString(output) && toReplace.length > 0 ? output.toString().replace(regexp, SECRET_REPLACEMENT) : output;
|
12 | };
|