fix: hide sensitive data in relesae notes and fail/success plugin params

This commit is contained in:
Pierre Vanduynslager
2018-08-27 16:20:36 -04:00
parent 1aed97e577
commit dffe148e33
6 changed files with 128 additions and 13 deletions
+5 -1
View File
@@ -1,5 +1,7 @@
const {isString, isPlainObject} = require('lodash');
const {gitHead} = require('../git');
const hideSensitive = require('../hide-sensitive');
const {hideSensitiveValues} = require('../utils');
const {RELEASE_TYPE, RELEASE_NOTES_SEPARATOR} = require('./constants');
module.exports = {
@@ -40,7 +42,7 @@ module.exports = {
},
}),
}),
postprocess: results => results.filter(Boolean).join(RELEASE_NOTES_SEPARATOR),
postprocess: (results, {env}) => hideSensitive(env)(results.filter(Boolean).join(RELEASE_NOTES_SEPARATOR)),
},
prepare: {
default: ['@semantic-release/npm'],
@@ -80,11 +82,13 @@ module.exports = {
multiple: true,
required: false,
pipelineConfig: () => ({settleAll: true}),
preprocess: ({releases, env, ...inputs}) => ({...inputs, env, releases: hideSensitiveValues(env, releases)}),
},
fail: {
default: ['@semantic-release/github'],
multiple: true,
required: false,
pipelineConfig: () => ({settleAll: true}),
preprocess: ({errors, env, ...inputs}) => ({...inputs, env, errors: hideSensitiveValues(env, errors)}),
},
};
+3 -2
View File
@@ -1,4 +1,4 @@
const {escapeRegExp, size} = require('lodash');
const {escapeRegExp, size, isString} = require('lodash');
const {SECRET_REPLACEMENT, SECRET_MIN_SIZE} = require('./definitions/constants');
module.exports = env => {
@@ -7,5 +7,6 @@ module.exports = env => {
);
const regexp = new RegExp(toReplace.map(envVar => escapeRegExp(env[envVar])).join('|'), 'g');
return output => (output && toReplace.length > 0 ? output.toString().replace(regexp, SECRET_REPLACEMENT) : output);
return output =>
output && isString(output) && toReplace.length > 0 ? output.toString().replace(regexp, SECRET_REPLACEMENT) : output;
};
+4 -1
View File
@@ -36,7 +36,10 @@ module.exports = (context, pluginsPath) => {
);
plugins[type] = async input =>
postprocess(await pipeline(steps, pipelineConfig && pipelineConfig(plugins, logger))(await preprocess(input)));
postprocess(
await pipeline(steps, pipelineConfig && pipelineConfig(plugins, logger))(await preprocess(input)),
input
);
return plugins;
},
+14 -1
View File
@@ -1,7 +1,20 @@
const {isFunction} = require('lodash');
const hideSensitive = require('./hide-sensitive');
function extractErrors(err) {
return err && isFunction(err[Symbol.iterator]) ? [...err] : [err];
}
module.exports = {extractErrors};
function hideSensitiveValues(env, objs) {
const hideFunction = hideSensitive(env);
return objs.map(obj => {
Object.getOwnPropertyNames(obj).forEach(prop => {
if (obj[prop]) {
obj[prop] = hideFunction(obj[prop]);
}
});
return obj;
});
}
module.exports = {extractErrors, hideSensitiveValues};