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.

28 lines
902 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 = [], reload = false) {
  12. if (loadedConfigs.has(configFile) && !reload) {
  13. return loadedConfigs.get(configFile);
  14. } else {
  15. logger.info("Reading config: %s", configFile);
  16. let rawConfigData = fs.readFileSync(configFile);
  17. let config = JSON.parse(rawConfigData);
  18. logger.info("Loaded config: %s", configFile);
  19. logger.debug("%o", sanitizeConfig(config, sanitizedFields));
  20. loadedConfigs.set(configFile, config);
  21. return config;
  22. }
  23. }
  24. exports.getConfig = getConfig;
  25. exports.sanitizeConfig = sanitizeConfig;