-
Notifications
You must be signed in to change notification settings - Fork 1
/
components.js
52 lines (46 loc) · 1.48 KB
/
components.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use strict";
const option = require("commons/option");
const bunyan = require("bunyan");
const sendgrid = require("sendgrid");
function init() {
return option().config.then(config => {
for (let key in config) {
if (process.env[`egf_${key}`]) {
try {
config[key] = JSON.parse(process.env[`egf_${key}`]);
} catch (e) {
config[key] = process.env[`egf_${key}`];
}
}
}
const log = bunyan.createLogger({
name: "pusher",
level: config.log_level
});
log.info({config});
module.exports.config = config;
let cd = require("commons/client-data")(config["client-data"]);
module.exports.clientData = cd;
module.exports.logger = log;
let promises = [];
if (config.email_transport === "sendgrid") {
let sg = cd.getGraphConfig().then(conf =>
cd.getObject(conf.objects.secret_organization)
.then(secret => {
let apiKey = secret.secret_keys.find(item => item.key === "sendgrid_api_key");
module.exports.sendgrid = sendgrid(apiKey.value);
})
);
promises.push(sg);
}
return Promise.all(promises);
})
.then(() => module.exports)
.catch(err => {
console.log(err);
process.exit(1);
});
}
module.exports = {
init
};