-
Notifications
You must be signed in to change notification settings - Fork 0
/
envTest.mjs
76 lines (57 loc) · 2.12 KB
/
envTest.mjs
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
import fs from 'fs';
import winstonModule from 'winston';
import { nanoid } from 'nanoid';
import Auth from './test/lib/Auth.mjs';
import Mongo from './mongo.mjs';
import DeviceLastSeenService from './test/lib/RecordSkipManager.mjs';
const { createLogger, format, transports } = winstonModule;
const { combine, timestamp, label } = format;
export function makeLogger() {
const alignedWithColorsAndTime = format.combine(
format.colorize(),
format.timestamp(),
format.align(),
format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`)
);
const level = process.env.LOGGING_LEVEL ? process.env.LOGGING_LEVEL : 'info';
const logger = createLogger({
level,
format: combine(label({ label: 'right meow!' }), timestamp(), alignedWithColorsAndTime),
transports: [new transports.Console()],
});
return logger;
}
function Environment() {
const envTest = {};
envTest.logger = makeLogger();
envTest.logger.info('Initializing the environment');
const FHIR_SERVER = process.env.FHIR_SERVER;
if (!FHIR_SERVER) {
envTest.logger.error('FHIR_SERVER missing, cannot start');
process.exit();
}
envTest.lastSeenService = DeviceLastSeenService(envTest);
const TOKEN_ENCRYPTION_KEY = process.env.TOKEN_ENCRYPTION_KEY;
envTest.userProvider = Auth(TOKEN_ENCRYPTION_KEY, envTest);
envTest.FHIRServer = FHIR_SERVER;
if (process.env.MONGODB_URI) {
envTest.MONGODB_URI = process.env.MONGODB_URI;
envTest.mongo = Mongo(envTest);
}
envTest.randomString = nanoid;
envTest.session_key =
process.env.SESSION_KEY ||
'2466c1cc-3bed-11e9-a4de-53cf880a6d1a-2d2ea702-3bed-11e9-8842-ef5457fba264';
envTest.setOauthProvider = function (oauthProvider) {
envTest.oauthProvider = oauthProvider;
};
const authCert = process.env.FIPHR_AUTH_CERT_PATH;
const authKey = process.env.FIPHR_AUTH_KEY_PATH;
if (authCert) {
envTest.https_privateKey = fs.readFileSync(authKey, 'utf8');
envTest.https_certificate = fs.readFileSync(authCert, 'utf8');
envTest.logger.info('Using certificate and private key for HTTPS');
}
return envTest;
}
export default Environment;