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

telefonicaid / iotagent-node-lib / 18746791456

23 Oct 2025 11:25AM UTC coverage: 79.305% (+0.004%) from 79.301%
18746791456

Pull #1742

github

web-flow
Merge 6f0ea7b67 into c75a87805
Pull Request #1742: add mongo uri

2046 of 2757 branches covered (74.21%)

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.

3932 of 4781 relevant lines covered (82.24%)

280.85 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
        // FIXME: the following IOTA_MONGO_ env vars are deprecated and will
178
        // be eventually removed (use IOTA_MONGO_URI)
179
        'IOTA_MONGO_HOST',
180
        'IOTA_MONGO_PORT',
181
        'IOTA_MONGO_DB',
182
        'IOTA_MONGO_REPLICASET',
183
        'IOTA_MONGO_USER',
184
        'IOTA_MONGO_PASSWORD',
185
        'IOTA_MONGO_AUTH_SOURCE',
186
        'IOTA_MONGO_RETRIES',
187
        'IOTA_MONGO_RETRY_TIME',
188
        'IOTA_MONGO_SSL',
189
        'IOTA_MONGO_EXTRAARGS'
190
    ];
191
    const protectedVariables = [
1,664✔
192
        'IOTA_AUTH_USER',
193
        'IOTA_AUTH_PASSWORD',
194
        'IOTA_AUTH_CLIENT_ID',
195
        'IOTA_AUTH_CLIENT_SECRET',
196
        'IOTA_MONGO_USER',
197
        'IOTA_MONGO_PASSWORD'
198
    ];
199

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

516
function setConfig(newConfig) {
517
    config = newConfig;
1,664✔
518

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

523
    processEnvironmentVariables();
1,664✔
524
    logAuthState();
1,664✔
525
}
526

527
function getConfig() {
528
    return config;
15,111✔
529
}
530

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

550
function setRegistry(newRegistry) {
551
    registry = newRegistry;
804✔
552
}
553

554
function getRegistry() {
555
    return registry;
1,905✔
556
}
557

558
function setGroupRegistry(newGroupRegistry) {
559
    groupRegistry = newGroupRegistry;
804✔
560
}
561

562
function getGroupRegistry() {
563
    return groupRegistry;
2,657✔
564
}
565

566
function setCommandRegistry(newCommandRegistry) {
567
    commandRegistry = newCommandRegistry;
804✔
568
}
569

570
function getCommandRegistry() {
571
    return commandRegistry;
263✔
572
}
573

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

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

596
function setSecurityService(newSecurityService) {
597
    securityService = newSecurityService;
804✔
598
}
599

600
function getSecurityService() {
601
    return securityService;
54✔
602
}
603

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

© 2025 Coveralls, Inc