Skip to content

Commit 6135ad0

Browse files
committed
config heirarchical
1 parent eb71afe commit 6135ad0

10 files changed

Lines changed: 117 additions & 109 deletions

File tree

api/auto/autoScale.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const autoScale = async () => {
3333
let database = {};
3434

3535
for (const server of serverList) {
36-
if (server.tags.includes(config.DB_HOST)) {
36+
if (server.tags.includes(config.DB.HOST)) {
3737
database = server;
3838
database.cpus += parseInt(server.specs.vcpus);
3939
database.one = (database.cpus / parseInt(server.loadOne)) * 100;

api/auto/scaleServers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ if (mode === 'show') {
3636

3737
let label = machine.label;
3838

39-
if (label !== config.DB_HOST && label !== config.DB_REPLICA) {
39+
if (label !== config.DB.HOST && label !== config.DB.REPLICA) {
4040
label = `${machine.label}\t`;
4141
}
4242

api/controllers/public/status.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const systemStatus = (req, res) => {
1515
totalmem : os.totalmem(),
1616
node : process.version,
1717
runtime : process.env?.NODE_ENV,
18-
database : config.DB_DATABASE,
18+
database : config.DB.DATABASE,
1919
});
2020
};
2121

api/data/auto.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ import config from '../../config/config.js';
33
import autoConfig from '../../config/sequelize-auto.config.js';
44

55
const auto = new SequelizeAuto(
6-
autoConfig.database || config.DB_DATABASE,
7-
autoConfig.user || config.DB_USER,
8-
autoConfig.pass || config.DB_PASS,
6+
autoConfig.database || config.DB.DATABASE || config.DB_DATABASE,
7+
autoConfig.user || config.DB.USER || config.DB_USER,
8+
autoConfig.pass || config.DB.PASS || config.DB_PASS,
99
{
1010
...autoConfig.options,
11-
host: autoConfig.options?.host || config.DB_HOST,
12-
port: autoConfig.options?.port || config.DB_PORT,
11+
host: autoConfig.options?.host || config.DB.HOST || config.DB_HOST,
12+
port: autoConfig.options?.port || config.DB.PORT || config.DB_PORT,
1313
}
1414
);
15-
console.log('Connecing to database at ' + (autoConfig.options?.host || config.DB_HOST) + ':' + (autoConfig.options?.port || config.DB_PORT) + ' with user ' + (autoConfig.user || config.DB_USER) + '\n');
15+
16+
console.log(`Connecting to database at ${autoConfig.options?.host || config.DB.HOST || config.DB_HOST}:`);
17+
console.log(`${autoConfig.options?.port || config.DB.PORT || config.DB_PORT} with user `);
18+
console.log(`${autoConfig.user || config.DB_USER} \n`);
1619
console.log(`Replacing data models with defintions from ${autoConfig.database || config.DB_DATABASE } \n`);
1720
const results = await auto.run();
1821
console.log(`Models generated for ${ Object.keys(results.tables).length } tables.\n`);

api/data/db.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import config from '../../config/config.js';
44
import initModels from './models/init-models.js';
55

66
// How slow is too slow?
7-
const slowQueryMs = Number(config.SLOW_QUERY_MS || 1000);
7+
const slowQueryMs = Number(config.DB.SLOW_QUERY_MS || 1000);
88

99
const sequelize = new Sequelize(
10-
config.DB_DATABASE,
11-
config.DB_USER,
12-
config.DB_PASS,
10+
config.DB.DATABASE,
11+
config.DB.USER,
12+
config.DB.PASS,
1313
{
14-
...config.sequelizeOptions,
14+
...config.DB.sequelizeOptions,
1515
benchmark: true,
1616
logging: (sql, timingMs) => {
1717
if (typeof timingMs === 'number') {
@@ -20,7 +20,7 @@ const sequelize = new Sequelize(
2020
durationMs: timingMs,
2121
caller: getCallerFrame({ skipContains: ['/node_modules/sequelize/', '/api/data/db.js'] }),
2222
});
23-
} else if (!config.DB_NO_LOGGING) {
23+
} else if (!config.DB.NO_LOGGING) {
2424
logger.debug('SQL query', {
2525
durationMs: timingMs,
2626
caller: getCallerFrame({ skipContains: ['/node_modules/sequelize/', '/api/data/db.js'] }),

api/helpers/admin.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export const adminBlast = async (inputData) => {
88
const messageData = { ...inputData };
99

1010
const transporter = nodemailer.createTransport({
11-
host : config.ADMINMAIL?.SERVER || config.MAIL_SERVER || 'localhost',
12-
port : config.ADMINMAIL?.PORT || config.MAIL_PORT || '25',
13-
secure : config.ADMINMAIL?.SECURE || false,
11+
host : config.MAIL.ADMIN?.SERVER || config.MAIL.SERVER || 'localhost',
12+
port : config.MAIL.ADMIN?.PORT || config.MAIL.PORT || '25',
13+
secure : config.MAIL.ADMIN?.SECURE || false,
1414
pool : true,
15-
maxConnections : config.MAIL_POOL || 64,
15+
maxConnections : config.MAIL.POOL || 64,
1616
maxMessages : 100,
1717
});
1818

@@ -51,16 +51,16 @@ export const adminBlast = async (inputData) => {
5151
messageData.html += 'check off "No Emails", and save</p>';
5252
}
5353

54-
messageData.from = messageData.from ? messageData.from : config.MAIL_FROM;
54+
messageData.from = messageData.from ? messageData.from : config.MAIL.FROM;
5555

5656
const promises = [];
5757

5858
if (messageData.email) {
5959
messageData.to = messageData.email;
6060
if (
6161
process.env.NODE_ENV === 'production'
62-
|| config.MAIL_SERVER === 'mail.in.speechanddebate.org'
63-
|| config.MAIL_TEST
62+
|| config.MAIL.SERVER === 'mail.in.speechanddebate.org'
63+
|| config.MAIL.TEST
6464
) {
6565
const result = transporter.sendMail(messageData);
6666
promises.push(result);

api/helpers/litedb.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import config from '../../config/config.js';
88
// command line scripts outside of the full app.
99

1010
const sequelize = new Sequelize(
11-
config.DB_DATABASE,
12-
config.DB_USER,
13-
config.DB_PASS,
11+
config.DB.DATABASE,
12+
config.DB.USER,
13+
config.DB.PASS,
1414
{
15-
...config.sequelizeOptions,
15+
...config.DB.sequelizeOptions,
1616
logging: false,
1717
}
1818
);

api/helpers/mail.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const emailBlast = async (inputData) => {
1414
if (messageData.share) {
1515

1616
transporter = nodemailer.createTransport({
17-
host : config.SHARE_SMTP_HOST,
17+
host : config.SHARE.SMTP_HOST,
1818
port : 25,
1919
secure : false, // Still allows STARTTLS
2020
pool : true,
@@ -25,16 +25,16 @@ export const emailBlast = async (inputData) => {
2525
rejectUnauthorized : false,
2626
},
2727
auth: {
28-
user: config.SHARE_SMTP_USER,
29-
pass: config.SHARE_SMTP_PASS,
28+
user: config.SHARE.SMTP_USER,
29+
pass: config.SHARE.SMTP_PASS,
3030
},
3131
});
3232

33-
} else if (config.MAIL_TEST) {
33+
} else if (config.MAIL.TEST) {
3434

3535
transporter = nodemailer.createTransport({
36-
host : config.MAIL_SERVER,
37-
port : config.MAIL_PORT,
36+
host : config.MAIL.SERVER,
37+
port : config.MAIL.PORT,
3838
secure : false,
3939
pool : true,
4040
maxConnections : 400,
@@ -48,11 +48,11 @@ export const emailBlast = async (inputData) => {
4848

4949
} else {
5050
transporter = nodemailer.createTransport({
51-
host : config.MAIL_SERVER,
52-
port : config.MAIL_PORT,
51+
host : config.MAIL.SERVER,
52+
port : config.MAIL.PORT,
5353
secure : false,
5454
pool : true,
55-
maxConnections : config.MAIL_POOL || 128,
55+
maxConnections : config.MAIL.POOL || 128,
5656
maxMessages : 'Infinity',
5757
});
5858
}
@@ -73,8 +73,8 @@ export const emailBlast = async (inputData) => {
7373
// etc. And then add the sender as the To as well so it will not deliver.
7474

7575
messageData.bcc = Array.from(new Set(messageData.email));
76-
messageData.to = messageData.to || config.MAIL_FROM;
77-
messageData.from = messageData.from || config.MAIL_FROM;
76+
messageData.to = messageData.to || config.MAIL.FROM;
77+
messageData.from = messageData.from || config.MAIL.FROM;
7878
messageData.replyTo = messageData.replyTo || messageData.from;
7979
messageData.subject = messageData.subject || 'Message from Tab';
8080
messageData.subject = `[TAB] ${messageData.subject}`;
@@ -117,7 +117,7 @@ export const emailBlast = async (inputData) => {
117117

118118
if (
119119
process.env.NODE_ENV === 'production'
120-
|| config.MAIL_TEST
120+
|| config.MAIL.TEST
121121
) {
122122
try {
123123
const result = transporter.sendMail(messageData);

config/config.sample.js

Lines changed: 70 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,40 @@
11

22
export const config = {
3-
LOG_LEVEL : 'info',
4-
HIDE_DEV_ENDPOINTS : true,
5-
PORT : 8001,
6-
RATE_WINDOW : 15 * 60 * 1000,
7-
RATE_MAX : 100000,
8-
RATE_DELAY : 0,
9-
MESSAGE_RATE_MAX : 15 * 1000,
10-
MESSAGE_RATE_WINDOW : 1,
11-
SEARCH_RATE_WINDOW : 30 * 1000,
12-
SEARCH_RATE_MAX : 5,
13-
BASE_URL : 'http://api.dev.tabroom.com',
14-
LOGIN_URL : 'http://mason.dev.tabroom.com/user/login/login.mhtml',
15-
DOCKERHOST : 'devenv',
16-
CODE_PATH : '/www/indexcards',
17-
MAIL_FROM : 'live@www.tabroom.com',
18-
MAIL_SERVER : 'localhost',
19-
MAIL_PORT : 25,
20-
ERROR_DESTINATION : ['errors@tabroom.com'],
21-
LOGIN_TOKEN : 'flurgleflimmer',
22-
JITSI_KEY : 'campus-jitsi-key',
23-
JITSI_URI : 'https://campus.speechanddebate.org',
24-
CASELIST_KEY : 'caselist-key',
25-
SHARE_KEY : 'fd4af7c6f485',
26-
SHARE_SMTP_HOST : '192.168.37.28',
27-
SHARE_SMTP_USER : 'share@share.tabroom.com',
28-
SHARE_SMTP_PASS : 'sharepass',
29-
IPLOCATION : '/var/lib/GeoIP/GeoLite2-City.mmdb',
30-
IPISP : '/var/lib/GeoIP/GeoIP2-ISP.mmdb',
31-
S3_URL : 'https://s3.amazonaws.com/tabroom-files/',
32-
COOKIE_NAME : 'TabroomLocal',
33-
COOKIE_DOMAIN : '.dev.tabroom.com',
34-
SESSION_SHARED : 'random_string',
3+
LOG_LEVEL : 'info',
4+
HIDE_DEV_ENDPOINTS : true,
5+
PORT : 8001,
6+
RATE_WINDOW : 15 * 60 * 1000,
7+
RATE_MAX : 100000,
8+
RATE_DELAY : 0,
9+
MESSAGE_RATE_MAX : 15 * 1000,
10+
MESSAGE_RATE_WINDOW : 1,
11+
SEARCH_RATE_WINDOW : 30 * 1000,
12+
SEARCH_RATE_MAX : 5,
13+
BASE_URL : 'http://api.dev.tabroom.com',
14+
LOGIN_URL : 'http://mason.dev.tabroom.com/user/login/login.mhtml',
15+
DOCKERHOST : 'devenv',
16+
CODE_PATH : '/www/indexcards',
17+
ERROR_DESTINATION : ['errors@tabroom.com'],
18+
JITSI_KEY : 'campus-jitsi-key',
19+
JITSI_URI : 'https://campus.speechanddebate.org',
20+
CASELIST_KEY : 'caselist-key',
21+
SHARE_KEY : 'fd4af7c6f485',
22+
IPLOCATION : '/var/lib/GeoIP/GeoLite2-City.mmdb',
23+
IPISP : '/var/lib/GeoIP/GeoIP2-ISP.mmdb',
24+
S3_URL : 'https://s3.amazonaws.com/tabroom-files/',
25+
COOKIE_NAME : 'TabroomLocal',
26+
COOKIE_DOMAIN : '.dev.tabroom.com',
27+
SESSION_SHARED : 'random_string',
3528
CORS_ORIGINS : ['http://localhost:9000', 'https://localhost:9000'],
3629
CSRF : {
3730
COOKIE_NAME : 'CSRF_Token',
3831
HEADER_NAME : 'x-csrf-token',
3932
},
40-
DB_PORT : '3306',
41-
DB_DATABASE : 'tabroom',
42-
SLOW_QUERY_MS : 1000,
33+
MAIL : {
34+
FROM : 'live@www.tabroom.com',
35+
SERVER : 'localhost',
36+
PORT : 25,
37+
},
4338
NSDA : {
4439
USER_ID : '12345678',
4540
KEY : 'IAmNotAPassword',
@@ -51,37 +46,47 @@ export const config = {
5146
nco : 33333,
5247
},
5348
},
54-
NAUDL : {
55-
USERNAME : 'nope@nopesauce.org',
56-
PW : 'ThisIsAlsoNotAPassword',
57-
TOKEN : 'NotAToken',
58-
CLIENT_SECRET : 'DoNotEvenThinkIt',
59-
CLIENT_ID : 'IDontThinkThisWasSecretButWhyChanceIt',
60-
URL : 'https://urbandebate.my.salesforce.com',
61-
TOURN_ENDPOINT : '/services/apexrest/v.1/TournamentService',
62-
STUDENT_ENDPOINT : '/services/apexrest/v.1/StudentServiceTabroom',
63-
STA_ENDPOINT : '/services/apexrest/v.1/STATabroomService',
49+
SHARE: {
50+
SMTP_HOST : '192.168.37.28',
51+
SMTP_USER : 'share@share.tabroom.com',
52+
SMTP_PASS : 'sharepass',
53+
},
54+
NAUDL : {
55+
USERNAME : 'nope@nopesauce.org',
56+
PW : 'ThisIsAlsoNotAPassword',
57+
TOKEN : 'NotAToken',
58+
CLIENT_SECRET : 'DoNotEvenThinkIt',
59+
CLIENT_ID : 'IDontThinkThisWasSecretButWhyChanceIt',
60+
URL : 'https://urbandebate.my.salesforce.com',
61+
TOURN_ENDPOINT : '/services/apexrest/v.1/TournamentService',
62+
STUDENT_ENDPOINT : '/services/apexrest/v.1/StudentServiceTabroom',
63+
STA_ENDPOINT : '/services/apexrest/v.1/STATabroomService',
6464
},
65-
ONESIGNAL : {
65+
ONESIGNAL : {
6666
API_URL : 'https://onesignal.com/api/v1',
6767
URL : `https://api.onesignal.com/apps/someRandomUUID`,
6868
appId : 'YeahNO',
6969
safariId : 'web.onesignal.auto.nothingmuchtoseeherefolks',
7070
appKey : 'cryHavocAndLetLooseTheDogsofWar!',
7171
},
72-
AWS_CREDENTIALS : {
72+
AWS_CREDENTIALS : {
7373
accessKeyId : 'DefNo',
7474
secretAccessKey : 'DoNotTry',
7575
region : 'us-east-1',
7676
Bucket : 'tabroom-files',
7777
},
78-
sequelizeOptions : {
79-
dialect : 'mariadb',
80-
define : {
81-
freezeTableName : true,
82-
modelName : 'singularName',
83-
underscored : true,
84-
timestamps : false,
78+
DB : {
79+
PORT : '3306',
80+
DATABASE : 'tabroom',
81+
SLOW_QUERY_MS : 1000,
82+
sequelizeOptions : {
83+
dialect : 'mariadb',
84+
define : {
85+
freezeTableName : true,
86+
modelName : 'singularName',
87+
underscored : true,
88+
timestamps : false,
89+
},
8590
},
8691
},
8792
winstonConsoleOptions : {
@@ -102,28 +107,28 @@ const env = process.env.NODE_ENV || 'development';
102107

103108
switch (env) {
104109
case 'staging':
105-
config.DB_HOST = 'localhost';
106-
config.DB_USER = 'tabroom';
107-
config.DB_PASS = '';
110+
config.DB.HOST = 'localhost';
111+
config.DB.USER = 'tabroom';
112+
config.DB.PASS = '';
108113
config.MESSAGE_RATE_MAX = '1000000000';
109114
config.LOG_PATH = '/var/log/indexcards';
110115
config.PROXY_NUMBER = 1;
111116
break;
112117

113118
case 'development':
114-
config.DB_HOST = 'localhost';
115-
config.DB_USER = 'tabroom';
116-
config.DB_PASS = 'lolz',
119+
config.DB.HOST = 'localhost';
120+
config.DB.USER = 'tabroom';
121+
config.DB.PASS = 'lolz',
117122
config.MESSAGE_RATE_MAX = '1000000000';
118-
config.sequelizeOptions.logging = false;
123+
config.DB.sequelizeOptions.logging = false;
119124
config.LOG_PATH = '/var/log/indexcards';
120125
config.PROXY_NUMBER = 0;
121126
break;
122127

123128
case 'test':
124-
config.DB_HOST = 'localhost';
125-
config.DB_USER = 'tabroom';
126-
config.DB_PASS = 'tabroom';
129+
config.DB.HOST = 'localhost';
130+
config.DB.USER = 'tabroom';
131+
config.DB.PASS = 'tabroom';
127132
config.MESSAGE_RATE_MAX = '1000000000';
128133
config.sequelizeOptions.logging = false;
129134
config.MODE = 'test';
@@ -134,7 +139,7 @@ switch (env) {
134139
break;
135140
}
136141

137-
config.sequelizeOptions.host = config.DB_HOST;
142+
config.DB.sequelizeOptions.host = config.DB.HOST;
138143

139144
// Override any config value if corresponding env var is set
140145
const configKeys = Object.keys(config);

0 commit comments

Comments
 (0)