forked from project-sunbird/ml-core-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
envVariables.js
198 lines (182 loc) · 4.99 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
let table = require("cli-table");
var Log = require("log");
let log = new Log("debug");
let tableData = new table();
let enviromentVariables = {
"APPLICATION_PORT" : {
"message" : "Required port no",
"optional" : false
},
"APPLICATION_ENV" : {
"message" : "Required node environment",
"optional" : false
},
"MONGODB_URL" : {
"message" : "Required mongodb url",
"optional" : false
},
"INTERNAL_ACCESS_TOKEN" : {
"message" : "Required internal access token",
"optional" : false
},
"CLOUD_STORAGE" : {
"message" : "Enable/Disable cloud services",
"optional" : false
},
"GCP_PATH" : {
"message" : "Required Gcp path",
"optional" : true,
"requiredIf" : {
"key": "CLOUD_STORAGE",
"value" : "GC"
}
},
"GCP_BUCKET_NAME" : {
"message" : "Required Gcp bucket name",
"optional" : true,
"requiredIf" : {
"key": "CLOUD_STORAGE",
"value" : "GC"
}
},
"AZURE_ACCOUNT_NAME" : {
"message" : "Required Azure Account name",
"optional" : true,
"requiredIf" : {
"key": "CLOUD_STORAGE",
"value" : "AZURE"
}
},
"AZURE_ACCOUNT_KEY" : {
"message" : "Required Azure Account key",
"optional" : true,
"requiredIf" : {
"key": "CLOUD_STORAGE",
"value" : "AZURE"
}
},
"AZURE_STORAGE_CONTAINER" : {
"message" : "Required Azure container",
"optional" : true,
"requiredIf" : {
"key": "CLOUD_STORAGE",
"value" : "AZURE"
}
},
"AWS_ACCESS_KEY_ID" : {
"message" : "Required Aws access key id",
"optional" : true,
"requiredIf" : {
"key": "CLOUD_STORAGE",
"value" : "AWS"
}
},
"AWS_SECRET_ACCESS_KEY" : {
"message" : "Required Aws secret access key",
"optional" : true,
"requiredIf" : {
"key": "CLOUD_STORAGE",
"value" : "AWS"
}
},
"AWS_BUCKET_NAME" : {
"message" : "Required Aws bucket name",
"optional" : true,
"requiredIf" : {
"key": "CLOUD_STORAGE",
"value" : "AWS"
}
},
"AWS_BUCKET_REGION" : {
"message" : "Required Aws bucket region",
"optional" : true,
"requiredIf" : {
"key": "CLOUD_STORAGE",
"value" : "AWS"
}
},
"AWS_BUCKET_ENDPOINT" : {
"message" : "Required Aws bucket endpoint",
"optional" : true,
"requiredIf" : {
"key": "CLOUD_STORAGE",
"value" : "AWS"
}
},
"KEYCLOAK_PUBLIC_KEY_PATH" : {
"message" : "Required keycloak public key path",
"optional" : false
},
"ML_SURVEY_SERVICE_URL" : {
"message" : "Required survey service API endpoint",
"optional" : false
},
"ML_PROJECT_SERVICE_URL" : {
"message" : "Required project service API endpoint",
"optional" : false
},
"ELASTICSEARCH_COMMUNICATIONS_ON_OFF" : {
"message" : "Enable/Disable elastic search communications",
"optional" : false
},
"ELASTICSEARCH_HOST_URL" : {
"message" : "Elastic search host url",
"optional" : false
},
"ELASTICSEARCH_ENTITIES_INDEX" : {
"message" : "Elastic search entities index",
"optional" : false
},
"USER_SERVICE_URL" : {
"message" : "Sunbird environment base url",
"optional" : false
}
}
let success = true;
module.exports = function() {
Object.keys(enviromentVariables).forEach(eachEnvironmentVariable=>{
let tableObj = { [eachEnvironmentVariable] : "PASSED" };
if(
enviromentVariables[eachEnvironmentVariable].requiredIf
&& process.env[enviromentVariables[eachEnvironmentVariable].requiredIf.key]
&& process.env[enviromentVariables[eachEnvironmentVariable].requiredIf.key] === enviromentVariables[eachEnvironmentVariable].requiredIf.value
) {
enviromentVariables[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
}
}