• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

telefonicaid / iotagent-node-lib / 22754394382

06 Mar 2026 07:55AM UTC coverage: 79.414% (+0.04%) from 79.378%
22754394382

Pull #1764

github

web-flow
Merge 0a8fde5c0 into 0beb42ab8
Pull Request #1764: Task/add health check to metrics and /ready

2158 of 2902 branches covered (74.36%)

Branch coverage included in aggregate %.

198 of 259 new or added lines in 5 files covered. (76.45%)

36 existing lines in 3 files now uncovered.

4161 of 5055 relevant lines covered (82.31%)

293.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.52
/lib/commonConfig.js
1
/*
2
 * Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U
3
 *
4
 * This file is part of fiware-iotagent-lib
5
 *
6
 * fiware-iotagent-lib is free software: you can redistribute it and/or
7
 * modify it under the terms of the GNU Affero General Public License as
8
 * published by the Free Software Foundation, either version 3 of the License,
9
 * or (at your option) any later version.
10
 *
11
 * fiware-iotagent-lib is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 * See the GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public
17
 * License along with fiware-iotagent-lib.
18
 * If not, see http://www.gnu.org/licenses/.
19
 *
20
 * For those usages not covered by the GNU Affero General Public License
21
 * please contact with::daniel.moranjimenez@telefonica.com
22
 *
23
 * Modified by: Federico M. Facca - Martel Innovate
24
 * Modified by: Daniel Calvo - ATOS Research & Innovation
25
 * Modified by: Fernando López - FIWARE Foundation
26
 */
27

28
let config = {};
1✔
29
const logger = require('logops');
1✔
30
let registry;
31
let groupRegistry;
32
let commandRegistry;
33
let securityService;
34

35
const fs = require('fs');
1✔
36
const path = require('path');
1✔
37
const SECRETS_DIR = process.env.SECRETS_DIR || '/run/secrets';
1✔
38
const secrets = {};
1✔
39

40
if (fs.existsSync(SECRETS_DIR)) {
1!
41
    const files = fs.readdirSync(SECRETS_DIR);
×
42
    files.forEach(function (file) {
×
43
        const fullPath = path.join(SECRETS_DIR, file);
×
44
        const key = file;
×
45
        try {
×
46
            const data = fs.readFileSync(fullPath, 'utf8').toString().trim();
×
47
            secrets[key] = data;
×
48
        } catch (e) {
49
            logger.error(e.message);
×
50
        }
51
    });
52
}
53

54
function anyIsSet(variableSet) {
55
    for (let i = 0; i < variableSet.length; i++) {
3,360✔
56
        if (process.env[variableSet[i]]) {
31,190✔
57
            return true;
76✔
58
        }
59
    }
60

61
    return false;
3,284✔
62
}
63

64
/**
65
 * If an ENV is a protected Docker Secret extract the value of the secret data
66
 */
67
function getSecretData(key) {
68
    const filepath = process.env[key + '_FILE'];
10,080✔
69
    if (filepath) {
10,080!
70
        process.env[key] = secrets[path.parse(filepath).base] || process.env[key];
×
71
    }
72
}
73

74
/*
75
 *  Inform the user if security is correctly enabled.
76
 */
77
function logAuthState() {
78
    const stars = '***********************************************';
1,680✔
79
    if (config.authentication === undefined) {
1,680✔
80
        logger.warn(
1,586✔
81
            stars +
82
                '\n' +
83
                'WARNING: authentication for secure connections is not in use,\n' +
84
                'It is recommended to enable authentication\n' +
85
                stars
86
        );
87
    } else {
88
        const authKeystone = !!config.authentication.user && !!config.authentication.password;
94✔
89
        const authKeyrock = !!config.authentication.clientSecret && !!config.authentication.clientId;
94✔
90

91
        if (authKeystone) {
94✔
92
            logger.info('INFO: IoT Agent=>Keystone Auth credentials have been configured');
16✔
93
        } else if (authKeyrock) {
78!
94
            logger.info('INFO: IoT Agent=>Keyrock Auth credentials have been configured');
78✔
95
        } else {
96
            logger.warn(
×
97
                stars +
98
                    '\n' +
99
                    'WARNING: authentication for secure connections is in use,\n' +
100
                    ' but default Auth credentials have not been overridden\n' +
101
                    stars
102
            );
103
        }
104
    }
105
}
106

107
/**
108
 * Looks for environment variables that could override configuration values.
109
 */
110
function processEnvironmentVariables() {
111
    const environmentVariables = [
1,680✔
112
        'IOTA_CB_URL',
113
        'IOTA_CB_HOST',
114
        'IOTA_CB_PORT',
115
        'IOTA_CB_NGSI_VERSION',
116
        'IOTA_NORTH_HOST',
117
        'IOTA_NORTH_PORT',
118
        'IOTA_PROVIDER_URL',
119
        'IOTA_AUTH_ENABLED',
120
        'IOTA_AUTH_TYPE',
121
        'IOTA_AUTH_HEADER',
122
        'IOTA_AUTH_URL',
123
        'IOTA_AUTH_HOST',
124
        'IOTA_AUTH_PORT',
125
        'IOTA_AUTH_USER',
126
        'IOTA_AUTH_PASSWORD',
127
        'IOTA_AUTH_CLIENT_ID',
128
        'IOTA_AUTH_CLIENT_SECRET',
129
        'IOTA_AUTH_TOKEN_PATH',
130
        'IOTA_AUTH_PERMANENT_TOKEN',
131
        'IOTA_REGISTRY_TYPE',
132
        'IOTA_LOG_LEVEL',
133
        'IOTA_TIMESTAMP',
134
        'IOTA_IOTAM_HOST',
135
        'IOTA_IOTAM_PORT',
136
        'IOTA_IOTAM_PATH',
137
        'IOTA_IOTAM_PROTOCOL',
138
        'IOTA_IOTAM_DESCRIPTION',
139
        'IOTA_DEFAULT_RESOURCE',
140
        'IOTA_EXPLICIT_ATTRS',
141
        'IOTA_MONGO_HOST',
142
        'IOTA_MONGO_PORT',
143
        'IOTA_MONGO_DB',
144
        'IOTA_MONGO_REPLICASET',
145
        'IOTA_MONGO_PASSWORD',
146
        'IOTA_MONGO_AUTH_SOURCE',
147
        'IOTA_MONGO_RETRIES',
148
        'IOTA_MONGO_USER',
149
        'IOTA_MONGO_RETRY_TIME',
150
        'IOTA_POLLING_EXPIRATION',
151
        'IOTA_POLLING_DAEMON_FREQ',
152
        'IOTA_MULTI_CORE',
153
        'IOTA_RELAX_TEMPLATE_VALIDATION',
154
        'IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION',
155
        'IOTA_JSON_LD_CONTEXT',
156
        'IOTA_FALLBACK_TENANT',
157
        'IOTA_FALLBACK_PATH',
158
        'IOTA_LD_SUPPORT_NULL',
159
        'IOTA_LD_SUPPORT_DATASET_ID',
160
        'IOTA_LD_SUPPORT_DATA_TYPE',
161
        'IOTA_EXPRESS_LIMIT',
162
        'IOTA_USE_CB_FLOW_CONTROL',
163
        'IOTA_STORE_LAST_MEASURE',
164
        'IOTA_CMD_MODE',
165
        'IOTA_HEALTH_CHECK_INTERVAL',
166
        'IOTA_HEALTH_CHECK_TIMEOUT',
167
        'IOTA_HEALTH_CHECK_DOWN_AFTER_FAILS',
168
        'IOTA_HEALTH_CHECK_CONSIDER_HTTP_RESPONSE_UP'
169
    ];
170
    const iotamVariables = [
1,680✔
171
        'IOTA_IOTAM_URL',
172
        'IOTA_IOTAM_HOST',
173
        'IOTA_IOTAM_PORT',
174
        'IOTA_IOTAM_PATH',
175
        'IOTA_IOTAM_PROTOCOL',
176
        'IOTA_IOTAM_DESCRIPTION',
177
        'IOTA_IOTAM_AGENTPATH'
178
    ];
179
    const mongoVariables = [
1,680✔
180
        'IOTA_MONGO_URI',
181
        // FIXME: the following IOTA_MONGO_ env vars are deprecated and will
182
        // be eventually removed (use IOTA_MONGO_URI)
183
        'IOTA_MONGO_HOST',
184
        'IOTA_MONGO_PORT',
185
        'IOTA_MONGO_DB',
186
        'IOTA_MONGO_REPLICASET',
187
        'IOTA_MONGO_USER',
188
        'IOTA_MONGO_PASSWORD',
189
        'IOTA_MONGO_AUTH_SOURCE',
190
        'IOTA_MONGO_RETRIES',
191
        'IOTA_MONGO_RETRY_TIME',
192
        'IOTA_MONGO_SSL',
193
        'IOTA_MONGO_EXTRAARGS'
194
    ];
195
    const protectedVariables = [
1,680✔
196
        'IOTA_AUTH_USER',
197
        'IOTA_AUTH_PASSWORD',
198
        'IOTA_AUTH_CLIENT_ID',
199
        'IOTA_AUTH_CLIENT_SECRET',
200
        'IOTA_MONGO_USER',
201
        'IOTA_MONGO_PASSWORD'
202
    ];
203

204
    // Substitute Docker Secret Variables where set.
205
    protectedVariables.forEach((key) => {
1,680✔
206
        getSecretData(key);
10,080✔
207
    });
208
    environmentVariables.forEach((key) => {
1,680✔
209
        let value = process.env[key];
95,760✔
210
        if (value) {
95,760✔
211
            if (
753✔
212
                key.endsWith('USER') ||
2,680✔
213
                key.endsWith('PASSWORD') ||
214
                key.endsWith('CLIENT_ID') ||
215
                key.endsWith('CLIENT_SECRET')
216
            ) {
217
                value = '********';
136✔
218
            }
219
            logger.info('Setting %s to environment value: %s', key, value);
753✔
220
        }
221
    });
222

223
    // Context Broker Configuration (ensuring the configuration sub-object exists before start using it)
224
    if (config.contextBroker === undefined) {
1,680✔
225
        config.contextBroker = {};
1✔
226
    }
227

228
    if (process.env.IOTA_CB_URL) {
1,680!
UNCOV
229
        config.contextBroker.url = process.env.IOTA_CB_URL;
×
230
        // Not sure if config.contextBroker.host and config.contextBroker.port are used
231
        // in this case, but better to have them initialized
UNCOV
232
        if (process.env.IOTA_CB_HOST) {
×
233
            config.contextBroker.host = process.env.IOTA_CB_HOST;
×
234
        }
UNCOV
235
        if (process.env.IOTA_CB_PORT) {
×
236
            config.contextBroker.port = process.env.IOTA_CB_PORT;
×
237
        }
238
    } else if (process.env.IOTA_CB_HOST) {
1,680✔
239
        config.contextBroker.host = process.env.IOTA_CB_HOST;
8✔
240
        config.contextBroker.url = 'http://' + process.env.IOTA_CB_HOST;
8✔
241
        if (process.env.IOTA_CB_PORT) {
8✔
242
            config.contextBroker.url += ':' + process.env.IOTA_CB_PORT;
6✔
243
        } else {
244
            config.contextBroker.url += ':' + config.contextBroker.port;
2✔
245
        }
246
    }
247

248
    if (process.env.IOTA_CB_NGSI_VERSION) {
1,680✔
249
        config.contextBroker.ngsiVersion = process.env.IOTA_CB_NGSI_VERSION;
4✔
250
    }
251

252
    if (process.env.IOTA_JSON_LD_CONTEXT) {
1,680✔
253
        config.contextBroker.jsonLdContext = process.env.IOTA_JSON_LD_CONTEXT.split(',').map((ctx) => ctx.trim());
8✔
254
    }
255

256
    if (Array.isArray(config.contextBroker.jsonLdContext) && config.contextBroker.jsonLdContext.length === 1) {
1,680✔
257
        config.contextBroker.jsonLdContext = config.contextBroker.jsonLdContext[0];
3✔
258
    }
259

260
    config.contextBroker.fallbackTenant =
1,680✔
261
        process.env.IOTA_FALLBACK_TENANT || config.contextBroker.service || 'iotagent';
5,036✔
262
    config.contextBroker.fallbackPath = process.env.IOTA_FALLBACK_PATH || config.contextBroker.subservice || '/';
1,680✔
263

264
    // North Port Configuration (ensuring the configuration sub-object exists before start using it)
265
    if (config.server === undefined) {
1,680!
UNCOV
266
        config.server = {};
×
267
    }
268

269
    if (process.env.IOTA_NORTH_HOST) {
1,680✔
270
        config.server.host = process.env.IOTA_NORTH_HOST;
6✔
271
    }
272
    if (process.env.IOTA_NORTH_PORT) {
1,680✔
273
        config.server.port = process.env.IOTA_NORTH_PORT;
6✔
274
    }
275

276
    config.server.ldSupport = config.server.ldSupport || {
1,680✔
277
        null: true,
278
        datasetId: true,
279
        merge: false,
280
        dataType: 'none'
281
    };
282

283
    if (process.env.IOTA_LD_SUPPORT_NULL) {
1,680✔
284
        config.server.ldSupport.null = process.env.IOTA_LD_SUPPORT_NULL === 'true';
2✔
285
    }
286
    if (process.env.IOTA_LD_SUPPORT_DATASET_ID) {
1,680✔
287
        config.server.ldSupport.datasetId = process.env.IOTA_LD_SUPPORT_DATASET_ID === 'true';
2✔
288
    }
289
    if (process.env.IOTA_LD_SUPPORT_MERGE) {
1,680!
UNCOV
290
        config.server.ldSupport.datasetId = process.env.IOTA_LD_SUPPORT_MERGE === 'true';
×
291
    }
292
    if (process.env.IOTA_LD_SUPPORT_DATA_TYPE) {
1,680✔
293
        config.server.ldSupport.dataType = process.env.IOTA_LD_SUPPORT_DATA_TYPE;
2✔
294
    }
295

296
    if (process.env.IOTA_PROVIDER_URL) {
1,680✔
297
        config.providerUrl = process.env.IOTA_PROVIDER_URL;
6✔
298
    }
299

300
    // Authentication Parameters - General
301
    if (process.env.IOTA_AUTH_ENABLED) {
1,680✔
302
        config.authentication = {};
4✔
303
        config.authentication.enabled = process.env.IOTA_AUTH_ENABLED === 'true';
4✔
304
    }
305
    if (process.env.IOTA_AUTH_TYPE) {
1,680!
UNCOV
306
        config.authentication.type = process.env.IOTA_AUTH_TYPE;
×
307
    }
308
    if (process.env.IOTA_AUTH_HEADER) {
1,680!
UNCOV
309
        config.authentication.header = process.env.IOTA_AUTH_HEADER;
×
310
    }
311
    if (process.env.IOTA_AUTH_URL) {
1,680!
UNCOV
312
        config.authentication.url = process.env.IOTA_AUTH_URL;
×
313
    } else if (process.env.IOTA_AUTH_HOST) {
1,680!
UNCOV
314
        config.authentication.host = process.env.IOTA_AUTH_HOST;
×
315
        config.authentication.url = 'http://' + process.env.IOTA_AUTH_HOST;
×
316
        if (process.env.IOTA_AUTH_PORT) {
×
317
            config.authentication.url += ':' + process.env.IOTA_AUTH_PORT;
×
318
        } else {
UNCOV
319
            config.authentication.url += ':' + config.authentication.port;
×
320
        }
321
    }
322
    if (process.env.IOTA_AUTH_HOST) {
1,680!
UNCOV
323
        config.authentication.host = process.env.IOTA_AUTH_HOST;
×
324
    }
325
    if (process.env.IOTA_AUTH_PORT) {
1,680!
UNCOV
326
        config.authentication.port = process.env.IOTA_AUTH_PORT;
×
327
    }
328
    // Authentication Parameters - Oauth + Keyrock
329
    if (process.env.IOTA_AUTH_CLIENT_ID) {
1,680✔
330
        config.authentication.clientId = process.env.IOTA_AUTH_CLIENT_ID;
2✔
331
    }
332
    if (process.env.IOTA_AUTH_CLIENT_SECRET) {
1,680✔
333
        config.authentication.clientSecret = process.env.IOTA_AUTH_CLIENT_SECRET;
2✔
334
    }
335
    if (process.env.IOTA_AUTH_TOKEN_PATH) {
1,680!
UNCOV
336
        config.authentication.tokenPath = process.env.IOTA_AUTH_TOKEN_PATH;
×
337
    }
338
    // Authentication Parameters - Keyrock only
339
    if (process.env.IOTA_AUTH_PERMANENT_TOKEN) {
1,680!
UNCOV
340
        config.authentication.permanentToken = process.env.IOTA_AUTH_PERMANENT_TOKEN;
×
341
    }
342
    // Authentication Parameters - Keystone only
343
    if (process.env.IOTA_AUTH_USER) {
1,680✔
344
        config.authentication.user = process.env.IOTA_AUTH_USER;
2✔
345
    }
346
    if (process.env.IOTA_AUTH_PASSWORD) {
1,680✔
347
        config.authentication.password = process.env.IOTA_AUTH_PASSWORD;
2✔
348
    }
349

350
    // Registry configuration (memory or database)
351
    config.deviceRegistry = config.deviceRegistry || {};
1,680✔
352
    if (process.env.IOTA_REGISTRY_TYPE) {
1,680✔
353
        config.deviceRegistry.type = process.env.IOTA_REGISTRY_TYPE;
6✔
354
    }
355

356
    // Log Level configuration
357
    if (process.env.IOTA_LOG_LEVEL) {
1,680✔
358
        config.logLevel = process.env.IOTA_LOG_LEVEL;
6✔
359
        logger.setLevel(process.env.IOTA_LOG_LEVEL);
6✔
360
    }
361

362
    // Whether to include timestamps
363
    if (process.env.IOTA_TIMESTAMP) {
1,680✔
364
        config.timestamp = process.env.IOTA_TIMESTAMP === 'true';
6✔
365
    }
366

367
    // Default resource
368
    if (process.env.IOTA_DEFAULT_RESOURCE !== undefined) {
1,680✔
369
        config.defaultResource = process.env.IOTA_DEFAULT_RESOURCE;
6✔
370
    }
371

372
    // Default transport
373
    if (process.env.IOTA_DEFAULT_TRANSPORT !== undefined) {
1,680!
UNCOV
374
        config.defaultTransport = process.env.IOTA_DEFAULT_TRANSPORT;
×
375
    } else {
376
        // defaultTransport is "MQTT" by default even when no ENV VAR is used
377
        // and should be available in iotagent-library to allow
378
        // set polling and transport for autoprovisioned devices
379
        // at lib/services/devices/deviceService.js#L302
380
        config.defaultTransport = 'MQTT';
1,680✔
381
    }
382

383
    // Default explicitAttrs
384
    if (process.env.IOTA_EXPLICIT_ATTRS !== undefined) {
1,680!
UNCOV
385
        config.explicitAttrs = process.env.IOTA_EXPLICIT_ATTRS;
×
386
    }
387

388
    // IoT Manager Configuration
389
    if (anyIsSet(iotamVariables)) {
1,680✔
390
        config.iotManager = {};
6✔
391
    }
392

393
    if (process.env.IOTA_IOTAM_URL) {
1,680!
UNCOV
394
        config.iotManager.url = process.env.IOTA_IOTAM_URL;
×
395
    } else if (process.env.IOTA_IOTAM_HOST) {
1,680✔
396
        config.iotManager.url = 'http://' + process.env.IOTA_IOTAM_HOST;
6✔
397
        if (process.env.IOTA_IOTAM_PORT) {
6!
398
            config.iotManager.url += ':' + process.env.IOTA_IOTAM_PORT;
6✔
399
        } else {
UNCOV
400
            config.iotManager.url += ':' + config.iotManager.port;
×
401
        }
402
    }
403

404
    if (process.env.IOTA_IOTAM_PATH) {
1,680✔
405
        config.iotManager.path = process.env.IOTA_IOTAM_PATH;
6✔
406
    }
407

408
    if (process.env.IOTA_IOTAM_PROTOCOL) {
1,680✔
409
        config.iotManager.protocol = process.env.IOTA_IOTAM_PROTOCOL;
6✔
410
    }
411

412
    if (process.env.IOTA_IOTAM_DESCRIPTION) {
1,680✔
413
        config.iotManager.description = process.env.IOTA_IOTAM_DESCRIPTION;
6✔
414
    }
415

416
    if (process.env.IOTA_IOTAM_AGENTPATH) {
1,680!
UNCOV
417
        config.iotManager.agentPath = process.env.IOTA_IOTAM_AGENTPATH;
×
418
    }
419

420
    // Mongo DB configuration
421
    if (anyIsSet(mongoVariables)) {
1,680✔
422
        config.mongodb = {};
70✔
423
    }
424

425
    if (process.env.IOTA_MONGO_URI) {
1,680!
UNCOV
426
        config.mongodb.uri = process.env.IOTA_MONGO_URI;
×
427
    }
428

429
    if (process.env.IOTA_MONGO_HOST) {
1,680✔
430
        config.mongodb.host = process.env.IOTA_MONGO_HOST;
70✔
431
    }
432

433
    if (process.env.IOTA_MONGO_PORT) {
1,680✔
434
        config.mongodb.port = process.env.IOTA_MONGO_PORT;
70✔
435
    }
436

437
    if (process.env.IOTA_MONGO_DB) {
1,680✔
438
        config.mongodb.db = process.env.IOTA_MONGO_DB;
70✔
439
    }
440

441
    if (process.env.IOTA_MONGO_REPLICASET) {
1,680✔
442
        config.mongodb.replicaSet = process.env.IOTA_MONGO_REPLICASET;
70✔
443
    }
444

445
    if (process.env.IOTA_MONGO_USER) {
1,680✔
446
        config.mongodb.user = process.env.IOTA_MONGO_USER;
64✔
447
    }
448

449
    if (process.env.IOTA_MONGO_PASSWORD) {
1,680✔
450
        config.mongodb.password = process.env.IOTA_MONGO_PASSWORD;
64✔
451
    }
452

453
    if (process.env.IOTA_MONGO_AUTH_SOURCE) {
1,680✔
454
        config.mongodb.authSource = process.env.IOTA_MONGO_AUTH_SOURCE;
64✔
455
    }
456

457
    if (process.env.IOTA_MONGO_RETRIES) {
1,680✔
458
        config.mongodb.retries = process.env.IOTA_MONGO_RETRIES;
64✔
459
    }
460

461
    if (process.env.IOTA_MONGO_RETRY_TIME) {
1,680✔
462
        config.mongodb.retryTime = process.env.IOTA_MONGO_RETRY_TIME;
64✔
463
    }
464

465
    if (process.env.IOTA_MONGO_SSL) {
1,680✔
466
        config.mongodb.ssl = process.env.IOTA_MONGO_SSL.toLowerCase() === 'true';
28✔
467
    }
468

469
    if (process.env.IOTA_MONGO_EXTRAARGS) {
1,680✔
470
        try {
24✔
471
            const ea = JSON.parse(process.env.IOTA_MONGO_EXTRAARGS);
24✔
472
            if (ea !== null && typeof ea === 'object' && ea.constructor === Object) {
20✔
473
                config.mongodb.extraArgs = ea;
16✔
474
            }
475
        } catch (e) {
476
            // Do nothing
477
        }
478
    }
479

480
    if (process.env.IOTA_POLLING_EXPIRATION) {
1,680!
UNCOV
481
        config.pollingExpiration = process.env.IOTA_POLLING_EXPIRATION;
×
482
    }
483

484
    if (process.env.IOTA_POLLING_DAEMON_FREQ) {
1,680!
UNCOV
485
        config.pollingDaemonFrequency = process.env.IOTA_POLLING_DAEMON_FREQ;
×
486
    }
487

488
    if (process.env.IOTA_MULTI_CORE) {
1,680✔
489
        config.multiCore = process.env.IOTA_MULTI_CORE === 'true';
4✔
490
    } else {
491
        config.multiCore = config.multiCore === true;
1,676✔
492
    }
493

494
    if (process.env.IOTA_RELAX_TEMPLATE_VALIDATION) {
1,680!
UNCOV
495
        config.relaxTemplateValidation = process.env.IOTA_RELAX_TEMPLATE_VALIDATION === 'true';
×
496
    } else {
497
        config.relaxTemplateValidation = config.relaxTemplateValidation === true;
1,680✔
498
    }
499
    if (process.env.IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION) {
1,680!
UNCOV
500
        config.defaultEntityNameConjunction = process.env.IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION;
×
501
    } else {
502
        config.defaultEntityNameConjunction = config.defaultEntityNameConjunction
1,680✔
503
            ? config.defaultEntityNameConjunction
504
            : ':';
505
    }
506
    if (process.env.IOTA_EXPRESS_LIMIT) {
1,680!
UNCOV
507
        config.expressLimit = process.env.IOTA_EXPRESS_LIMIT;
×
508
    } else {
509
        config.expressLimit = config.expressLimit ? config.expressLimit : '1mb';
1,680✔
510
    }
511
    if (process.env.IOTA_USE_CB_FLOW_CONTROL) {
1,680!
UNCOV
512
        config.useCBflowControl = process.env.IOTA_USE_CB_FLOW_CONTROL === 'true';
×
513
    } else {
514
        config.useCBflowControl = config.useCBflowControl === true;
1,680✔
515
    }
516
    if (process.env.IOTA_STORE_LAST_MEASURE) {
1,680!
UNCOV
517
        config.storeLastMeasure = process.env.IOTA_STORE_LAST_MEASURE === 'true';
×
518
    } else {
519
        config.storeLastMeasure = config.storeLastMeasure === true;
1,680✔
520
    }
521
    if (process.env.IOTA_CMD_MODE) {
1,680!
UNCOV
522
        config.cmdMode = process.env.IOTA_CMD_MODE;
×
523
    }
524

525
    if (process.env.IOTA_HEALTH_CHECK_INTERVAL) {
1,680✔
526
        config.healthCheckInterval = process.env.IOTA_HEALTH_CHECK_INTERVAL;
8✔
527
    } else {
528
        config.healthCheckInterval = config.healthCheckInterval ? config.healthCheckInterval : 20000;
1,672✔
529
    }
530
    if (process.env.IOTA_HEALTH_CHECK_TIMEOUT) {
1,680✔
531
        config.healthCheckTimeout = process.env.IOTA_HEALTH_CHECK_TIMEOUT;
8✔
532
    } else {
533
        config.healthCheckTimeout = config.healthCheckTimeout ? config.healthCheckTimeout : 1500;
1,672✔
534
    }
535
    if (process.env.IOTA_HEALTH_CHECK_DOWN_AFTER_FAILS) {
1,680✔
536
        config.healthCheckDownAfterFails = process.env.IOTA_HEALTH_CHECK_DOWN_AFTER_FAILS;
8✔
537
    } else {
538
        config.healthCheckDownAfterFails = config.healthCheckDownAfterFails ? config.healthCheckDownAfterFails : 3;
1,672✔
539
    }
540
    if (process.env.IOTA_HEALTH_CHECK_CONSIDER_HTTP_RESPONSE_UP) {
1,680✔
541
        config.healthCheckConsiderHttpResponseUp = process.env.IOTA_HEALTH_CHECK_CONSIDER_HTTP_RESPONSE_UP === 'true';
8✔
542
    } else {
543
        config.healthCheckConsiderHttpResponseUp = config.healthCheckConsiderHttpResponseUp === true;
1,672✔
544
    }
545
}
546

547
function setConfig(newConfig) {
548
    config = newConfig;
1,680✔
549

550
    if (config.logLevel) {
1,680✔
551
        logger.setLevel(config.logLevel);
1,030✔
552
    }
553

554
    processEnvironmentVariables();
1,680✔
555
    logAuthState();
1,680✔
556
}
557

558
function getConfig() {
559
    return config;
15,394✔
560
}
561

562
function getConfigForTypeInformation() {
563
    // Just return relevant configuration flags
564
    // avoid to include server, authentication, mongodb, orion and iotamanger info
565
    const conf = {
315✔
566
        timestamp: config.timestamp,
567
        defaultResource: config.defaultResource,
568
        explicitAttrs: config.explicitAttrs,
569
        pollingExpiration: config.pollingExpiration,
570
        pollingDaemonFrequency: config.pollingDaemonFrequency,
571
        multiCore: config.multiCore,
572
        relaxTemplateValidation: config.relaxTemplateValidation,
573
        defaultEntityNameConjunction: config.defaultEntityNameConjunction,
574
        defaultType: config.defaultType,
575
        useCBflowControl: config.useCBflowControl,
576
        storeLastMeasure: config.storeLastMeasure
577
    };
578
    return conf;
315✔
579
}
580

581
function setRegistry(newRegistry) {
582
    registry = newRegistry;
812✔
583
}
584

585
function getRegistry() {
586
    return registry;
1,907✔
587
}
588

589
function setGroupRegistry(newGroupRegistry) {
590
    groupRegistry = newGroupRegistry;
812✔
591
}
592

593
function getGroupRegistry() {
594
    return groupRegistry;
2,989✔
595
}
596

597
function setCommandRegistry(newCommandRegistry) {
598
    commandRegistry = newCommandRegistry;
812✔
599
}
600

601
function getCommandRegistry() {
602
    return commandRegistry;
260✔
603
}
604

605
/**
606
 * Returns the supported NGSI format
607
 *
608
 * @return     {string}  the supported NGSI format
609
 */
610
function ngsiVersion() {
611
    if (config && config.contextBroker && config.contextBroker.ngsiVersion) {
4,424✔
612
        return config.contextBroker.ngsiVersion.toLowerCase();
3,594✔
613
    }
614
    return 'unknown';
830✔
615
}
616

617
/**
618
 * It checks if a combination of typeInformation or common Config is LD
619
 *
620
 * @return     {boolean}  Result of the checking
621
 */
622
function checkNgsiLD(typeInformation) {
623
    const format = typeInformation.ngsiVersion || ngsiVersion();
605✔
624
    return format.toLowerCase() === 'ld';
605✔
625
}
626

627
function setSecurityService(newSecurityService) {
628
    securityService = newSecurityService;
812✔
629
}
630

631
function getSecurityService() {
632
    return securityService;
54✔
633
}
634

635
exports.setConfig = setConfig;
1✔
636
exports.getConfig = getConfig;
1✔
637
exports.getConfigForTypeInformation = getConfigForTypeInformation;
1✔
638
exports.setRegistry = setRegistry;
1✔
639
exports.getRegistry = getRegistry;
1✔
640
exports.setGroupRegistry = setGroupRegistry;
1✔
641
exports.getGroupRegistry = getGroupRegistry;
1✔
642
exports.setCommandRegistry = setCommandRegistry;
1✔
643
exports.getCommandRegistry = getCommandRegistry;
1✔
644
exports.ngsiVersion = ngsiVersion;
1✔
645
exports.checkNgsiLD = checkNgsiLD;
1✔
646
exports.setSecurityService = setSecurityService;
1✔
647
exports.getSecurityService = getSecurityService;
1✔
648
exports.getSecretData = getSecretData;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc