-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathapi.config.service.ts
More file actions
378 lines (328 loc) · 11 KB
/
api.config.service.ts
File metadata and controls
378 lines (328 loc) · 11 KB
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class ApiConfigService {
constructor(private readonly configService: ConfigService) {}
getPublicAppPort(): number {
const port = this.configService.get<number>('PORT');
if (!port) {
throw new Error('No public app port present');
}
return port;
}
getPublicAppListenAddress(): string {
const listenAddress = this.configService.get<string>('LISTEN_ADDRESS');
if (!listenAddress) {
throw new Error('No public app listen address present');
}
return listenAddress;
}
getPrivateAppPort(): number {
const port = this.configService.get<number>('PRIVATE_PORT');
if (!port) {
throw new Error('No private app port present');
}
return port;
}
getPrivateAppListenAddress(): string {
const listenAddress = this.configService.get<string>(
'PRIVATE_LISTEN_ADDRESS',
);
if (!listenAddress) {
throw new Error('No private app listen address present');
}
return listenAddress;
}
getCacheWarmerPort(): number {
const port = this.configService.get<number>('CACHEWARMER_PORT');
if (!port) {
throw new Error('No cache warmer app port present');
}
return port;
}
isPublicApiActive(): boolean {
const publicApiActive =
this.configService.get<string>('ENABLE_PUBLIC_API');
if (!publicApiActive) {
throw new Error('No public api flag present');
}
return publicApiActive === 'true';
}
isCacheWarmerCronActive(): boolean {
const cacheWramerActive = this.configService.get<string>(
'ENABLE_CACHE_WARMER',
);
if (!cacheWramerActive) {
throw new Error('No cache warmer flag present');
}
return cacheWramerActive === 'true';
}
isPrivateAppActive(): boolean {
const privateApiActive =
this.configService.get<string>('ENABLE_PRIVATE_API');
if (!privateApiActive) {
throw new Error('No private api flag present');
}
return privateApiActive === 'true';
}
isEventsNotifierAppActive(): boolean {
const eventsNotifierAppActive = this.configService.get<string>(
'ENABLE_EVENTS_NOTIFIER',
);
if (!eventsNotifierAppActive) {
throw new Error('No events notifier api flag present');
}
return eventsNotifierAppActive === 'true';
}
isTracerActive(): boolean {
const tracerFlag = this.configService.get<string>('ENABLE_TRACER');
if (!tracerFlag) {
throw new Error('No tracer flag present');
}
return tracerFlag === 'true';
}
isDeephistoryActive(): boolean {
const deepHistoryFlag = this.configService.get<string>(
'ENABLE_DEEP_HISTORY',
);
if (!deepHistoryFlag) {
return false;
}
return deepHistoryFlag === 'true';
}
getRedisUrl(): string {
const redisUrl = this.configService.get<string>('REDIS_URL');
if (!redisUrl) {
throw new Error('No redis url present');
}
return redisUrl;
}
getRedisPort(): number {
const redisPort = this.configService.get<number>('REDIS_PORT');
if (!redisPort) {
throw new Error('No redis port present');
}
return redisPort;
}
getRedisPassword(): string | undefined {
const password = this.configService.get<string>('REDIS_PASSWORD');
return password !== '' ? password : undefined;
}
getCommonRedisUrl(): string {
const redisUrl = this.configService.get<string>('REDIS_COMMON_URL');
if (!redisUrl) {
throw new Error('No common redis url present');
}
return redisUrl;
}
getCommonRedisPort(): number {
const redisPort = this.configService.get<number>('REDIS_COMMON_PORT');
if (!redisPort) {
throw new Error('No common redis port present');
}
return redisPort;
}
getCommonRedisPassword(): string | undefined {
const password = this.configService.get<string>(
'REDIS_COMMON_PASSWORD',
);
return password !== '' ? password : undefined;
}
getApiUrl(): string {
const apiUrl = this.configService.get<string>('MX_API_URL');
if (!apiUrl) {
throw new Error('No apiUrl present');
}
return apiUrl;
}
getGatewayUrl(): string {
const gatewayUrl = this.configService.get<string>('MX_GATEWAY_URL');
if (!gatewayUrl) {
throw new Error('No gatewayUrl present');
}
return gatewayUrl;
}
getKeepAliveTimeoutDownstream(): number {
const keepAliveTimeoutDownstream = this.configService.get<string>(
'KEEPALIVE_TIMEOUT_DOWNSTREAM',
);
if (!keepAliveTimeoutDownstream) {
throw new Error('No keepAliveTimeoutDownstream present');
}
return parseInt(keepAliveTimeoutDownstream);
}
getKeepAliveTimeoutUpstream(): number {
const keepAliveTimeoutUpstream = this.configService.get<string>(
'KEEPALIVE_TIMEOUT_UPSTREAM',
);
if (!keepAliveTimeoutUpstream) {
throw new Error('No keepAliveTimeoutUpstream present');
}
return parseInt(keepAliveTimeoutUpstream);
}
getMongoDBURL(): string {
const mongoDBUrl = this.configService.get<string>('MONGODB_URL');
if (!mongoDBUrl) {
throw new Error('No MongoDB URL present');
}
return mongoDBUrl;
}
getMongoDBDatabase(): string {
const mongoDBDatabase =
this.configService.get<string>('MONGODB_DATABASE');
if (!mongoDBDatabase) {
throw new Error('No MongoDB Database present');
}
return mongoDBDatabase;
}
getMongoDBUsername(): string {
const mongoDBUsername =
this.configService.get<string>('MONGODB_USERNAME');
if (!mongoDBUsername) {
throw new Error('No MongoDB username present');
}
return mongoDBUsername;
}
getMongoDBPassword(): string {
const mongoDBPassword =
this.configService.get<string>('MONGODB_PASSWORD');
if (!mongoDBPassword) {
throw new Error('No MongoDB password present');
}
return mongoDBPassword;
}
getJwtSecret(): string {
const secret = this.configService.get<string>('JWT_SECRET');
if (!secret) {
throw new Error('No jwt secret present');
}
return secret;
}
isAWSTimestreamRead(): boolean {
const readFlag = this.configService.get<string>('AWS_TIMESTREAM_READ');
if (!readFlag) {
throw new Error('No AWS Timestream read flag present');
}
return readFlag === 'true';
}
isAWSTimestreamWrite(): boolean {
const writeFlag = this.configService.get<string>(
'AWS_TIMESTREAM_WRITE',
);
if (!writeFlag) {
throw new Error('No AWS Timestream write flag present');
}
return writeFlag === 'true';
}
getNativeAuthMaxExpirySeconds(): number {
const maxExpiry = this.configService.get<string>(
'NATIVE_AUTH_MAX_EXPIRY_SECONDS',
);
if (!maxExpiry) {
throw new Error('No native auth max expiry in seconds present');
}
return parseInt(maxExpiry);
}
getNativeAuthAcceptedOrigins(): string[] {
const origins = this.configService.get<string>(
'NATIVE_AUTH_ACCEPTED_ORIGINS',
);
if (!origins) {
throw new Error('No accepted origins present');
}
return origins.split(',');
}
getImpersonateUrl(): string {
const impersonateUrl =
this.configService.get<string>('IMPERSONATE_URL');
if (!impersonateUrl) {
throw new Error('No impersonate url present');
}
return impersonateUrl;
}
getMXDataApiURL(): string {
const url = this.configService.get<string>('MX_DATA_API_URL');
if (!url) {
throw new Error('No MX Data API url present');
}
return url;
}
getSecurityAdmins(): string[] {
const admins = this.configService.get<string>('SECURITY_ADMINS');
if (!admins) {
throw new Error('No security admins present');
}
return admins.split(',');
}
getNativeAuthKeyPath(): string {
const nativeAuthPemPath = this.configService.get<string>(
'NATIVE_AUTH_PEM_PATH',
);
if (!nativeAuthPemPath) {
throw new Error('No NATIVE_AUTH_PEM_PATH present');
}
return nativeAuthPemPath;
}
getTimescaleDbHost(): string {
const host = this.configService.get<string>('TIMESCALEDB_URL');
if (!host) {
throw new Error('No TIMESCALEDB_URL present');
}
return host;
}
getTimescaleDbPort(): number {
const port = this.configService.get<string>('TIMESCALEDB_PORT');
if (!port) {
throw new Error('No TIMESCALEDB_PORT present');
}
return parseInt(port);
}
getTimescaleDbDatabase(): string {
const database = this.configService.get<string>('TIMESCALEDB_DATABASE');
if (!database) {
throw new Error('No TIMESCALEDB_DATABASE present');
}
return database;
}
getTimescaleDbUsername(): string {
const username = this.configService.get<string>('TIMESCALEDB_USERNAME');
if (!username) {
throw new Error('No TIMESCALEDB_USERNAME present');
}
return username;
}
getTimescaleDbPassword(): string {
const password = this.configService.get<string>('TIMESCALEDB_PASSWORD');
if (!password) {
throw new Error('No TIMESCALEDB_PASSWORD present');
}
return password;
}
getElasticSearchUrl(): string {
const elasticSearchUrl =
this.configService.get<string>('ELASTICSEARCH_URL');
if (!elasticSearchUrl) {
throw new Error('No Elastic Search url present');
}
return elasticSearchUrl;
}
getOpenExchangeRateAppID(): string {
const appId = this.configService.get<string>(
'OPEN_EXCHANGE_RATES_APP_ID',
);
if (!appId) {
throw new Error('No OPEN_EXCHANGE_RATES_APP_ID present');
}
return appId;
}
getOpenExchangeRateUrl(): string {
const url = this.configService.get<string>('OPEN_EXCHANGE_RATES_URL');
if (!url) {
throw new Error('No OPEN_EXCHANGE_RATES_URL present');
}
return url;
}
getRateLimiterSecret(): string | undefined {
return this.configService.get<string>('RATE_LIMITER_SECRET');
}
}