forked from project-sunbird/ml-projects-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
envVariables.js
106 lines (86 loc) · 2.75 KB
/
envVariables.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
/**
* name : envVariables.js.
* author : Aman Karki.
* created-date : 19-June-2020.
* Description : Required Environment variables .
*/
const Log = require("log");
let log = new Log("debug");
let table = require("cli-table");
let tableData = new table();
let enviromentVariables = {
"APPLICATION_PORT" : {
"message" : "Please specify the value for e.g. 4201",
"optional" : false
},
"APPLICATION_ENV" : {
"message" : "Please specify the value for e.g. local/development/qa/production",
"optional" : false
},
"MONGODB_URL" : {
"message" : "Required mongodb url",
"optional" : false
},
"INTERNAL_ACCESS_TOKEN" : {
"message" : "Required internal access token",
"optional" : false
},
"KAFKA_COMMUNICATIONS_ON_OFF" : {
"message" : "Enable/Disable kafka communications",
"optional" : false
},
"KAFKA_URL" : {
"message" : "Required",
"optional" : false
}
}
let success = true;
module.exports = function() {
Object.keys(enviromentVariables).forEach(eachEnvironmentVariable=>{
let tableObj = {
[eachEnvironmentVariable] : ""
};
if(
enviromentVariables[eachEnvironmentVariable].requiredIf
&& process.env[enviromentVariables[eachEnvironmentVariable].requiredIf.key]
&& process.env[enviromentVariables[eachEnvironmentVariable].requiredIf.key] === enviromentVariables[eachEnvironmentVariable].requiredIf.value
) {
tableObj[eachEnvironmentVariable].optional = false;
}
if(
!(process.env[eachEnvironmentVariable]) &&
!(enviromentVariables[eachEnvironmentVariable].optional)
) {
success = false;
if(
enviromentVariables[eachEnvironmentVariable].default &&
enviromentVariables[eachEnvironmentVariable].default != ""
) {
process.env[eachEnvironmentVariable] =
enviromentVariables[eachEnvironmentVariable].default;
}
if(
enviromentVariables[eachEnvironmentVariable] &&
enviromentVariables[eachEnvironmentVariable].message !== ""
) {
tableObj[eachEnvironmentVariable] =
enviromentVariables[eachEnvironmentVariable].message;
} else {
tableObj[eachEnvironmentVariable] = "required";
}
} else {
tableObj[eachEnvironmentVariable] = "Passed";
if(
enviromentVariables[eachEnvironmentVariable].possibleValues &&
!enviromentVariables[eachEnvironmentVariable].possibleValues.includes(process.env[eachEnvironmentVariable])
) {
tableObj[eachEnvironmentVariable] = ` Valid values - ${enviromentVariables[eachEnvironmentVariable].possibleValues.join(", ")}`;
}
}
tableData.push(tableObj);
})
log.info(tableData.toString());
return {
success : success
}
}