Baphomet is the dedicated bot for nulloctet matrix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
830 B

  1. let fs = require('fs');
  2. let { logger } = require('./logging');
  3. let loadedConfigs = new Map();
  4. function sanitizeConfig(config, fields=[]) {
  5. let clonedConfig = { ...config };
  6. fields.forEach((field) => {
  7. clonedConfig[field] = '******'
  8. })
  9. return clonedConfig;
  10. }
  11. function getConfig(configFile, sanitizedFields=[]) {
  12. if (!loadedConfigs.has(configFile)) {
  13. logger.info("Reading config: %s", configFile);
  14. let rawConfigData = fs.readFileSync(configFile);
  15. let config = JSON.parse(rawConfigData);
  16. logger.info("Loaded config: %s", configFile);
  17. logger.debug("%o", sanitizeConfig(config, sanitizedFields));
  18. loadedConfigs.set(configFile, config);
  19. return config;
  20. } else {
  21. return loadedConfigs.get(configFile);
  22. }
  23. }
  24. exports.getConfig = getConfig