2019-10-13 03:38:25 +02:00
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*
|
|
|
|
* Handle configuration file
|
|
|
|
*
|
|
|
|
* @file This files defines the configuration
|
|
|
|
* @author nioc
|
|
|
|
* @since 1.0.0
|
|
|
|
* @license AGPL-3.0+
|
|
|
|
*/
|
|
|
|
|
2019-10-20 01:07:10 +02:00
|
|
|
module.exports = function Configuration (logger, configPath = null) {
|
2019-10-13 03:38:25 +02:00
|
|
|
let config
|
2019-10-20 01:07:10 +02:00
|
|
|
if (configPath === null) {
|
|
|
|
configPath = './lib/config/config.json'
|
|
|
|
}
|
2019-10-13 03:38:25 +02:00
|
|
|
try {
|
2019-10-20 01:07:10 +02:00
|
|
|
let data = require('fs').readFileSync(configPath)
|
2019-10-13 03:38:25 +02:00
|
|
|
config = JSON.parse(data)
|
|
|
|
} catch (error) {
|
2019-10-20 01:07:10 +02:00
|
|
|
logger.fatal(`Invalid configuration file: ${error.message}, current directory is: ${process.cwd()}`)
|
2019-10-13 03:38:25 +02:00
|
|
|
process.exit(99)
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
listener: {
|
|
|
|
path: config.webhooksListener.path,
|
|
|
|
port: config.webhooksListener.port,
|
|
|
|
ssl: config.webhooksListener.ssl,
|
|
|
|
log: config.webhooksListener.accessLog,
|
|
|
|
users: config.webhooksListener.users.reduce((acc, user) => {
|
|
|
|
acc[user.login] = user.password
|
|
|
|
return acc
|
|
|
|
}, {})
|
|
|
|
},
|
|
|
|
xmpp: config.xmppServer,
|
|
|
|
logger: config.logger,
|
|
|
|
getWebhookAction: (path) => {
|
|
|
|
return config.incomingWebhooks.find((webhook) => {
|
|
|
|
return (webhook.path === path)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getOutgoingWebhook: (code) => {
|
|
|
|
return config.outgoingWebhooks.find((webhook) => {
|
|
|
|
return (webhook.code === code)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getXmppHookAction: (room) => {
|
|
|
|
return config.xmppHooks.find((xmppHook) => {
|
|
|
|
return (xmppHook.room === room)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|