-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.js
55 lines (51 loc) · 1.69 KB
/
config.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
53
54
55
const dotenv = require("dotenv");
dotenv.config();
const config = {
version: process.env.VERSION,
date: process.env.DATE,
BENTO_BACKEND_GRAPHQL_URI: process.env.BENTO_BACKEND_GRAPHQL_URI,
REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT,
AWS_REGION: process.env.AWS_REGION,
S3_ACCESS_KEY_ID: process.env.S3_ACCESS_KEY_ID,
S3_SECRET_ACCESS_KEY: process.env.S3_SECRET_ACCESS_KEY,
FILE_MANIFEST_BUCKET_NAME: process.env.FILE_MANIFEST_BUCKET_NAME,
CLOUDFRONT_KEY_PAIR_ID: process.env.CLOUDFRONT_KEY_PAIR_ID,
CLOUDFRONT_PRIVATE_KEY: process.env.CLOUDFRONT_PRIVATE_KEY,
CLOUDFRONT_DOMAIN: process.env.CLOUDFRONT_DOMAIN,
SIGNED_URL_EXPIRY_SECONDS: process.env.SIGNED_URL_EXPIRY_SECONDS,
REDIS_AUTH_ENABLED: process.env.REDIS_AUTH_ENABLED,
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
};
function scanConfigObject(configObject) {
if (!configObject.version) {
configObject.version = "Version not set!";
}
if (!configObject.date) {
configObject.date = new Date();
}
unsetVars = [];
let filteredKeys = Object.keys(configObject).filter((key) => {
return !["date", "version"].includes(key);
});
if (
!configObject.REDIS_AUTH_ENABLED ||
configObject.REDIS_AUTH_ENABLED.toLowerCase() !== "true"
) {
filteredKeys = filteredKeys.filter((key) => {
return !["REDIS_AUTH_ENABLED", "REDIS_PASSWORD"].includes(key);
});
}
for (key in filteredKeys) {
if (!configObject[filteredKeys[key]]) {
unsetVars.push(filteredKeys[key]);
}
}
if (unsetVars.length !== 0) {
throw new Error(
`The following environment variables are not set: ${unsetVars.join(", ")}`
);
}
}
scanConfigObject(config);
module.exports = config;