-
Notifications
You must be signed in to change notification settings - Fork 8
/
envVariables.js
329 lines (315 loc) · 9.5 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
let table = require("cli-table");
let tableData = new table();
let enviromentVariables = {
"HOST" : {
"message":"Required host name",
"optional": false
},
"PORT" : {
"message" : "Required port no",
"optional" : false
},
"LOG" : {
"message" : "Required logger type",
"optional" : false
},
"NODE_ENV" : {
"message" : "Required node environment",
"optional" : false
},
"ENABLE_BUNYAN_LOGGING" : {
"message" : "Enable or disable bunyan logging",
"optional" : false
},
"REQUEST_TIMEOUT_FOR_REPORTS" : {
"message" : "Required Reports request timeout",
"optional" : false
},
"APPLICATION_BASE_URL" : {
"message" : "Required Application base url",
"optional" : false
},
"MOBILE_APPLICATION_APP_TYPE" : {
"message" : "Required mobile application app type value",
"optional" : false
},
"APPLICATION_BASE_HOST" : {
"message" : "Required Base host",
"optional" : false
},
"AUTHORIZATION" : {
"message" : "Required Server authorization code",
"optional" : false
},
"CLOUD_STORAGE" : {
"message" : "Required cloud storage provider",
"optional" : false
},
"GCP_PATH" : {
"message" : "Optional google cloud platform path",
"optional" : true
},
"GCP_BUCKET_NAME" : {
"message" : "Optional gcp bucket name",
"optional" : true
},
"AZURE_ACCOUNT_NAME" : {
"message" : "Optional azure account name",
"optional" : true
},
"AZURE_ACCOUNT_KEY" : {
"message" : "Optional azure storage account key",
"optional" : true
},
"AZURE_STORAGE_CONTAINER" : {
"message" : "Optional azure storage container name",
"optional" : true
},
"AWS_ACCESS_KEY_ID" : {
"message" : "Optional aws access key id",
"optional" : true
},
"AWS_SECRET_ACCESS_KEY" : {
"message" : "Optional aws secret access key",
"optional" : true
},
"AWS_BUCKET_NAME" : {
"message" : "Optional aws bucket name",
"optional" : true
},
"AWS_BUCKET_REGION" : {
"message" : "Optional aws bucket region",
"optional" : true
},
"AWS_BUCKET_ENDPOINT" : {
"message" : "Optional aws bucket endpoint",
"optional" : true
},
"MONGODB_URL" : {
"message" : "Required mongodb url",
"optional" : false
},
"SHIKSHALOKAM_BASE_HOST" : {
"message" : "Required shikshalokam base host",
"optional" : false
},
"DB" : {
"message" : "Required database",
"optional" : false
},
"INTERNAL_ACCESS_TOKEN" : {
"message" : "Required internal access token",
"optional" : false
},
"sunbird_keycloak_auth_server_url" : {
"message" : "Required sunbird keycloak auth server url",
"optional" : false
},
"sunbird_keycloak_realm" : {
"message" : "Required sunbird keycloak realm",
"optional" : false
},
"sunbird_keycloak_client_id" : {
"message" : "Required sunbird keycloak client id",
"optional" : false
},
"sunbird_keycloak_public" : {
"message" : "Required sunbird keycloak public",
"optional" : false
},
"sunbird_cache_store" : {
"message" : "Required sunbird cache store",
"optional" : false
},
"sunbird_cache_ttl" : {
"message" : "Required sunbird cache ttl",
"optional" : false
},
"MIGRATION_COLLECTION" : {
"message" : "Required migrations collection name",
"optional" : false
},
"MIGRATION_DIR" : {
"message" : "Required migrations directory name",
"optional" : false
},
"SLACK_COMMUNICATIONS_ON_OFF" : {
"message" : "Enable/Disable slack communications",
"optional" : false
},
"SLACK_EXCEPTION_LOG_URL" : {
"message" : "Enable/Disable slack exception log url",
"optional" : false
},
"SLACK_TOKEN" : {
"message" : "Required slack token",
"optional" : false
},
"RUBRIC_ERROR_MESSAGES_TO_SLACK" : {
"message" : "Enable/Disable rubric error message",
"optional" : false
},
"CSV_REPORTS_PATH" : {
"message" : "Required csv reports path",
"optional" : false
},
"DISABLE_TOKEN_ON_OFF" : {
"message" : "",
"optional" : false
},
"DISABLE_TOKEN_CHECK_FOR_API" : {
"message" : "Required Api endpoint for disabling token check",
"optional" : false
},
"DISABLE_TOKEN_DEFAULT_USERID" : {
"message" : "Required",
"optional" : false
},
"DISABLE_TOKEN_DEFAULT_USER_ROLE" : {
"message" : "ASSESSOR",
"optional" : false
},
"DISABLE_TOKEN_DEFAULT_USER_NAME" : {
"message" : "DISABLE_TOKEN_CHECK_DEFAULT_USER_NAME",
"optional" : false
},
"DISABLE_TOKEN_DEFAULT_USER_EMAIL" : {
"message" : "DISABLE_TOKEN_CHECK_DEFAULT_USER_EMAIL",
"optional" : false
},
"DISABLE_LEARNER_SERVICE_ON_OFF" : {
"message" : "Disable learner service",
"optional" : false
},
"KAFKA_COMMUNICATIONS_ON_OFF" : {
"message" : "Enable/Disable kafka communications",
"optional" : false
},
"KAFKA_URL" : {
"message" : "Required kafka url",
"optional" : false
},
"KAFKA_GROUP_ID" : {
"message" : "Required kafka group id",
"optional" : false
},
"COMPLETED_SUBMISSION_TOPIC" : {
"message" : "OFF/TOPIC_NAME",
"optional" : false
},
"INCOMPLETE_SUBMISSION_TOPIC" : {
"message" : "OFF/TOPIC_NAME",
"optional" : false
},
"SUBMISSION_RATING_QUEUE_TOPIC" : {
"message" : "OFF/TOPIC_NAME",
"optional" : false
},
"COMPLETED_OBSERVATION_SUBMISSION_TOPIC" : {
"message" : "OFF/TOPIC_NAME",
"optional" : false
},
"INCOMPLETE_OBSERVATION_SUBMISSION_TOPIC" : {
"message" : "OFF/TOPIC_NAME",
"optional" : false
},
"NOTIFICATIONS_TOPIC" : {
"message" : "OFF/TOPIC_NAME",
"optional" : false
},
"KAFKA_ERROR_MESSAGES_TO_SLACK" : {
"message" : "ON/OFF",
"optional" : false
},
"EMAIL_COMMUNICATIONS_ON_OFF" : {
"message" : "ON/OFF",
"optional" : false
},
"EMAIL_SERVICE_BASE_URL" : {
"message" : "Required email service url",
"optional" : false
},
"EMAIL_SERVICE_TOKEN" : {
"message" : "Required email service token",
"optional" : false
},
"SUBMISSION_RATING_DEFAULT_EMAIL_RECIPIENTS" : {
"message" : "Required email recipients for submission rating",
"optional" : false
},
"SHIKSHALOKAM_USER_PROFILE_FETCH_ENDPOINT" : {
"message" : "Required user profile fetch API endpoint",
"optional" : true
},
"USE_USER_ORGANISATION_ID_FILTER" : {
"message" : "Required",
"optional" : true,
"default" : "OFF"
}
}
let success = true;
module.exports = function() {
Object.keys(enviromentVariables).forEach(eachEnvironmentVariable=>{
let tableObj = {
[eachEnvironmentVariable] : "PASSED"
};
let keyCheckPass = true;
if(enviromentVariables[eachEnvironmentVariable].optional === true
&& enviromentVariables[eachEnvironmentVariable].requiredIf
&& enviromentVariables[eachEnvironmentVariable].requiredIf.key
&& enviromentVariables[eachEnvironmentVariable].requiredIf.key != ""
&& enviromentVariables[eachEnvironmentVariable].requiredIf.operator
&& validRequiredIfOperators.includes(enviromentVariables[eachEnvironmentVariable].requiredIf.operator)
&& enviromentVariables[eachEnvironmentVariable].requiredIf.value
&& enviromentVariables[eachEnvironmentVariable].requiredIf.value != "") {
switch (enviromentVariables[eachEnvironmentVariable].requiredIf.operator) {
case "EQUALS":
if(process.env[enviromentVariables[eachEnvironmentVariable].requiredIf.key] === enviromentVariables[eachEnvironmentVariable].requiredIf.value) {
enviromentVariables[eachEnvironmentVariable].optional = false;
}
break;
case "NOT_EQUALS":
if(process.env[enviromentVariables[eachEnvironmentVariable].requiredIf.key] != enviromentVariables[eachEnvironmentVariable].requiredIf.value) {
enviromentVariables[eachEnvironmentVariable].optional = false;
}
break;
default:
break;
}
}
if(enviromentVariables[eachEnvironmentVariable].optional === false) {
if(!(process.env[eachEnvironmentVariable])
|| process.env[eachEnvironmentVariable] == "") {
environmentVariablesCheckSuccessful = false;
keyCheckPass = false;
} else if (enviromentVariables[eachEnvironmentVariable].possibleValues
&& Array.isArray(enviromentVariables[eachEnvironmentVariable].possibleValues)
&& enviromentVariables[eachEnvironmentVariable].possibleValues.length > 0) {
if(!enviromentVariables[eachEnvironmentVariable].possibleValues.includes(process.env[eachEnvironmentVariable])) {
environmentVariablesCheckSuccessful = false;
keyCheckPass = false;
enviromentVariables[eachEnvironmentVariable].message += ` Valid values - ${enviromentVariables[eachEnvironmentVariable].possibleValues.join(", ")}`
}
}
}
if((!(process.env[eachEnvironmentVariable])
|| process.env[eachEnvironmentVariable] == "")
&& enviromentVariables[eachEnvironmentVariable].default
&& enviromentVariables[eachEnvironmentVariable].default != "") {
process.env[eachEnvironmentVariable] = enviromentVariables[eachEnvironmentVariable].default;
}
if(!keyCheckPass) {
if(enviromentVariables[eachEnvironmentVariable].message !== "") {
tableObj[eachEnvironmentVariable] =
enviromentVariables[eachEnvironmentVariable].message;
} else {
tableObj[eachEnvironmentVariable] = `FAILED - ${eachEnvironmentVariable} is required`;
}
}
tableData.push(tableObj);
})
log.info(tableData.toString());
return {
success : success
}
}