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

telefonicaid / iotagent-node-lib / 23635227181

27 Mar 2026 07:04AM UTC coverage: 79.436% (+0.006%) from 79.43%
23635227181

Pull #1767

github

web-flow
Merge 73a4a0da1 into 9055fa88c
Pull Request #1767: Task/remove old mongodb env vars

2119 of 2856 branches covered (74.19%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 2 files covered. (100.0%)

1 existing line in 1 file now uncovered.

4131 of 5012 relevant lines covered (82.42%)

263.42 hits per line

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

83.46
/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,304✔
56
        if (process.env[variableSet[i]]) {
13,186✔
57
            return true;
48✔
58
        }
59
    }
60

61
    return false;
3,256✔
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'];
6,608✔
69
    if (filepath) {
6,608!
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,652✔
79
    if (config.authentication === undefined) {
1,652✔
80
        logger.warn(
1,558✔
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,652✔
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_POLLING_EXPIRATION',
142
        'IOTA_POLLING_DAEMON_FREQ',
143
        'IOTA_MULTI_CORE',
144
        'IOTA_RELAX_TEMPLATE_VALIDATION',
145
        'IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION',
146
        'IOTA_JSON_LD_CONTEXT',
147
        'IOTA_FALLBACK_TENANT',
148
        'IOTA_FALLBACK_PATH',
149
        'IOTA_LD_SUPPORT_NULL',
150
        'IOTA_LD_SUPPORT_DATASET_ID',
151
        'IOTA_LD_SUPPORT_DATA_TYPE',
152
        'IOTA_EXPRESS_LIMIT',
153
        'IOTA_USE_CB_FLOW_CONTROL',
154
        'IOTA_STORE_LAST_MEASURE',
155
        'IOTA_CMD_MODE',
156
        'IOTA_HEALTH_CHECK',
157
        'IOTA_HEALTH_CHECK_INTERVAL',
158
        'IOTA_HEALTH_CHECK_TIMEOUT',
159
        'IOTA_HEALTH_CHECK_DOWN_AFTER_FAILS',
160
        'IOTA_HEALTH_CHECK_CONSIDER_HTTP_RESPONSE_UP'
161
    ];
162
    const iotamVariables = [
1,652✔
163
        'IOTA_IOTAM_URL',
164
        'IOTA_IOTAM_HOST',
165
        'IOTA_IOTAM_PORT',
166
        'IOTA_IOTAM_PATH',
167
        'IOTA_IOTAM_PROTOCOL',
168
        'IOTA_IOTAM_DESCRIPTION',
169
        'IOTA_IOTAM_AGENTPATH'
170
    ];
171
    const mongoVariables = ['IOTA_MONGO_URI'];
1,652✔
172
    const protectedVariables = [
1,652✔
173
        'IOTA_AUTH_USER',
174
        'IOTA_AUTH_PASSWORD',
175
        'IOTA_AUTH_CLIENT_ID',
176
        'IOTA_AUTH_CLIENT_SECRET'
177
    ];
178

179
    // Substitute Docker Secret Variables where set.
180
    protectedVariables.forEach((key) => {
1,652✔
181
        getSecretData(key);
6,608✔
182
    });
183
    environmentVariables.forEach((key) => {
1,652✔
184
        let value = process.env[key];
80,948✔
185
        if (value) {
80,948✔
186
            if (
215✔
187
                key.endsWith('USER') ||
848✔
188
                key.endsWith('PASSWORD') ||
189
                key.endsWith('CLIENT_ID') ||
190
                key.endsWith('CLIENT_SECRET')
191
            ) {
192
                value = '********';
8✔
193
            }
194
            logger.info('Setting %s to environment value: %s', key, value);
215✔
195
        }
196
    });
197

198
    // Context Broker Configuration (ensuring the configuration sub-object exists before start using it)
199
    if (config.contextBroker === undefined) {
1,652✔
200
        config.contextBroker = {};
1✔
201
    }
202

203
    if (process.env.IOTA_CB_URL) {
1,652!
204
        config.contextBroker.url = process.env.IOTA_CB_URL;
×
205
        // Not sure if config.contextBroker.host and config.contextBroker.port are used
206
        // in this case, but better to have them initialized
207
        if (process.env.IOTA_CB_HOST) {
×
208
            config.contextBroker.host = process.env.IOTA_CB_HOST;
×
209
        }
210
        if (process.env.IOTA_CB_PORT) {
×
211
            config.contextBroker.port = process.env.IOTA_CB_PORT;
×
212
        }
213
    } else if (process.env.IOTA_CB_HOST) {
1,652✔
214
        config.contextBroker.host = process.env.IOTA_CB_HOST;
8✔
215
        config.contextBroker.url = 'http://' + process.env.IOTA_CB_HOST;
8✔
216
        if (process.env.IOTA_CB_PORT) {
8✔
217
            config.contextBroker.url += ':' + process.env.IOTA_CB_PORT;
6✔
218
        } else {
219
            config.contextBroker.url += ':' + config.contextBroker.port;
2✔
220
        }
221
    }
222

223
    if (process.env.IOTA_CB_NGSI_VERSION) {
1,652✔
224
        config.contextBroker.ngsiVersion = process.env.IOTA_CB_NGSI_VERSION;
4✔
225
    }
226

227
    if (process.env.IOTA_JSON_LD_CONTEXT) {
1,652✔
228
        config.contextBroker.jsonLdContext = process.env.IOTA_JSON_LD_CONTEXT.split(',').map((ctx) => ctx.trim());
8✔
229
    }
230

231
    if (Array.isArray(config.contextBroker.jsonLdContext) && config.contextBroker.jsonLdContext.length === 1) {
1,652✔
232
        config.contextBroker.jsonLdContext = config.contextBroker.jsonLdContext[0];
3✔
233
    }
234

235
    config.contextBroker.fallbackTenant =
1,652✔
236
        process.env.IOTA_FALLBACK_TENANT || config.contextBroker.service || 'iotagent';
4,952✔
237
    config.contextBroker.fallbackPath = process.env.IOTA_FALLBACK_PATH || config.contextBroker.subservice || '/';
1,652✔
238

239
    // North Port Configuration (ensuring the configuration sub-object exists before start using it)
240
    if (config.server === undefined) {
1,652!
241
        config.server = {};
×
242
    }
243

244
    if (process.env.IOTA_NORTH_HOST) {
1,652✔
245
        config.server.host = process.env.IOTA_NORTH_HOST;
6✔
246
    }
247
    if (process.env.IOTA_NORTH_PORT) {
1,652✔
248
        config.server.port = process.env.IOTA_NORTH_PORT;
6✔
249
    }
250

251
    config.server.ldSupport = config.server.ldSupport || {
1,652✔
252
        null: true,
253
        datasetId: true,
254
        merge: false,
255
        dataType: 'none'
256
    };
257

258
    if (process.env.IOTA_LD_SUPPORT_NULL) {
1,652✔
259
        config.server.ldSupport.null = process.env.IOTA_LD_SUPPORT_NULL === 'true';
2✔
260
    }
261
    if (process.env.IOTA_LD_SUPPORT_DATASET_ID) {
1,652✔
262
        config.server.ldSupport.datasetId = process.env.IOTA_LD_SUPPORT_DATASET_ID === 'true';
2✔
263
    }
264
    if (process.env.IOTA_LD_SUPPORT_MERGE) {
1,652!
265
        config.server.ldSupport.datasetId = process.env.IOTA_LD_SUPPORT_MERGE === 'true';
×
266
    }
267
    if (process.env.IOTA_LD_SUPPORT_DATA_TYPE) {
1,652✔
268
        config.server.ldSupport.dataType = process.env.IOTA_LD_SUPPORT_DATA_TYPE;
2✔
269
    }
270

271
    if (process.env.IOTA_PROVIDER_URL) {
1,652✔
272
        config.providerUrl = process.env.IOTA_PROVIDER_URL;
6✔
273
    }
274

275
    // Authentication Parameters - General
276
    if (process.env.IOTA_AUTH_ENABLED) {
1,652✔
277
        config.authentication = {};
4✔
278
        config.authentication.enabled = process.env.IOTA_AUTH_ENABLED === 'true';
4✔
279
    }
280
    if (process.env.IOTA_AUTH_TYPE) {
1,652!
281
        config.authentication.type = process.env.IOTA_AUTH_TYPE;
×
282
    }
283
    if (process.env.IOTA_AUTH_HEADER) {
1,652!
284
        config.authentication.header = process.env.IOTA_AUTH_HEADER;
×
285
    }
286
    if (process.env.IOTA_AUTH_URL) {
1,652!
287
        config.authentication.url = process.env.IOTA_AUTH_URL;
×
288
    } else if (process.env.IOTA_AUTH_HOST) {
1,652!
289
        config.authentication.host = process.env.IOTA_AUTH_HOST;
×
290
        config.authentication.url = 'http://' + process.env.IOTA_AUTH_HOST;
×
291
        if (process.env.IOTA_AUTH_PORT) {
×
292
            config.authentication.url += ':' + process.env.IOTA_AUTH_PORT;
×
293
        } else {
294
            config.authentication.url += ':' + config.authentication.port;
×
295
        }
296
    }
297
    if (process.env.IOTA_AUTH_HOST) {
1,652!
298
        config.authentication.host = process.env.IOTA_AUTH_HOST;
×
299
    }
300
    if (process.env.IOTA_AUTH_PORT) {
1,652!
301
        config.authentication.port = process.env.IOTA_AUTH_PORT;
×
302
    }
303
    // Authentication Parameters - Oauth + Keyrock
304
    if (process.env.IOTA_AUTH_CLIENT_ID) {
1,652✔
305
        config.authentication.clientId = process.env.IOTA_AUTH_CLIENT_ID;
2✔
306
    }
307
    if (process.env.IOTA_AUTH_CLIENT_SECRET) {
1,652✔
308
        config.authentication.clientSecret = process.env.IOTA_AUTH_CLIENT_SECRET;
2✔
309
    }
310
    if (process.env.IOTA_AUTH_TOKEN_PATH) {
1,652!
311
        config.authentication.tokenPath = process.env.IOTA_AUTH_TOKEN_PATH;
×
312
    }
313
    // Authentication Parameters - Keyrock only
314
    if (process.env.IOTA_AUTH_PERMANENT_TOKEN) {
1,652!
315
        config.authentication.permanentToken = process.env.IOTA_AUTH_PERMANENT_TOKEN;
×
316
    }
317
    // Authentication Parameters - Keystone only
318
    if (process.env.IOTA_AUTH_USER) {
1,652✔
319
        config.authentication.user = process.env.IOTA_AUTH_USER;
2✔
320
    }
321
    if (process.env.IOTA_AUTH_PASSWORD) {
1,652✔
322
        config.authentication.password = process.env.IOTA_AUTH_PASSWORD;
2✔
323
    }
324

325
    // Registry configuration (memory or database)
326
    config.deviceRegistry = config.deviceRegistry || {};
1,652✔
327
    if (process.env.IOTA_REGISTRY_TYPE) {
1,652✔
328
        config.deviceRegistry.type = process.env.IOTA_REGISTRY_TYPE;
6✔
329
    }
330

331
    // Log Level configuration
332
    if (process.env.IOTA_LOG_LEVEL) {
1,652✔
333
        config.logLevel = process.env.IOTA_LOG_LEVEL;
6✔
334
        logger.setLevel(process.env.IOTA_LOG_LEVEL);
6✔
335
    }
336

337
    // Whether to include timestamps
338
    if (process.env.IOTA_TIMESTAMP) {
1,652✔
339
        config.timestamp = process.env.IOTA_TIMESTAMP === 'true';
6✔
340
    }
341

342
    // Default resource
343
    if (process.env.IOTA_DEFAULT_RESOURCE !== undefined) {
1,652✔
344
        config.defaultResource = process.env.IOTA_DEFAULT_RESOURCE;
6✔
345
    }
346

347
    // Default transport
348
    if (process.env.IOTA_DEFAULT_TRANSPORT !== undefined) {
1,652!
349
        config.defaultTransport = process.env.IOTA_DEFAULT_TRANSPORT;
×
350
    } else {
351
        // defaultTransport is "MQTT" by default even when no ENV VAR is used
352
        // and should be available in iotagent-library to allow
353
        // set polling and transport for autoprovisioned devices
354
        // at lib/services/devices/deviceService.js#L302
355
        config.defaultTransport = 'MQTT';
1,652✔
356
    }
357

358
    // Default explicitAttrs
359
    if (process.env.IOTA_EXPLICIT_ATTRS !== undefined) {
1,652!
360
        config.explicitAttrs = process.env.IOTA_EXPLICIT_ATTRS;
×
361
    }
362

363
    // IoT Manager Configuration
364
    if (anyIsSet(iotamVariables)) {
1,652✔
365
        config.iotManager = {};
6✔
366
    }
367

368
    if (process.env.IOTA_IOTAM_URL) {
1,652!
369
        config.iotManager.url = process.env.IOTA_IOTAM_URL;
×
370
    } else if (process.env.IOTA_IOTAM_HOST) {
1,652✔
371
        config.iotManager.url = 'http://' + process.env.IOTA_IOTAM_HOST;
6✔
372
        if (process.env.IOTA_IOTAM_PORT) {
6!
373
            config.iotManager.url += ':' + process.env.IOTA_IOTAM_PORT;
6✔
374
        } else {
375
            config.iotManager.url += ':' + config.iotManager.port;
×
376
        }
377
    }
378

379
    if (process.env.IOTA_IOTAM_PATH) {
1,652✔
380
        config.iotManager.path = process.env.IOTA_IOTAM_PATH;
6✔
381
    }
382

383
    if (process.env.IOTA_IOTAM_PROTOCOL) {
1,652✔
384
        config.iotManager.protocol = process.env.IOTA_IOTAM_PROTOCOL;
6✔
385
    }
386

387
    if (process.env.IOTA_IOTAM_DESCRIPTION) {
1,652✔
388
        config.iotManager.description = process.env.IOTA_IOTAM_DESCRIPTION;
6✔
389
    }
390

391
    if (process.env.IOTA_IOTAM_AGENTPATH) {
1,652!
392
        config.iotManager.agentPath = process.env.IOTA_IOTAM_AGENTPATH;
×
393
    }
394

395
    // Mongo DB configuration
396
    if (anyIsSet(mongoVariables)) {
1,652✔
397
        config.mongodb = {};
42✔
398
    }
399

400
    if (process.env.IOTA_MONGO_URI) {
1,652✔
401
        config.mongodb.uri = process.env.IOTA_MONGO_URI;
42✔
402
    }
403

404
    if (process.env.IOTA_POLLING_EXPIRATION) {
1,652!
UNCOV
405
        config.pollingExpiration = process.env.IOTA_POLLING_EXPIRATION;
×
406
    }
407

408
    if (process.env.IOTA_POLLING_DAEMON_FREQ) {
1,652!
409
        config.pollingDaemonFrequency = process.env.IOTA_POLLING_DAEMON_FREQ;
×
410
    }
411

412
    if (process.env.IOTA_MULTI_CORE) {
1,652✔
413
        config.multiCore = process.env.IOTA_MULTI_CORE === 'true';
4✔
414
    } else {
415
        config.multiCore = config.multiCore === true;
1,648✔
416
    }
417

418
    if (process.env.IOTA_RELAX_TEMPLATE_VALIDATION) {
1,652✔
419
        config.relaxTemplateValidation = process.env.IOTA_RELAX_TEMPLATE_VALIDATION === 'true';
2✔
420
    } else {
421
        config.relaxTemplateValidation = config.relaxTemplateValidation === true;
1,650✔
422
    }
423
    if (process.env.IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION) {
1,652!
424
        config.defaultEntityNameConjunction = process.env.IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION;
×
425
    } else {
426
        config.defaultEntityNameConjunction = config.defaultEntityNameConjunction
1,652✔
427
            ? config.defaultEntityNameConjunction
428
            : ':';
429
    }
430
    if (process.env.IOTA_EXPRESS_LIMIT) {
1,652✔
431
        config.expressLimit = process.env.IOTA_EXPRESS_LIMIT;
2✔
432
    } else {
433
        config.expressLimit = config.expressLimit ? config.expressLimit : '1mb';
1,650✔
434
    }
435
    if (process.env.IOTA_USE_CB_FLOW_CONTROL) {
1,652✔
436
        config.useCBflowControl = process.env.IOTA_USE_CB_FLOW_CONTROL === 'true';
2✔
437
    } else {
438
        config.useCBflowControl = config.useCBflowControl === true;
1,650✔
439
    }
440
    if (process.env.IOTA_STORE_LAST_MEASURE) {
1,652✔
441
        config.storeLastMeasure = process.env.IOTA_STORE_LAST_MEASURE === 'true';
2✔
442
    } else {
443
        config.storeLastMeasure = config.storeLastMeasure === true;
1,650✔
444
    }
445
    if (process.env.IOTA_CMD_MODE) {
1,652✔
446
        config.cmdMode = process.env.IOTA_CMD_MODE;
2✔
447
    }
448
    if (process.env.IOTA_HEALTH_CHECK) {
1,652✔
449
        config.healthCheck = process.env.IOTA_HEALTH_CHECK === 'true';
52✔
450
    } else {
451
        config.healthCheck = config.healthCheck === true;
1,600✔
452
    }
453
    if (process.env.IOTA_HEALTH_CHECK_INTERVAL) {
1,652✔
454
        config.healthCheckInterval = process.env.IOTA_HEALTH_CHECK_INTERVAL;
8✔
455
    } else {
456
        config.healthCheckInterval = config.healthCheckInterval ? config.healthCheckInterval : 20000;
1,644✔
457
    }
458
    if (process.env.IOTA_HEALTH_CHECK_TIMEOUT) {
1,652✔
459
        config.healthCheckTimeout = process.env.IOTA_HEALTH_CHECK_TIMEOUT;
8✔
460
    } else {
461
        config.healthCheckTimeout = config.healthCheckTimeout ? config.healthCheckTimeout : 1500;
1,644✔
462
    }
463
    if (process.env.IOTA_HEALTH_CHECK_DOWN_AFTER_FAILS) {
1,652✔
464
        config.healthCheckDownAfterFails = process.env.IOTA_HEALTH_CHECK_DOWN_AFTER_FAILS;
8✔
465
    } else {
466
        config.healthCheckDownAfterFails = config.healthCheckDownAfterFails ? config.healthCheckDownAfterFails : 3;
1,644✔
467
    }
468
    if (process.env.IOTA_HEALTH_CHECK_CONSIDER_HTTP_RESPONSE_UP) {
1,652✔
469
        config.healthCheckConsiderHttpResponseUp = process.env.IOTA_HEALTH_CHECK_CONSIDER_HTTP_RESPONSE_UP === 'true';
8✔
470
    } else {
471
        config.healthCheckConsiderHttpResponseUp = config.healthCheckConsiderHttpResponseUp === true;
1,644✔
472
    }
473
}
474

475
function setConfig(newConfig) {
476
    config = newConfig;
1,652✔
477

478
    if (config.logLevel) {
1,652✔
479
        logger.setLevel(config.logLevel);
1,002✔
480
    }
481

482
    processEnvironmentVariables();
1,652✔
483
    logAuthState();
1,652✔
484
}
485

486
function getConfig() {
487
    return config;
14,835✔
488
}
489

490
function getConfigForTypeInformation() {
491
    // Just return relevant configuration flags
492
    // avoid to include server, authentication, mongodb, orion and iotamanger info
493
    const conf = {
315✔
494
        timestamp: config.timestamp,
495
        defaultResource: config.defaultResource,
496
        explicitAttrs: config.explicitAttrs,
497
        pollingExpiration: config.pollingExpiration,
498
        pollingDaemonFrequency: config.pollingDaemonFrequency,
499
        multiCore: config.multiCore,
500
        relaxTemplateValidation: config.relaxTemplateValidation,
501
        defaultEntityNameConjunction: config.defaultEntityNameConjunction,
502
        defaultType: config.defaultType,
503
        useCBflowControl: config.useCBflowControl,
504
        storeLastMeasure: config.storeLastMeasure
505
    };
506
    return conf;
315✔
507
}
508

509
function setRegistry(newRegistry) {
510
    registry = newRegistry;
798✔
511
}
512

513
function getRegistry() {
514
    return registry;
1,907✔
515
}
516

517
function setGroupRegistry(newGroupRegistry) {
518
    groupRegistry = newGroupRegistry;
798✔
519
}
520

521
function getGroupRegistry() {
522
    return groupRegistry;
2,975✔
523
}
524

525
function setCommandRegistry(newCommandRegistry) {
526
    commandRegistry = newCommandRegistry;
798✔
527
}
528

529
function getCommandRegistry() {
530
    return commandRegistry;
262✔
531
}
532

533
/**
534
 * Returns the supported NGSI format
535
 *
536
 * @return     {string}  the supported NGSI format
537
 */
538
function ngsiVersion() {
539
    if (config && config.contextBroker && config.contextBroker.ngsiVersion) {
4,368✔
540
        return config.contextBroker.ngsiVersion.toLowerCase();
3,566✔
541
    }
542
    return 'unknown';
802✔
543
}
544

545
/**
546
 * It checks if a combination of typeInformation or common Config is LD
547
 *
548
 * @return     {boolean}  Result of the checking
549
 */
550
function checkNgsiLD(typeInformation) {
551
    const format = typeInformation.ngsiVersion || ngsiVersion();
605✔
552
    return format.toLowerCase() === 'ld';
605✔
553
}
554

555
function setSecurityService(newSecurityService) {
556
    securityService = newSecurityService;
798✔
557
}
558

559
function getSecurityService() {
560
    return securityService;
54✔
561
}
562

563
exports.setConfig = setConfig;
1✔
564
exports.getConfig = getConfig;
1✔
565
exports.getConfigForTypeInformation = getConfigForTypeInformation;
1✔
566
exports.setRegistry = setRegistry;
1✔
567
exports.getRegistry = getRegistry;
1✔
568
exports.setGroupRegistry = setGroupRegistry;
1✔
569
exports.getGroupRegistry = getGroupRegistry;
1✔
570
exports.setCommandRegistry = setCommandRegistry;
1✔
571
exports.getCommandRegistry = getCommandRegistry;
1✔
572
exports.ngsiVersion = ngsiVersion;
1✔
573
exports.checkNgsiLD = checkNgsiLD;
1✔
574
exports.setSecurityService = setSecurityService;
1✔
575
exports.getSecurityService = getSecurityService;
1✔
576
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