Skip to content
Snippets Groups Projects
Commit 9fc83cd1 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

Redact token in logs

commit e6ca456e63f9f42089275ceb14e42442d8cbe8eb
Author: Rhys Arkins <rhys@keylocation.sg>
Date:   Wed Jan 18 14:11:53 2017 +0100

    Redact string

commit 154367927f60a895708ef0f83192342bbf7a4093
Author: Rhys Arkins <rhys@keylocation.sg>
Date:   Wed Jan 18 14:02:12 2017 +0100

    Redact config
parent 837deecb
No related branches found
No related tags found
No related merge requests found
const logger = require('winston'); const logger = require('winston');
const program = require('commander'); const program = require('commander');
const stringify = require('json-stringify-pretty-compact');
let config = null; let config = null;
...@@ -14,14 +15,14 @@ function parseConfigs() { ...@@ -14,14 +15,14 @@ function parseConfigs() {
const envConfig = require('./env'); const envConfig = require('./env');
/* eslint-enable global-require */ /* eslint-enable global-require */
logger.debug(`Default config = ${JSON.stringify(defaultConfig)}`); logger.debug(`Default config = ${redact(defaultConfig)}`);
logger.debug(`File config = ${JSON.stringify(fileConfig)}`); logger.debug(`File config = ${redact(fileConfig)}`);
logger.debug(`CLI config: ${JSON.stringify(cliConfig)}`); logger.debug(`CLI config: ${redact(cliConfig)}`);
logger.debug(`Env config: ${JSON.stringify(envConfig)}`); logger.debug(`Env config: ${redact(envConfig)}`);
// Get global config // Get global config
config = Object.assign({}, defaultConfig, fileConfig, envConfig, cliConfig); config = Object.assign({}, defaultConfig, fileConfig, envConfig, cliConfig);
logger.debug(`raw config=${JSON.stringify(config)}`); logger.debug(`raw config=${redact(config)}`);
// Set log level // Set log level
logger.level = config.logLevel; logger.level = config.logLevel;
...@@ -63,7 +64,7 @@ function parseConfigs() { ...@@ -63,7 +64,7 @@ function parseConfigs() {
}); });
}); });
// Print config // Print config
logger.verbose(`config=${JSON.stringify(config)}`); logger.verbose(`config=${redact(config)}`);
} }
function getCascadedConfig(repo, packageFile) { function getCascadedConfig(repo, packageFile) {
...@@ -81,6 +82,15 @@ function getGlobalConfig() { ...@@ -81,6 +82,15 @@ function getGlobalConfig() {
return config; return config;
} }
function redact(inputConfig) {
const tokenConfig = {};
if (inputConfig.token) {
tokenConfig.token = `${inputConfig.token.substr(0, 4)}${new Array(inputConfig.token.length - 3).join('*')}`;
}
const redactedConfig = Object.assign({}, inputConfig, tokenConfig);
return stringify(redactedConfig);
}
module.exports = { module.exports = {
getCascadedConfig, getCascadedConfig,
getGlobalConfig, getGlobalConfig,
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
"gh-got": "5.0.0", "gh-got": "5.0.0",
"got": "6.7.1", "got": "6.7.1",
"handlebars": "4.0.6", "handlebars": "4.0.6",
"json-stringify-pretty-compact": "^1.0.2",
"lodash": "4.17.4", "lodash": "4.17.4",
"semver": "5.3.0", "semver": "5.3.0",
"semver-stable": "2.0.4", "semver-stable": "2.0.4",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment