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

telefonicaid / iotagent-node-lib / 18585610203

17 Oct 2025 07:22AM UTC coverage: 79.285% (+0.004%) from 79.281%
18585610203

Pull #1742

github

web-flow
Merge ba0105e1d into 53c57b6eb
Pull Request #1742: add mongo uri

2042 of 2753 branches covered (74.17%)

Branch coverage included in aggregate %.

37 of 42 new or added lines in 2 files covered. (88.1%)

1 existing line in 1 file now uncovered.

3925 of 4773 relevant lines covered (82.23%)

281.31 hits per line

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

80.94
/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,328✔
56
        if (process.env[variableSet[i]]) {
30,886✔
57
            return true;
76✔
58
        }
59
    }
60

61
    return false;
3,252✔
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'];
9,984✔
69
    if (filepath) {
9,984!
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,664✔
79
    if (config.authentication === undefined) {
1,664✔
80
        logger.warn(
1,570✔
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,664✔
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
    ];
166
    const iotamVariables = [
1,664✔
167
        'IOTA_IOTAM_URL',
168
        'IOTA_IOTAM_HOST',
169
        'IOTA_IOTAM_PORT',
170
        'IOTA_IOTAM_PATH',
171
        'IOTA_IOTAM_PROTOCOL',
172
        'IOTA_IOTAM_DESCRIPTION',
173
        'IOTA_IOTAM_AGENTPATH'
174
    ];
175
    const mongoVariables = [
1,664✔
176
        'IOTA_MONGO_URI',
177
        'IOTA_MONGO_HOST',
178
        'IOTA_MONGO_PORT',
179
        'IOTA_MONGO_DB',
180
        'IOTA_MONGO_REPLICASET',
181
        'IOTA_MONGO_USER',
182
        'IOTA_MONGO_PASSWORD',
183
        'IOTA_MONGO_AUTH_SOURCE',
184
        'IOTA_MONGO_RETRIES',
185
        'IOTA_MONGO_RETRY_TIME',
186
        'IOTA_MONGO_SSL',
187
        'IOTA_MONGO_EXTRAARGS'
188
    ];
189
    const protectedVariables = [
1,664✔
190
        'IOTA_AUTH_USER',
191
        'IOTA_AUTH_PASSWORD',
192
        'IOTA_AUTH_CLIENT_ID',
193
        'IOTA_AUTH_CLIENT_SECRET',
194
        'IOTA_MONGO_USER',
195
        'IOTA_MONGO_PASSWORD'
196
    ];
197

198
    // Substitute Docker Secret Variables where set.
199
    protectedVariables.forEach((key) => {
1,664✔
200
        getSecretData(key);
9,984✔
201
    });
202
    environmentVariables.forEach((key) => {
1,664✔
203
        let value = process.env[key];
88,192✔
204
        if (value) {
88,192✔
205
            if (
721✔
206
                key.endsWith('USER') ||
2,552✔
207
                key.endsWith('PASSWORD') ||
208
                key.endsWith('CLIENT_ID') ||
209
                key.endsWith('CLIENT_SECRET')
210
            ) {
211
                value = '********';
136✔
212
            }
213
            logger.info('Setting %s to environment value: %s', key, value);
721✔
214
        }
215
    });
216

217
    // Context Broker Configuration (ensuring the configuration sub-object exists before start using it)
218
    if (config.contextBroker === undefined) {
1,664!
219
        config.contextBroker = {};
×
220
    }
221

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

242
    if (process.env.IOTA_CB_NGSI_VERSION) {
1,664✔
243
        config.contextBroker.ngsiVersion = process.env.IOTA_CB_NGSI_VERSION;
4✔
244
    }
245

246
    if (process.env.IOTA_JSON_LD_CONTEXT) {
1,664✔
247
        config.contextBroker.jsonLdContext = process.env.IOTA_JSON_LD_CONTEXT.split(',').map((ctx) => ctx.trim());
8✔
248
    }
249

250
    if (Array.isArray(config.contextBroker.jsonLdContext) && config.contextBroker.jsonLdContext.length === 1) {
1,664✔
251
        config.contextBroker.jsonLdContext = config.contextBroker.jsonLdContext[0];
3✔
252
    }
253

254
    config.contextBroker.fallbackTenant =
1,664✔
255
        process.env.IOTA_FALLBACK_TENANT || config.contextBroker.service || 'iotagent';
4,988✔
256
    config.contextBroker.fallbackPath = process.env.IOTA_FALLBACK_PATH || config.contextBroker.subservice || '/';
1,664✔
257

258
    // North Port Configuration (ensuring the configuration sub-object exists before start using it)
259
    if (config.server === undefined) {
1,664!
260
        config.server = {};
×
261
    }
262

263
    if (process.env.IOTA_NORTH_HOST) {
1,664✔
264
        config.server.host = process.env.IOTA_NORTH_HOST;
6✔
265
    }
266
    if (process.env.IOTA_NORTH_PORT) {
1,664✔
267
        config.server.port = process.env.IOTA_NORTH_PORT;
6✔
268
    }
269

270
    config.server.ldSupport = config.server.ldSupport || {
1,664✔
271
        null: true,
272
        datasetId: true,
273
        merge: false,
274
        dataType: 'none'
275
    };
276

277
    if (process.env.IOTA_LD_SUPPORT_NULL) {
1,664✔
278
        config.server.ldSupport.null = process.env.IOTA_LD_SUPPORT_NULL === 'true';
2✔
279
    }
280
    if (process.env.IOTA_LD_SUPPORT_DATASET_ID) {
1,664✔
281
        config.server.ldSupport.datasetId = process.env.IOTA_LD_SUPPORT_DATASET_ID === 'true';
2✔
282
    }
283
    if (process.env.IOTA_LD_SUPPORT_MERGE) {
1,664!
284
        config.server.ldSupport.datasetId = process.env.IOTA_LD_SUPPORT_MERGE === 'true';
×
285
    }
286
    if (process.env.IOTA_LD_SUPPORT_DATA_TYPE) {
1,664✔
287
        config.server.ldSupport.dataType = process.env.IOTA_LD_SUPPORT_DATA_TYPE;
2✔
288
    }
289

290
    if (process.env.IOTA_PROVIDER_URL) {
1,664✔
291
        config.providerUrl = process.env.IOTA_PROVIDER_URL;
6✔
292
    }
293

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

344
    // Registry configuration (memory or database)
345
    config.deviceRegistry = config.deviceRegistry || {};
1,664✔
346
    if (process.env.IOTA_REGISTRY_TYPE) {
1,664✔
347
        config.deviceRegistry.type = process.env.IOTA_REGISTRY_TYPE;
6✔
348
    }
349

350
    // Log Level configuration
351
    if (process.env.IOTA_LOG_LEVEL) {
1,664✔
352
        config.logLevel = process.env.IOTA_LOG_LEVEL;
6✔
353
        logger.setLevel(process.env.IOTA_LOG_LEVEL);
6✔
354
    }
355

356
    // Whether to include timestamps
357
    if (process.env.IOTA_TIMESTAMP) {
1,664✔
358
        config.timestamp = process.env.IOTA_TIMESTAMP === 'true';
6✔
359
    }
360

361
    // Default resource
362
    if (process.env.IOTA_DEFAULT_RESOURCE !== undefined) {
1,664✔
363
        config.defaultResource = process.env.IOTA_DEFAULT_RESOURCE;
6✔
364
    }
365

366
    // Default transport
367
    if (process.env.IOTA_DEFAULT_TRANSPORT !== undefined) {
1,664!
368
        config.defaultTransport = process.env.IOTA_DEFAULT_TRANSPORT;
×
369
    }
370

371
    // Default explicitAttrs
372
    if (process.env.IOTA_EXPLICIT_ATTRS !== undefined) {
1,664!
373
        config.explicitAttrs = process.env.IOTA_EXPLICIT_ATTRS;
×
374
    }
375

376
    // IoT Manager Configuration
377
    if (anyIsSet(iotamVariables)) {
1,664✔
378
        config.iotManager = {};
6✔
379
    }
380

381
    if (process.env.IOTA_IOTAM_URL) {
1,664!
382
        config.iotManager.url = process.env.IOTA_IOTAM_URL;
×
383
    } else if (process.env.IOTA_IOTAM_HOST) {
1,664✔
384
        config.iotManager.url = 'http://' + process.env.IOTA_IOTAM_HOST;
6✔
385
        if (process.env.IOTA_IOTAM_PORT) {
6!
386
            config.iotManager.url += ':' + process.env.IOTA_IOTAM_PORT;
6✔
387
        } else {
388
            config.iotManager.url += ':' + config.iotManager.port;
×
389
        }
390
    }
391

392
    if (process.env.IOTA_IOTAM_PATH) {
1,664✔
393
        config.iotManager.path = process.env.IOTA_IOTAM_PATH;
6✔
394
    }
395

396
    if (process.env.IOTA_IOTAM_PROTOCOL) {
1,664✔
397
        config.iotManager.protocol = process.env.IOTA_IOTAM_PROTOCOL;
6✔
398
    }
399

400
    if (process.env.IOTA_IOTAM_DESCRIPTION) {
1,664✔
401
        config.iotManager.description = process.env.IOTA_IOTAM_DESCRIPTION;
6✔
402
    }
403

404
    if (process.env.IOTA_IOTAM_AGENTPATH) {
1,664!
405
        config.iotManager.agentPath = process.env.IOTA_IOTAM_AGENTPATH;
×
406
    }
407

408
    // Mongo DB configuration
409
    if (anyIsSet(mongoVariables)) {
1,664✔
410
        config.mongodb = {};
70✔
411
    }
412

413
    if (process.env.IOTA_MONGO_URI) {
1,664!
NEW
414
        config.mongodb.uri = process.env.IOTA_MONGO_URI;
×
415
    }
416

417
    if (process.env.IOTA_MONGO_HOST) {
1,664✔
418
        config.mongodb.host = process.env.IOTA_MONGO_HOST;
70✔
419
    }
420

421
    if (process.env.IOTA_MONGO_PORT) {
1,664✔
422
        config.mongodb.port = process.env.IOTA_MONGO_PORT;
70✔
423
    }
424

425
    if (process.env.IOTA_MONGO_DB) {
1,664✔
426
        config.mongodb.db = process.env.IOTA_MONGO_DB;
70✔
427
    }
428

429
    if (process.env.IOTA_MONGO_REPLICASET) {
1,664✔
430
        config.mongodb.replicaSet = process.env.IOTA_MONGO_REPLICASET;
70✔
431
    }
432

433
    if (process.env.IOTA_MONGO_USER) {
1,664✔
434
        config.mongodb.user = process.env.IOTA_MONGO_USER;
64✔
435
    }
436

437
    if (process.env.IOTA_MONGO_PASSWORD) {
1,664✔
438
        config.mongodb.password = process.env.IOTA_MONGO_PASSWORD;
64✔
439
    }
440

441
    if (process.env.IOTA_MONGO_AUTH_SOURCE) {
1,664✔
442
        config.mongodb.authSource = process.env.IOTA_MONGO_AUTH_SOURCE;
64✔
443
    }
444

445
    if (process.env.IOTA_MONGO_RETRIES) {
1,664✔
446
        config.mongodb.retries = process.env.IOTA_MONGO_RETRIES;
64✔
447
    }
448

449
    if (process.env.IOTA_MONGO_RETRY_TIME) {
1,664✔
450
        config.mongodb.retryTime = process.env.IOTA_MONGO_RETRY_TIME;
64✔
451
    }
452

453
    if (process.env.IOTA_MONGO_SSL) {
1,664✔
454
        config.mongodb.ssl = process.env.IOTA_MONGO_SSL.toLowerCase() === 'true';
28✔
455
    }
456

457
    if (process.env.IOTA_MONGO_EXTRAARGS) {
1,664✔
458
        try {
24✔
459
            const ea = JSON.parse(process.env.IOTA_MONGO_EXTRAARGS);
24✔
460
            if (ea !== null && typeof ea === 'object' && ea.constructor === Object) {
20✔
461
                config.mongodb.extraArgs = ea;
16✔
462
            }
463
        } catch (e) {
464
            // Do nothing
465
        }
466
    }
467

468
    if (process.env.IOTA_POLLING_EXPIRATION) {
1,664!
469
        config.pollingExpiration = process.env.IOTA_POLLING_EXPIRATION;
×
470
    }
471

472
    if (process.env.IOTA_POLLING_DAEMON_FREQ) {
1,664!
473
        config.pollingDaemonFrequency = process.env.IOTA_POLLING_DAEMON_FREQ;
×
474
    }
475

476
    if (process.env.IOTA_MULTI_CORE) {
1,664✔
477
        config.multiCore = process.env.IOTA_MULTI_CORE === 'true';
4✔
478
    } else {
479
        config.multiCore = config.multiCore === true;
1,660✔
480
    }
481

482
    if (process.env.IOTA_RELAX_TEMPLATE_VALIDATION) {
1,664!
483
        config.relaxTemplateValidation = process.env.IOTA_RELAX_TEMPLATE_VALIDATION === 'true';
×
484
    } else {
485
        config.relaxTemplateValidation = config.relaxTemplateValidation === true;
1,664✔
486
    }
487
    if (process.env.IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION) {
1,664!
488
        config.defaultEntityNameConjunction = process.env.IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION;
×
489
    } else {
490
        config.defaultEntityNameConjunction = config.defaultEntityNameConjunction
1,664✔
491
            ? config.defaultEntityNameConjunction
492
            : ':';
493
    }
494
    if (process.env.IOTA_EXPRESS_LIMIT) {
1,664!
495
        config.expressLimit = process.env.IOTA_EXPRESS_LIMIT;
×
496
    } else {
497
        config.expressLimit = config.expressLimit ? config.expressLimit : '1mb';
1,664✔
498
    }
499
    if (process.env.IOTA_USE_CB_FLOW_CONTROL) {
1,664!
500
        config.useCBflowControl = process.env.IOTA_USE_CB_FLOW_CONTROL === 'true';
×
501
    } else {
502
        config.useCBflowControl = config.useCBflowControl === true;
1,664✔
503
    }
504
    if (process.env.IOTA_STORE_LAST_MEASURE) {
1,664!
505
        config.storeLastMeasure = process.env.IOTA_STORE_LAST_MEASURE === 'true';
×
506
    } else {
507
        config.storeLastMeasure = config.storeLastMeasure === true;
1,664✔
508
    }
509
    if (process.env.IOTA_CMD_MODE) {
1,664!
510
        config.cmdMode = process.env.IOTA_CMD_MODE;
×
511
    }
512
}
513

514
function setConfig(newConfig) {
515
    config = newConfig;
1,664✔
516

517
    if (config.logLevel) {
1,664✔
518
        logger.setLevel(config.logLevel);
1,014✔
519
    }
520

521
    processEnvironmentVariables();
1,664✔
522
    logAuthState();
1,664✔
523
}
524

525
function getConfig() {
526
    return config;
15,109✔
527
}
528

529
function getConfigForTypeInformation() {
530
    // Just return relevant configuration flags
531
    // avoid to include server, authentication, mongodb, orion and iotamanger info
532
    const conf = {
313✔
533
        timestamp: config.timestamp,
534
        defaultResource: config.defaultResource,
535
        explicitAttrs: config.explicitAttrs,
536
        pollingExpiration: config.pollingExpiration,
537
        pollingDaemonFrequency: config.pollingDaemonFrequency,
538
        multiCore: config.multiCore,
539
        relaxTemplateValidation: config.relaxTemplateValidation,
540
        defaultEntityNameConjunction: config.defaultEntityNameConjunction,
541
        defaultType: config.defaultType,
542
        useCBflowControl: config.useCBflowControl,
543
        storeLastMeasure: config.storeLastMeasure
544
    };
545
    return conf;
313✔
546
}
547

548
function setRegistry(newRegistry) {
549
    registry = newRegistry;
804✔
550
}
551

552
function getRegistry() {
553
    return registry;
1,905✔
554
}
555

556
function setGroupRegistry(newGroupRegistry) {
557
    groupRegistry = newGroupRegistry;
804✔
558
}
559

560
function getGroupRegistry() {
561
    return groupRegistry;
2,657✔
562
}
563

564
function setCommandRegistry(newCommandRegistry) {
565
    commandRegistry = newCommandRegistry;
804✔
566
}
567

568
function getCommandRegistry() {
569
    return commandRegistry;
262✔
570
}
571

572
/**
573
 * Returns the supported NGSI format
574
 *
575
 * @return     {string}  the supported NGSI format
576
 */
577
function ngsiVersion() {
578
    if (config && config.contextBroker && config.contextBroker.ngsiVersion) {
4,388✔
579
        return config.contextBroker.ngsiVersion.toLowerCase();
3,582✔
580
    }
581
    return 'unknown';
806✔
582
}
583

584
/**
585
 * It checks if a combination of typeInformation or common Config is LD
586
 *
587
 * @return     {boolean}  Result of the checking
588
 */
589
function checkNgsiLD(typeInformation) {
590
    const format = typeInformation.ngsiVersion || ngsiVersion();
601✔
591
    return format.toLowerCase() === 'ld';
601✔
592
}
593

594
function setSecurityService(newSecurityService) {
595
    securityService = newSecurityService;
804✔
596
}
597

598
function getSecurityService() {
599
    return securityService;
54✔
600
}
601

602
exports.setConfig = setConfig;
1✔
603
exports.getConfig = getConfig;
1✔
604
exports.getConfigForTypeInformation = getConfigForTypeInformation;
1✔
605
exports.setRegistry = setRegistry;
1✔
606
exports.getRegistry = getRegistry;
1✔
607
exports.setGroupRegistry = setGroupRegistry;
1✔
608
exports.getGroupRegistry = getGroupRegistry;
1✔
609
exports.setCommandRegistry = setCommandRegistry;
1✔
610
exports.getCommandRegistry = getCommandRegistry;
1✔
611
exports.ngsiVersion = ngsiVersion;
1✔
612
exports.checkNgsiLD = checkNgsiLD;
1✔
613
exports.setSecurityService = setSecurityService;
1✔
614
exports.getSecurityService = getSecurityService;
1✔
615
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