let fs = require('fs'); let { logger } = require('./logging'); let loadedConfigs = new Map(); function sanitizeConfig(config, fields=[]) { let clonedConfig = { ...config }; fields.forEach((field) => { clonedConfig[field] = '******' }) return clonedConfig; } function getConfig(configFile, sanitizedFields=[], reload=false) { if (loadedConfigs.has(configFile) && !reload) { return loadedConfigs.get(configFile); } else { logger.info("Reading config: %s", configFile); let rawConfigData = fs.readFileSync(configFile); let config = JSON.parse(rawConfigData); logger.info("Loaded config: %s", configFile); logger.debug("%o", sanitizeConfig(config, sanitizedFields)); loadedConfigs.set(configFile, config); return config; } } exports.getConfig = getConfig