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

telefonicaid / iotagent-node-lib / 12870027355

20 Jan 2025 02:21PM UTC coverage: 79.475% (-0.07%) from 79.54%
12870027355

push

github

web-flow
Merge pull request #1683 from telefonicaid/fix/set_polling_for_autoprovision_devices

set polling for autoprovisioned devices

1937 of 2599 branches covered (74.53%)

Branch coverage included in aggregate %.

9 of 12 new or added lines in 2 files covered. (75.0%)

3724 of 4524 relevant lines covered (82.32%)

283.97 hits per line

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

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

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

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

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

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

239
    if (process.env.IOTA_CB_NGSI_VERSION) {
1,662✔
240
        config.contextBroker.ngsiVersion = process.env.IOTA_CB_NGSI_VERSION;
4✔
241
    }
242

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

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

251
    config.contextBroker.fallbackTenant =
1,662✔
252
        process.env.IOTA_FALLBACK_TENANT || config.contextBroker.service || 'iotagent';
4,982✔
253
    config.contextBroker.fallbackPath = process.env.IOTA_FALLBACK_PATH || config.contextBroker.subservice || '/';
1,662✔
254

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

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

267
    config.server.ldSupport = config.server.ldSupport || { null: true, datasetId: true, merge: false };
1,662✔
268

269
    if (process.env.IOTA_LD_SUPPORT_NULL) {
1,662✔
270
        config.server.ldSupport.null = process.env.IOTA_LD_SUPPORT_NULL === 'true';
2✔
271
    }
272
    if (process.env.IOTA_LD_SUPPORT_DATASET_ID) {
1,662✔
273
        config.server.ldSupport.datasetId = process.env.IOTA_LD_SUPPORT_DATASET_ID === 'true';
2✔
274
    }
275
    if (process.env.IOTA_LD_SUPPORT_MERGE) {
1,662!
276
        config.server.ldSupport.datasetId = process.env.IOTA_LD_SUPPORT_MERGE === 'true';
×
277
    }
278

279
    if (process.env.IOTA_PROVIDER_URL) {
1,662✔
280
        config.providerUrl = process.env.IOTA_PROVIDER_URL;
6✔
281
    }
282

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

333
    // Registry configuration (memory or database)
334
    config.deviceRegistry = config.deviceRegistry || {};
1,662✔
335
    if (process.env.IOTA_REGISTRY_TYPE) {
1,662✔
336
        config.deviceRegistry.type = process.env.IOTA_REGISTRY_TYPE;
6✔
337
    }
338

339
    // Log Level configuration
340
    if (process.env.IOTA_LOG_LEVEL) {
1,662✔
341
        config.logLevel = process.env.IOTA_LOG_LEVEL;
6✔
342
        logger.setLevel(process.env.IOTA_LOG_LEVEL);
6✔
343
    }
344

345
    // Whether to include timestamps
346
    if (process.env.IOTA_TIMESTAMP) {
1,662✔
347
        config.timestamp = process.env.IOTA_TIMESTAMP === 'true';
6✔
348
    }
349

350
    // Default resource
351
    if (process.env.IOTA_DEFAULT_RESOURCE !== undefined) {
1,662✔
352
        config.defaultResource = process.env.IOTA_DEFAULT_RESOURCE;
6✔
353
    }
354

355
    // Default transport
356
    if (process.env.IOTA_DEFAULT_TRANSPORT !== undefined) {
1,662!
NEW
357
        config.defaultTransport = process.env.IOTA_DEFAULT_TRANSPORT;
×
358
    }
359

360
    // Default explicitAttrs
361
    if (process.env.IOTA_EXPLICIT_ATTRS !== undefined) {
1,662!
362
        config.explicitAttrs = process.env.IOTA_EXPLICIT_ATTRS;
×
363
    }
364

365
    // IoT Manager Configuration
366
    if (anyIsSet(iotamVariables)) {
1,662✔
367
        config.iotManager = {};
6✔
368
    }
369

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

381
    if (process.env.IOTA_IOTAM_PATH) {
1,662✔
382
        config.iotManager.path = process.env.IOTA_IOTAM_PATH;
6✔
383
    }
384

385
    if (process.env.IOTA_IOTAM_PROTOCOL) {
1,662✔
386
        config.iotManager.protocol = process.env.IOTA_IOTAM_PROTOCOL;
6✔
387
    }
388

389
    if (process.env.IOTA_IOTAM_DESCRIPTION) {
1,662✔
390
        config.iotManager.description = process.env.IOTA_IOTAM_DESCRIPTION;
6✔
391
    }
392

393
    if (process.env.IOTA_IOTAM_AGENTPATH) {
1,662!
394
        config.iotManager.agentPath = process.env.IOTA_IOTAM_AGENTPATH;
×
395
    }
396

397
    // Mongo DB configuration
398
    if (anyIsSet(mongoVariables)) {
1,662✔
399
        config.mongodb = {};
70✔
400
    }
401

402
    if (process.env.IOTA_MONGO_HOST) {
1,662✔
403
        config.mongodb.host = process.env.IOTA_MONGO_HOST;
70✔
404
    }
405

406
    if (process.env.IOTA_MONGO_PORT) {
1,662✔
407
        config.mongodb.port = process.env.IOTA_MONGO_PORT;
70✔
408
    }
409

410
    if (process.env.IOTA_MONGO_DB) {
1,662✔
411
        config.mongodb.db = process.env.IOTA_MONGO_DB;
70✔
412
    }
413

414
    if (process.env.IOTA_MONGO_REPLICASET) {
1,662✔
415
        config.mongodb.replicaSet = process.env.IOTA_MONGO_REPLICASET;
70✔
416
    }
417

418
    if (process.env.IOTA_MONGO_USER) {
1,662✔
419
        config.mongodb.user = process.env.IOTA_MONGO_USER;
64✔
420
    }
421

422
    if (process.env.IOTA_MONGO_PASSWORD) {
1,662✔
423
        config.mongodb.password = process.env.IOTA_MONGO_PASSWORD;
64✔
424
    }
425

426
    if (process.env.IOTA_MONGO_AUTH_SOURCE) {
1,662✔
427
        config.mongodb.authSource = process.env.IOTA_MONGO_AUTH_SOURCE;
64✔
428
    }
429

430
    if (process.env.IOTA_MONGO_RETRIES) {
1,662✔
431
        config.mongodb.retries = process.env.IOTA_MONGO_RETRIES;
64✔
432
    }
433

434
    if (process.env.IOTA_MONGO_RETRY_TIME) {
1,662✔
435
        config.mongodb.retryTime = process.env.IOTA_MONGO_RETRY_TIME;
64✔
436
    }
437

438
    if (process.env.IOTA_MONGO_SSL) {
1,662✔
439
        config.mongodb.ssl = process.env.IOTA_MONGO_SSL.toLowerCase() === 'true';
28✔
440
    }
441

442
    if (process.env.IOTA_MONGO_EXTRAARGS) {
1,662✔
443
        try {
24✔
444
            const ea = JSON.parse(process.env.IOTA_MONGO_EXTRAARGS);
24✔
445
            if (ea !== null && typeof ea === 'object' && ea.constructor === Object) {
20✔
446
                config.mongodb.extraArgs = ea;
16✔
447
            }
448
        } catch (e) {
449
            // Do nothing
450
        }
451
    }
452

453
    if (process.env.IOTA_POLLING_EXPIRATION) {
1,662!
454
        config.pollingExpiration = process.env.IOTA_POLLING_EXPIRATION;
×
455
    }
456

457
    if (process.env.IOTA_POLLING_DAEMON_FREQ) {
1,662!
458
        config.pollingDaemonFrequency = process.env.IOTA_POLLING_DAEMON_FREQ;
×
459
    }
460

461
    if (process.env.IOTA_MULTI_CORE) {
1,662✔
462
        config.multiCore = process.env.IOTA_MULTI_CORE === 'true';
4✔
463
    } else {
464
        config.multiCore = config.multiCore === true;
1,658✔
465
    }
466

467
    if (process.env.IOTA_RELAX_TEMPLATE_VALIDATION) {
1,662!
468
        config.relaxTemplateValidation = process.env.IOTA_RELAX_TEMPLATE_VALIDATION === 'true';
×
469
    } else {
470
        config.relaxTemplateValidation = config.relaxTemplateValidation === true;
1,662✔
471
    }
472
    if (process.env.IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION) {
1,662!
473
        config.defaultEntityNameConjunction = process.env.IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION;
×
474
    } else {
475
        config.defaultEntityNameConjunction = config.defaultEntityNameConjunction
1,662✔
476
            ? config.defaultEntityNameConjunction
477
            : ':';
478
    }
479
    if (process.env.IOTA_EXPRESS_LIMIT) {
1,662!
480
        config.expressLimit = process.env.IOTA_EXPRESS_LIMIT;
×
481
    } else {
482
        config.expressLimit = config.expressLimit ? config.expressLimit : '1mb';
1,662✔
483
    }
484
    if (process.env.IOTA_USE_CB_FLOW_CONTROL) {
1,662!
485
        config.useCBflowControl = process.env.IOTA_USE_CB_FLOW_CONTROL === 'true';
×
486
    } else {
487
        config.useCBflowControl = config.useCBflowControl === true;
1,662✔
488
    }
489
    if (process.env.IOTA_STORE_LAST_MEASURE) {
1,662!
490
        config.storeLastMeasure = process.env.IOTA_STORE_LAST_MEASURE === 'true';
×
491
    } else {
492
        config.storeLastMeasure = config.storeLastMeasure === true;
1,662✔
493
    }
494
}
495

496
function setConfig(newConfig) {
497
    config = newConfig;
1,662✔
498

499
    if (config.logLevel) {
1,662✔
500
        logger.setLevel(config.logLevel);
1,028✔
501
    }
502

503
    processEnvironmentVariables();
1,662✔
504
    logAuthState();
1,662✔
505
}
506

507
function getConfig() {
508
    return config;
13,699✔
509
}
510

511
function getConfigForTypeInformation() {
512
    // Just return relevant configuration flags
513
    // avoid to include server, authentication, mongodb, orion and iotamanger info
514
    let conf = {
306✔
515
        timestamp: config.timestamp,
516
        defaultResource: config.defaultResource,
517
        explicitAttrs: config.explicitAttrs,
518
        pollingExpiration: config.pollingExpiration,
519
        pollingDaemonFrequency: config.pollingDaemonFrequency,
520
        multiCore: config.multiCore,
521
        relaxTemplateValidation: config.relaxTemplateValidation,
522
        defaultEntityNameConjunction: config.defaultEntityNameConjunction,
523
        defaultType: config.defaultType,
524
        useCBflowControl: config.useCBflowControl,
525
        storeLastMeasure: config.storeLastMeasure
526
    };
527
    return conf;
306✔
528
}
529

530
function setRegistry(newRegistry) {
531
    registry = newRegistry;
803✔
532
}
533

534
function getRegistry() {
535
    return registry;
1,738✔
536
}
537

538
function setGroupRegistry(newGroupRegistry) {
539
    groupRegistry = newGroupRegistry;
803✔
540
}
541

542
function getGroupRegistry() {
543
    return groupRegistry;
2,659✔
544
}
545

546
function setCommandRegistry(newCommandRegistry) {
547
    commandRegistry = newCommandRegistry;
803✔
548
}
549

550
function getCommandRegistry() {
551
    return commandRegistry;
261✔
552
}
553

554
/**
555
 * Returns the supported NGSI format
556
 *
557
 * @return     {string}  the supported NGSI format
558
 */
559
function ngsiVersion() {
560
    if (config && config.contextBroker && config.contextBroker.ngsiVersion) {
4,378✔
561
        return config.contextBroker.ngsiVersion.toLowerCase();
3,572✔
562
    }
563
    return 'unknown';
806✔
564
}
565

566
/**
567
 * It checks if a combination of typeInformation or common Config is LD
568
 *
569
 * @return     {boolean}  Result of the checking
570
 */
571
function checkNgsiLD(typeInformation) {
572
    const format = typeInformation.ngsiVersion || ngsiVersion();
591✔
573
    return format.toLowerCase() === 'ld';
591✔
574
}
575

576
function setSecurityService(newSecurityService) {
577
    securityService = newSecurityService;
803✔
578
}
579

580
function getSecurityService() {
581
    return securityService;
54✔
582
}
583

584
exports.setConfig = setConfig;
1✔
585
exports.getConfig = getConfig;
1✔
586
exports.getConfigForTypeInformation = getConfigForTypeInformation;
1✔
587
exports.setRegistry = setRegistry;
1✔
588
exports.getRegistry = getRegistry;
1✔
589
exports.setGroupRegistry = setGroupRegistry;
1✔
590
exports.getGroupRegistry = getGroupRegistry;
1✔
591
exports.setCommandRegistry = setCommandRegistry;
1✔
592
exports.getCommandRegistry = getCommandRegistry;
1✔
593
exports.ngsiVersion = ngsiVersion;
1✔
594
exports.checkNgsiLD = checkNgsiLD;
1✔
595
exports.setSecurityService = setSecurityService;
1✔
596
exports.getSecurityService = getSecurityService;
1✔
597
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