forked from CBIIT/bento-files
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.js
127 lines (119 loc) · 3.75 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const { removeTrailingSlashes } = require('./utils');
const fs = require('fs');
const dotenv = require('dotenv')
dotenv.config();
const DEFAULT_EXPIRATION_SECONDS = 60 * 60 * 24; // 24 hours
const INDEXD = 'INDEXD';
const CLOUD_FRONT = 'CLOUD_FRONT';
const LOCAL = 'LOCAL';
const PUBLIC_S3 = 'PUBLIC_S3';
const SIGNED_S3 = 'SIGNED_S3';
const DUMMY = 'DUMMY';
const ICDC = 'ICDC';
const BENTO = 'BENTO';
const GMB = 'GMB';
const C3DC = 'C3DC';
const CTDC = 'CTDC';
const CDS = 'CDS';
const DCF = 'DCF';
const config = {
projectNames: {
ICDC,
BENTO,
GMB,
C3DC,
CTDC,
CDS
},
sourceNames: {
INDEXD,
CLOUD_FRONT,
LOCAL,
PUBLIC_S3,
SIGNED_S3,
DUMMY,
DCF,
},
source: 'DCF',
fake: process.env.FAKE ? (process.env.FAKE.toLowerCase() === 'true') : false, // This is used to fake CloudFront call locally
backendUrl: removeTrailingSlashes(process.env.BACKEND_URL),
authorizationEnabled: process.env.AUTHORIZATION_ENABLED ? process.env.AUTHORIZATION_ENABLED.toLowerCase() === 'true' : false,
authEnabled: process.env.AUTH_ENABLED ? process.env.AUTH_ENABLED.toLowerCase() === 'true' : false,
authUrl: process.env.AUTH_URL ? (process.env.AUTH_URL.toLowerCase() === 'null' ? null : process.env.AUTH_URL) : null,
version: process.env.VERSION,
date: process.env.DATE,
project: (process.env.PROJECT || BENTO).toUpperCase(),
// MySQL Session
mysqlSessionEnabled: process.env.MYSQL_SESSION_ENABLED ? process.env.MYSQL_SESSION_ENABLED.toLowerCase() === 'true' : false,
mysql_host: process.env.MYSQL_HOST,
mysql_port: process.env.MYSQL_PORT,
mysql_user: process.env.MYSQL_USER,
mysql_password: process.env.MYSQL_PASSWORD,
mysql_database: process.env.MYSQL_DATABASE,
session_timeout: process.env.SESSION_TIMEOUT ? parseInt(process.env.SESSION_TIMEOUT) * 1000 : 1000 * 30 * 60, // 30 minutes
cookie_secret: process.env.COOKIE_SECRET,
// Neo4j Connection
neo4j_uri: process.env.NEO4J_URI,
neo4j_user: process.env.NEO4J_USER,
neo4j_password: process.env.NEO4J_PASSWORD,
};
if (!config.version) {
config.version = 'Version not set'
}
if (!config.date) {
config.date = new Date();
}
// Make sure when authentication is enabled, authUrl is also set
if (config.authEnabled && (!config.authUrl || !config.authUrl.startsWith('http'))) {
throw `Invalid auth URL: ${config.authUrl}`;
}
function readPrivateKey(keyPath) {
return fs.readFileSync(keyPath, 'utf8');
}
switch (config.source) {
case DCF:
config.DCF_File_URL = removeTrailingSlashes(process.env.DCF_FILE_URL);
if (!config.DCF_File_URL) {
throw "DCF_File_URL is not set!";
}
break;
case INDEXD:
config.indexDUrl = removeTrailingSlashes(process.env.INDEXD_URL);
if (!config.indexDUrl) {
throw "INDEXD_URL is not set!";
}
break;
case CLOUD_FRONT:
config.cfUrl = removeTrailingSlashes(process.env.CF_URL);
config.cfKeyPairId = process.env.CF_KEY_PAIR_ID;
config.cfPrivateKey = process.env.CF_PRIVATE_KEY;
config.urlExpiresInSeconds = process.env.URL_EXPIRES_IN_SECONDS || DEFAULT_EXPIRATION_SECONDS
if (!config.cfUrl) {
throw "CF_URL is not set!";
}
if (!config.cfKeyPairId) {
throw "CF_KEY_PAIR_ID is not set!";
}
if (!config.cfPrivateKey) {
throw "CF_PRIVATE_KEY is not set!";
}
if (!config.backendUrl) {
throw 'BACKEND_URL is not set!';
}
break;
case SIGNED_S3:
// config.region = process.env.REGION || 'us-east-1';
config.urlExpiresInSeconds = process.env.URL_EXPIRES_IN_SECONDS || DEFAULT_EXPIRATION_SECONDS
break;
case LOCAL:
// Todo: add local support here
break;
case PUBLIC_S3:
// Todo: add public S3 support here
break;
case DUMMY:
break;
default:
throw `Unknown Source: '${config.source}'`;
}
module.exports = config;