-
Notifications
You must be signed in to change notification settings - Fork 9
/
envVariables.js
225 lines (215 loc) · 6.12 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
/**
* 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,
},
GOTENBERG_URL: {
message: 'Gotenberg url required',
optional: false,
},
KAFKA_COMMUNICATIONS_ON_OFF: {
message: 'Enable/Disable kafka communications',
optional: false,
},
// "KAFKA_URL" : {
// "message" : "Required",
// "optional" : false
// },
SERVICE_NAME: {
message: 'Project service name required',
optional: false,
default: 'project',
},
CERTIFICATE_SERVICE_URL: {
message: 'certificate service base url',
optional: true,
default: 'http://registry-service:8081',
requiredIf: {
key: 'PROJECT_CERTIFICATE_ON_OFF',
operator: 'EQUALS',
value: 'ON',
},
},
PROJECT_CERTIFICATE_ON_OFF: {
message: 'Enable/Disable project certification',
optional: false,
default: 'ON',
},
// cloud service variables
CLOUD_STORAGE_PROVIDER: {
message: 'Require cloud storage provider',
optional: false,
},
CLOUD_STORAGE_BUCKETNAME: {
message: 'Require client storage bucket name',
optional: false,
},
CLOUD_STORAGE_SECRET: {
message: 'Require client storage provider identity',
optional: false,
},
CLOUD_STORAGE_ACCOUNTNAME: {
message: 'Require client storage account name',
optional: false,
},
ALLOWED_HOST: {
message: 'Required CORS allowed host',
optional: true,
default: '*',
},
// signedUrl and downloadAble url expiry durations
DOWNLOADABLE_URL_EXPIRY_IN_SECONDS: {
message: 'Required downloadable url expiration time',
optional: false,
default: 300,
},
PRESIGNED_URL_EXPIRY_IN_SECONDS: {
message: 'Required presigned url expiration time',
optional: false,
default: 300,
},
// default organisation code
DEFAULT_ORGANISATION_CODE: {
message: 'Default Organization Id/Code is required',
optional: false,
},
APP_PORTAL_BASE_URL: {
message: 'App Portal base url required',
optional: false,
default: 'https://dev.elevate.org',
},
TIMEZONE_DIFFRENECE_BETWEEN_LOCAL_TIME_AND_UTC: {
message: 'Timezone diffrence required',
optional: false,
},
ELEVATE_PROJECT_SERVICE_URL: {
message: 'Elevate project service url required',
optional: false,
},
API_DOC_URL: {
message: 'Required api doc url',
optional: false,
},
INTERFACE_SERVICE_URL: {
message: 'Interface service url required',
optional: false,
},
USER_SERVICE_BASE_URL: {
message: 'User service name required',
optional: false,
},
ENTITY_MANAGEMENT_SERVICE_BASE_URL: {
message: 'Entity management service name required',
optional: false,
},
SUBMISSION_LEVEL: {
message: 'Project submission level required',
optional: false,
default: 'USER',
},
}
let success = true
module.exports = function () {
Object.keys(enviromentVariables).forEach((eachEnvironmentVariable) => {
let tableObj = {
[eachEnvironmentVariable]: 'PASSED',
}
let keyCheckPass = true
let validRequiredIfOperators = ['EQUALS', 'NOT_EQUALS']
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] == '') {
keyCheckPass = false
if (
enviromentVariables[eachEnvironmentVariable].default &&
enviromentVariables[eachEnvironmentVariable].default != ''
) {
process.env[eachEnvironmentVariable] = enviromentVariables[eachEnvironmentVariable].default
keyCheckPass = true
} else {
success = false
}
} else if (
enviromentVariables[eachEnvironmentVariable].possibleValues &&
Array.isArray(enviromentVariables[eachEnvironmentVariable].possibleValues) &&
enviromentVariables[eachEnvironmentVariable].possibleValues.length > 0
) {
if (
!enviromentVariables[eachEnvironmentVariable].possibleValues.includes(
process.env[eachEnvironmentVariable]
)
) {
success = false
keyCheckPass = false
enviromentVariables[eachEnvironmentVariable].message += ` Valid values - ${enviromentVariables[
eachEnvironmentVariable
].possibleValues.join(', ')}`
}
}
}
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,
}
}