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

telefonicaid / iotagent-node-lib / 18165933486

01 Oct 2025 02:42PM UTC coverage: 79.318% (-0.001%) from 79.319%
18165933486

Pull #1734

github

web-flow
Merge 04824d46d into fd0c311cb
Pull Request #1734: allow use commands by simple subscriptions/notifications

2038 of 2743 branches covered (74.3%)

Branch coverage included in aggregate %.

89 of 110 new or added lines in 10 files covered. (80.91%)

10 existing lines in 1 file now uncovered.

3914 of 4761 relevant lines covered (82.21%)

281.13 hits per line

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

81.24
/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]]) {
29,222✔
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_HOST',
177
        'IOTA_MONGO_PORT',
178
        'IOTA_MONGO_DB',
179
        'IOTA_MONGO_REPLICASET',
180
        'IOTA_MONGO_USER',
181
        'IOTA_MONGO_PASSWORD',
182
        'IOTA_MONGO_AUTH_SOURCE',
183
        'IOTA_MONGO_RETRIES',
184
        'IOTA_MONGO_RETRY_TIME',
185
        'IOTA_MONGO_SSL',
186
        'IOTA_MONGO_EXTRAARGS'
187
    ];
188
    const protectedVariables = [
1,664✔
189
        'IOTA_AUTH_USER',
190
        'IOTA_AUTH_PASSWORD',
191
        'IOTA_AUTH_CLIENT_ID',
192
        'IOTA_AUTH_CLIENT_SECRET',
193
        'IOTA_MONGO_USER',
194
        'IOTA_MONGO_PASSWORD'
195
    ];
196

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

412
    if (process.env.IOTA_MONGO_HOST) {
1,664✔
413
        config.mongodb.host = process.env.IOTA_MONGO_HOST;
70✔
414
    }
415

416
    if (process.env.IOTA_MONGO_PORT) {
1,664✔
417
        config.mongodb.port = process.env.IOTA_MONGO_PORT;
70✔
418
    }
419

420
    if (process.env.IOTA_MONGO_DB) {
1,664✔
421
        config.mongodb.db = process.env.IOTA_MONGO_DB;
70✔
422
    }
423

424
    if (process.env.IOTA_MONGO_REPLICASET) {
1,664✔
425
        config.mongodb.replicaSet = process.env.IOTA_MONGO_REPLICASET;
70✔
426
    }
427

428
    if (process.env.IOTA_MONGO_USER) {
1,664✔
429
        config.mongodb.user = process.env.IOTA_MONGO_USER;
64✔
430
    }
431

432
    if (process.env.IOTA_MONGO_PASSWORD) {
1,664✔
433
        config.mongodb.password = process.env.IOTA_MONGO_PASSWORD;
64✔
434
    }
435

436
    if (process.env.IOTA_MONGO_AUTH_SOURCE) {
1,664✔
437
        config.mongodb.authSource = process.env.IOTA_MONGO_AUTH_SOURCE;
64✔
438
    }
439

440
    if (process.env.IOTA_MONGO_RETRIES) {
1,664✔
441
        config.mongodb.retries = process.env.IOTA_MONGO_RETRIES;
64✔
442
    }
443

444
    if (process.env.IOTA_MONGO_RETRY_TIME) {
1,664✔
445
        config.mongodb.retryTime = process.env.IOTA_MONGO_RETRY_TIME;
64✔
446
    }
447

448
    if (process.env.IOTA_MONGO_SSL) {
1,664✔
449
        config.mongodb.ssl = process.env.IOTA_MONGO_SSL.toLowerCase() === 'true';
28✔
450
    }
451

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

463
    if (process.env.IOTA_POLLING_EXPIRATION) {
1,664!
464
        config.pollingExpiration = process.env.IOTA_POLLING_EXPIRATION;
×
465
    }
466

467
    if (process.env.IOTA_POLLING_DAEMON_FREQ) {
1,664!
468
        config.pollingDaemonFrequency = process.env.IOTA_POLLING_DAEMON_FREQ;
×
469
    }
470

471
    if (process.env.IOTA_MULTI_CORE) {
1,664✔
472
        config.multiCore = process.env.IOTA_MULTI_CORE === 'true';
4✔
473
    } else {
474
        config.multiCore = config.multiCore === true;
1,660✔
475
    }
476

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

509
function setConfig(newConfig) {
510
    config = newConfig;
1,664✔
511

512
    if (config.logLevel) {
1,664✔
513
        logger.setLevel(config.logLevel);
1,014✔
514
    }
515

516
    processEnvironmentVariables();
1,664✔
517
    logAuthState();
1,664✔
518
}
519

520
function getConfig() {
521
    return config;
15,101✔
522
}
523

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

543
function setRegistry(newRegistry) {
544
    registry = newRegistry;
804✔
545
}
546

547
function getRegistry() {
548
    return registry;
1,905✔
549
}
550

551
function setGroupRegistry(newGroupRegistry) {
552
    groupRegistry = newGroupRegistry;
804✔
553
}
554

555
function getGroupRegistry() {
556
    return groupRegistry;
2,657✔
557
}
558

559
function setCommandRegistry(newCommandRegistry) {
560
    commandRegistry = newCommandRegistry;
804✔
561
}
562

563
function getCommandRegistry() {
564
    return commandRegistry;
264✔
565
}
566

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

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

589
function setSecurityService(newSecurityService) {
590
    securityService = newSecurityService;
804✔
591
}
592

593
function getSecurityService() {
594
    return securityService;
54✔
595
}
596

597
exports.setConfig = setConfig;
1✔
598
exports.getConfig = getConfig;
1✔
599
exports.getConfigForTypeInformation = getConfigForTypeInformation;
1✔
600
exports.setRegistry = setRegistry;
1✔
601
exports.getRegistry = getRegistry;
1✔
602
exports.setGroupRegistry = setGroupRegistry;
1✔
603
exports.getGroupRegistry = getGroupRegistry;
1✔
604
exports.setCommandRegistry = setCommandRegistry;
1✔
605
exports.getCommandRegistry = getCommandRegistry;
1✔
606
exports.ngsiVersion = ngsiVersion;
1✔
607
exports.checkNgsiLD = checkNgsiLD;
1✔
608
exports.setSecurityService = setSecurityService;
1✔
609
exports.getSecurityService = getSecurityService;
1✔
610
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