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

telefonicaid / iotagent-node-lib / 12768802855

14 Jan 2025 01:35PM UTC coverage: 79.579% (+0.04%) from 79.544%
12768802855

push

github

web-flow
Merge pull request #1677 from telefonicaid/task/use_cb_flow_control_when_update

use options=flowControl when update

1923 of 2575 branches covered (74.68%)

Branch coverage included in aggregate %.

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

1 existing line in 1 file now uncovered.

3716 of 4511 relevant lines covered (82.38%)

283.87 hits per line

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

81.66
/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 explicitAttrs
356
    if (process.env.IOTA_EXPLICIT_ATTRS !== undefined) {
1,662!
357
        config.explicitAttrs = process.env.IOTA_EXPLICIT_ATTRS;
×
358
    }
359

360
    // IoT Manager Configuration
361
    if (anyIsSet(iotamVariables)) {
1,662✔
362
        config.iotManager = {};
6✔
363
    }
364

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

376
    if (process.env.IOTA_IOTAM_PATH) {
1,662✔
377
        config.iotManager.path = process.env.IOTA_IOTAM_PATH;
6✔
378
    }
379

380
    if (process.env.IOTA_IOTAM_PROTOCOL) {
1,662✔
381
        config.iotManager.protocol = process.env.IOTA_IOTAM_PROTOCOL;
6✔
382
    }
383

384
    if (process.env.IOTA_IOTAM_DESCRIPTION) {
1,662✔
385
        config.iotManager.description = process.env.IOTA_IOTAM_DESCRIPTION;
6✔
386
    }
387

388
    if (process.env.IOTA_IOTAM_AGENTPATH) {
1,662!
389
        config.iotManager.agentPath = process.env.IOTA_IOTAM_AGENTPATH;
×
390
    }
391

392
    // Mongo DB configuration
393
    if (anyIsSet(mongoVariables)) {
1,662✔
394
        config.mongodb = {};
70✔
395
    }
396

397
    if (process.env.IOTA_MONGO_HOST) {
1,662✔
398
        config.mongodb.host = process.env.IOTA_MONGO_HOST;
70✔
399
    }
400

401
    if (process.env.IOTA_MONGO_PORT) {
1,662✔
402
        config.mongodb.port = process.env.IOTA_MONGO_PORT;
70✔
403
    }
404

405
    if (process.env.IOTA_MONGO_DB) {
1,662✔
406
        config.mongodb.db = process.env.IOTA_MONGO_DB;
70✔
407
    }
408

409
    if (process.env.IOTA_MONGO_REPLICASET) {
1,662✔
410
        config.mongodb.replicaSet = process.env.IOTA_MONGO_REPLICASET;
70✔
411
    }
412

413
    if (process.env.IOTA_MONGO_USER) {
1,662✔
414
        config.mongodb.user = process.env.IOTA_MONGO_USER;
64✔
415
    }
416

417
    if (process.env.IOTA_MONGO_PASSWORD) {
1,662✔
418
        config.mongodb.password = process.env.IOTA_MONGO_PASSWORD;
64✔
419
    }
420

421
    if (process.env.IOTA_MONGO_AUTH_SOURCE) {
1,662✔
422
        config.mongodb.authSource = process.env.IOTA_MONGO_AUTH_SOURCE;
64✔
423
    }
424

425
    if (process.env.IOTA_MONGO_RETRIES) {
1,662✔
426
        config.mongodb.retries = process.env.IOTA_MONGO_RETRIES;
64✔
427
    }
428

429
    if (process.env.IOTA_MONGO_RETRY_TIME) {
1,662✔
430
        config.mongodb.retryTime = process.env.IOTA_MONGO_RETRY_TIME;
64✔
431
    }
432

433
    if (process.env.IOTA_MONGO_SSL) {
1,662✔
434
        config.mongodb.ssl = process.env.IOTA_MONGO_SSL.toLowerCase() === 'true';
28✔
435
    }
436

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

448
    if (process.env.IOTA_POLLING_EXPIRATION) {
1,662!
449
        config.pollingExpiration = process.env.IOTA_POLLING_EXPIRATION;
×
450
    }
451

452
    if (process.env.IOTA_POLLING_DAEMON_FREQ) {
1,662!
453
        config.pollingDaemonFrequency = process.env.IOTA_POLLING_DAEMON_FREQ;
×
454
    }
455

456
    if (process.env.IOTA_MULTI_CORE) {
1,662✔
457
        config.multiCore = process.env.IOTA_MULTI_CORE === 'true';
4✔
458
    } else {
459
        config.multiCore = config.multiCore === true;
1,658✔
460
    }
461

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

491
function setConfig(newConfig) {
492
    config = newConfig;
1,662✔
493

494
    if (config.logLevel) {
1,662✔
495
        logger.setLevel(config.logLevel);
1,028✔
496
    }
497

498
    processEnvironmentVariables();
1,662✔
499
    logAuthState();
1,662✔
500
}
501

502
function getConfig() {
503
    return config;
13,346✔
504
}
505

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

525
function setRegistry(newRegistry) {
526
    registry = newRegistry;
803✔
527
}
528

529
function getRegistry() {
530
    return registry;
1,738✔
531
}
532

533
function setGroupRegistry(newGroupRegistry) {
534
    groupRegistry = newGroupRegistry;
803✔
535
}
536

537
function getGroupRegistry() {
538
    return groupRegistry;
2,659✔
539
}
540

541
function setCommandRegistry(newCommandRegistry) {
542
    commandRegistry = newCommandRegistry;
803✔
543
}
544

545
function getCommandRegistry() {
546
    return commandRegistry;
271✔
547
}
548

549
/**
550
 * Returns the supported NGSI format
551
 *
552
 * @return     {string}  the supported NGSI format
553
 */
554
function ngsiVersion() {
555
    if (config && config.contextBroker && config.contextBroker.ngsiVersion) {
4,378✔
556
        return config.contextBroker.ngsiVersion.toLowerCase();
3,572✔
557
    }
558
    return 'unknown';
806✔
559
}
560

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

571
function setSecurityService(newSecurityService) {
572
    securityService = newSecurityService;
803✔
573
}
574

575
function getSecurityService() {
576
    return securityService;
54✔
577
}
578

579
exports.setConfig = setConfig;
1✔
580
exports.getConfig = getConfig;
1✔
581
exports.getConfigForTypeInformation = getConfigForTypeInformation;
1✔
582
exports.setRegistry = setRegistry;
1✔
583
exports.getRegistry = getRegistry;
1✔
584
exports.setGroupRegistry = setGroupRegistry;
1✔
585
exports.getGroupRegistry = getGroupRegistry;
1✔
586
exports.setCommandRegistry = setCommandRegistry;
1✔
587
exports.getCommandRegistry = getCommandRegistry;
1✔
588
exports.ngsiVersion = ngsiVersion;
1✔
589
exports.checkNgsiLD = checkNgsiLD;
1✔
590
exports.setSecurityService = setSecurityService;
1✔
591
exports.getSecurityService = getSecurityService;
1✔
592
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