iotagent-node-lib 2.18.0 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/.github/workflows/ci.yml +1 -2
  2. package/doc/advanced-topics.md +122 -53
  3. package/doc/api.md +52 -52
  4. package/doc/development.md +8 -9
  5. package/doc/expressionLanguage.md +514 -316
  6. package/doc/installationguide.md +66 -64
  7. package/doc/usermanual.md +48 -16
  8. package/docker/Mosquitto/Dockerfile +1 -0
  9. package/docker/Mosquitto/README.md +1 -0
  10. package/docker/Mosquitto/startMosquitto.sh +6 -4
  11. package/lib/command/commandLine.js +1 -1
  12. package/lib/fiware-iotagent-lib.js +3 -0
  13. package/lib/jexlTranformsMap.js +9 -1
  14. package/lib/model/Device.js +4 -1
  15. package/lib/model/Group.js +19 -1
  16. package/lib/plugins/expressionParser.js +6 -4
  17. package/lib/plugins/expressionPlugin.js +8 -1
  18. package/lib/plugins/jexlParser.js +3 -1
  19. package/lib/request-shim.js +111 -0
  20. package/lib/services/common/genericMiddleware.js +6 -2
  21. package/lib/services/common/iotManagerService.js +1 -1
  22. package/lib/services/common/securityServiceKeystone.js +1 -1
  23. package/lib/services/common/securityServiceOAuth2.js +3 -2
  24. package/lib/services/devices/deviceRegistryMongoDB.js +1 -0
  25. package/lib/services/devices/devices-NGSI-LD.js +1 -1
  26. package/lib/services/devices/devices-NGSI-v2.js +2 -6
  27. package/lib/services/devices/registrationUtils.js +0 -2
  28. package/lib/services/ngsi/entities-NGSI-LD.js +95 -11
  29. package/lib/services/ngsi/entities-NGSI-v2.js +93 -8
  30. package/lib/services/ngsi/ngsiService.js +3 -2
  31. package/lib/services/northBound/contextServer-NGSI-LD.js +3 -2
  32. package/lib/services/northBound/deviceProvisioningServer.js +29 -6
  33. package/lib/services/northBound/northboundServer.js +2 -0
  34. package/lib/services/northBound/restUtils.js +1 -1
  35. package/package.json +4 -4
  36. package/test/tools/utils.js +2 -0
  37. package/test/unit/expressions/jexlExpression-test.js +5 -5
  38. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +1 -1
  39. package/test/unit/general/deviceService-test.js +2 -5
  40. package/test/unit/general/loglevel-api_test.js +6 -11
  41. package/test/unit/general/migration-test.js +1 -0
  42. package/test/unit/general/startup-test.js +1 -0
  43. package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +1 -0
  44. package/test/unit/mongodb/mongodb-group-registry-test.js +1 -1
  45. package/test/unit/mongodb/mongodb-registry-test.js +2 -1
  46. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin12a.json +7 -0
  47. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin13.json +13 -13
  48. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +18 -0
  49. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +18 -0
  50. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin31.json +15 -0
  51. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +17 -0
  52. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin33.json +18 -0
  53. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin34.json +17 -0
  54. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +36 -0
  55. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json +16 -16
  56. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8a.json +18 -0
  57. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
  58. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1018 -0
  59. package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +2 -2
  60. package/test/unit/ngsi-ld/general/deviceService-test.js +1 -1
  61. package/test/unit/ngsi-ld/general/https-support-test.js +2 -1
  62. package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +2 -1
  63. package/test/unit/ngsi-ld/general/startup-test.js +1 -0
  64. package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +3 -1
  65. package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +2 -1
  66. package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +2 -6
  67. package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +2 -1
  68. package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +1 -0
  69. package/test/unit/ngsi-ld/ngsiService/autocast-test.js +1 -0
  70. package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +1 -0
  71. package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +4 -3
  72. package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +1 -0
  73. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +3 -2
  74. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +61 -0
  75. package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +2 -1
  76. package/test/unit/ngsi-ld/provisioning/device-registration_test.js +3 -2
  77. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +1 -0
  78. package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +42 -54
  79. package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +2 -1
  80. package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +4 -4
  81. package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +3 -5
  82. package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +12 -18
  83. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +3 -1
  84. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin17.json +1 -1
  85. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +16 -0
  86. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +22 -0
  87. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +12 -0
  88. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
  89. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +25 -0
  90. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +4 -4
  91. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +500 -0
  92. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +3 -2
  93. package/test/unit/ngsiv2/general/deviceService-test.js +9 -8
  94. package/test/unit/ngsiv2/general/https-support-test.js +2 -1
  95. package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +2 -1
  96. package/test/unit/ngsiv2/general/startup-test.js +1 -0
  97. package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +3 -1
  98. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +2 -1
  99. package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +14 -18
  100. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +3 -1
  101. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +1 -0
  102. package/test/unit/ngsiv2/ngsiService/queryDeviceInformationInCb-test.js +0 -1
  103. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +4 -3
  104. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +3 -2
  105. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +210 -0
  106. package/test/unit/ngsiv2/plugins/translation-inPlugins_test.js +1 -1
  107. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +3 -2
  108. package/test/unit/ngsiv2/provisioning/device-group-utils-test.js +2 -1
  109. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +2 -1
  110. package/test/unit/ngsiv2/provisioning/device-registration_test.js +3 -2
  111. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +4 -3
  112. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +42 -53
  113. package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +2 -1
  114. package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +4 -4
  115. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +3 -4
  116. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +13 -19
  117. package/test/unit/plugins/capture-configuration-inPlugins_test.js +3 -1
  118. package/test/unit/plugins/capture-provision-inPlugins_test.js +2 -1
  119. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin20.json +0 -25
@@ -56,9 +56,10 @@ allowing the computer to interpret the rest of the data with more clarity and de
56
56
  }
57
57
  ```
58
58
 
59
- Under mixed mode, **NGSI v2** payloads are used for context broker communications by default, but this payload may also be switched
60
- to **NGSI LD** at service group or device provisioning time using the `ngsiVersion` field in the provisioning API.
61
- The `ngsiVersion` field switch may be added at either group or device level, with the device level overriding the group setting.
59
+ Under mixed mode, **NGSI v2** payloads are used for context broker communications by default, but this payload may also
60
+ be switched to **NGSI LD** at service group or device provisioning time using the `ngsiVersion` field in the
61
+ provisioning API. The `ngsiVersion` field switch may be added at either group or device level, with the device level
62
+ overriding the group setting.
62
63
 
63
64
  - **server**: configuration used to create the Context Server (port where the IoT Agent will be listening as a Context
64
65
  Provider and base root to prefix all the paths). The `port` attribute is required. If no `baseRoot` attribute is
@@ -159,7 +160,7 @@ used for the same purpose. For instance:
159
160
 
160
161
  ```javascript
161
162
  {
162
- type: "mongodb";
163
+ type: 'mongodb';
163
164
  }
164
165
  ```
165
166
 
@@ -241,8 +242,8 @@ used for the same purpose. For instance:
241
242
  - **singleConfigurationMode**: enables the Single Configuration mode for backwards compatibility (see description in
242
243
  the Overview). Default to false.
243
244
  - **timestamp**: if this flag is activated:
244
- - For NGSI-v2, the IoT Agent will add a `TimeInstant` metadata attribute to all the attributes updated from
245
- device information. This flag is overwritten by `timestamp` flag in group or device
245
+ - For NGSI-v2, the IoT Agent will add a `TimeInstant` metadata attribute to all the attributes updated from device
246
+ information. This flag is overwritten by `timestamp` flag in group or device
246
247
  - With NGSI-LD, the standard `observedAt` property-of-a-property is created instead.
247
248
  - **defaultResource**: default string to use as resource for the registration of new Configurations (if no resource is
248
249
  provided).
@@ -273,10 +274,11 @@ used for the same purpose. For instance:
273
274
  NGSILD-Path has not yet been included in the NGSI-LD standard (it has been proposed for the next update of the
274
275
  standard, but the final decision has yet been confirmed), take into account it could change
275
276
  - **explicitAttrs**: if this flag is activated, only provisioned attributes will be processed to Context Broker. This
276
- flag is overwritten by `explicitAttrs` flag in group or device provision.
277
+ flag is overwritten by `explicitAttrs` flag in group or device provision. Additionally `explicitAttrs` can be used
278
+ to define which meassures defined in JSON/JEXL array will be propagated to NGSI interface.
277
279
  - **defaultEntityNameConjunction**: the default conjunction string used to compose a default `entity_name` when is not
278
- provided at device provisioning time; in that case `entity_name` is composed by `type` + `:` + `device_id`.
279
- Default value is `:`. This value is overwritten by `defaultEntityNameConjunction` in group provision.
280
+ provided at device provisioning time; in that case `entity_name` is composed by `type` + `:` + `device_id`. Default
281
+ value is `:`. This value is overwritten by `defaultEntityNameConjunction` in group provision.
280
282
  - **relaxTemplateValidation**: if this flag is activated, `objectId` attributes for incoming devices are not
281
283
  validated, and may exceptionally include characters (such as semi-colons) which are
282
284
  [forbidden](https://fiware-orion.readthedocs.io/en/master/user/forbidden_characters/index.html) according to the
@@ -291,61 +293,61 @@ with container-based technologies, like Docker, Heroku, etc...
291
293
  The following table shows the accepted environment variables, as well as the configuration parameter the variable
292
294
  overrides.
293
295
 
294
- | Environment variable | Configuration attribute |
295
- | :------------------------------- | :------------------------------ |
296
- | IOTA_CB_URL | `contextBroker.url` |
297
- | IOTA_CB_HOST | `contextBroker.host` |
298
- | IOTA_CB_PORT | `contextBroker.port` |
299
- | IOTA_CB_NGSI_VERSION | `contextBroker.ngsiVersion` |
300
- | IOTA_NORTH_HOST | `server.host` |
301
- | IOTA_NORTH_PORT | `server.port` |
302
- | IOTA_PROVIDER_URL | `providerUrl` |
303
- | IOTA_AUTH_ENABLED | `authentication.enabled` |
304
- | IOTA_AUTH_TYPE | `authentication.type` |
305
- | IOTA_AUTH_HEADER | `authentication.header` |
306
- | IOTA_AUTH_URL | `authentication.url` |
307
- | IOTA_AUTH_HOST | `authentication.host` |
308
- | IOTA_AUTH_PORT | `authentication.port` |
309
- | IOTA_AUTH_USER | `authentication.user` |
310
- | IOTA_AUTH_PASSWORD | `authentication.password` |
311
- | IOTA_AUTH_CLIENT_ID | `authentication.clientId` |
312
- | IOTA_AUTH_CLIENT_SECRET | `authentication.clientSecret` |
313
- | IOTA_AUTH_TOKEN_PATH | `authentication.tokenPath` |
314
- | IOTA_AUTH_PERMANENT_TOKEN | `authentication.permanentToken` |
315
- | IOTA_REGISTRY_TYPE | `deviceRegistry.type` |
316
- | IOTA_LOG_LEVEL | `logLevel` |
317
- | IOTA_TIMESTAMP | `timestamp` |
318
- | IOTA_IOTAM_URL | `iotManager.url` |
319
- | IOTA_IOTAM_HOST | `iotManager.host` |
320
- | IOTA_IOTAM_PORT | `iotManager.port` |
321
- | IOTA_IOTAM_PATH | `iotManager.path` |
322
- | IOTA_IOTAM_AGENTPATH | `iotManager.agentPath` |
323
- | IOTA_IOTAM_PROTOCOL | `iotManager.protocol` |
324
- | IOTA_IOTAM_DESCRIPTION | `iotManager.description` |
325
- | IOTA_MONGO_HOST | `mongodb.host` |
326
- | IOTA_MONGO_PORT | `mongodb.port` |
327
- | IOTA_MONGO_DB | `mongodb.db` |
328
- | IOTA_MONGO_REPLICASET | `mongodb.replicaSet` |
329
- | IOTA_MONGO_USER | `mongodb.user` |
330
- | IOTA_MONGO_PASSWORD | `mongodb.password` |
331
- | IOTA_MONGO_AUTH_SOURCE | `mongodb.authSource` |
332
- | IOTA_MONGO_RETRIES | `mongodb.retries` |
333
- | IOTA_MONGO_RETRY_TIME | `mongodb.retryTime` |
334
- | IOTA_MONGO_SSL | `mongodb.ssl` |
335
- | IOTA_MONGO_EXTRAARGS | `mongodb.extraArgs` |
336
- | IOTA_SINGLE_MODE | `singleConfigurationMode` |
337
- | IOTA_APPEND_MODE | `appendMode` |
338
- | IOTA_POLLING_EXPIRATION | `pollingExpiration` |
339
- | IOTA_POLLING_DAEMON_FREQ | `pollingDaemonFrequency` |
340
- | IOTA_AUTOCAST | `autocast` |
341
- | IOTA_MULTI_CORE | `multiCore` |
342
- | IOTA_JSON_LD_CONTEXT | `jsonLdContext` |
343
- | IOTA_FALLBACK_TENANT | `fallbackTenant` |
344
- | IOTA_FALLBACK_PATH | `fallbackPath` |
345
- | IOTA_DEFAULT_EXPRESSION_LANGUAGE | `defaultExpressionLanguage` |
346
- | IOTA_EXPLICIT_ATTRS | `explicitAttrs` |
347
- | IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION | `defaultEntityNameConjunction` |
348
- | IOTA_RELAX_TEMPLATE_VALIDATION | `relaxTemplateValidation` |
296
+ | Environment variable | Configuration attribute |
297
+ | :----------------------------------- | :------------------------------ |
298
+ | IOTA_CB_URL | `contextBroker.url` |
299
+ | IOTA_CB_HOST | `contextBroker.host` |
300
+ | IOTA_CB_PORT | `contextBroker.port` |
301
+ | IOTA_CB_NGSI_VERSION | `contextBroker.ngsiVersion` |
302
+ | IOTA_NORTH_HOST | `server.host` |
303
+ | IOTA_NORTH_PORT | `server.port` |
304
+ | IOTA_PROVIDER_URL | `providerUrl` |
305
+ | IOTA_AUTH_ENABLED | `authentication.enabled` |
306
+ | IOTA_AUTH_TYPE | `authentication.type` |
307
+ | IOTA_AUTH_HEADER | `authentication.header` |
308
+ | IOTA_AUTH_URL | `authentication.url` |
309
+ | IOTA_AUTH_HOST | `authentication.host` |
310
+ | IOTA_AUTH_PORT | `authentication.port` |
311
+ | IOTA_AUTH_USER | `authentication.user` |
312
+ | IOTA_AUTH_PASSWORD | `authentication.password` |
313
+ | IOTA_AUTH_CLIENT_ID | `authentication.clientId` |
314
+ | IOTA_AUTH_CLIENT_SECRET | `authentication.clientSecret` |
315
+ | IOTA_AUTH_TOKEN_PATH | `authentication.tokenPath` |
316
+ | IOTA_AUTH_PERMANENT_TOKEN | `authentication.permanentToken` |
317
+ | IOTA_REGISTRY_TYPE | `deviceRegistry.type` |
318
+ | IOTA_LOG_LEVEL | `logLevel` |
319
+ | IOTA_TIMESTAMP | `timestamp` |
320
+ | IOTA_IOTAM_URL | `iotManager.url` |
321
+ | IOTA_IOTAM_HOST | `iotManager.host` |
322
+ | IOTA_IOTAM_PORT | `iotManager.port` |
323
+ | IOTA_IOTAM_PATH | `iotManager.path` |
324
+ | IOTA_IOTAM_AGENTPATH | `iotManager.agentPath` |
325
+ | IOTA_IOTAM_PROTOCOL | `iotManager.protocol` |
326
+ | IOTA_IOTAM_DESCRIPTION | `iotManager.description` |
327
+ | IOTA_MONGO_HOST | `mongodb.host` |
328
+ | IOTA_MONGO_PORT | `mongodb.port` |
329
+ | IOTA_MONGO_DB | `mongodb.db` |
330
+ | IOTA_MONGO_REPLICASET | `mongodb.replicaSet` |
331
+ | IOTA_MONGO_USER | `mongodb.user` |
332
+ | IOTA_MONGO_PASSWORD | `mongodb.password` |
333
+ | IOTA_MONGO_AUTH_SOURCE | `mongodb.authSource` |
334
+ | IOTA_MONGO_RETRIES | `mongodb.retries` |
335
+ | IOTA_MONGO_RETRY_TIME | `mongodb.retryTime` |
336
+ | IOTA_MONGO_SSL | `mongodb.ssl` |
337
+ | IOTA_MONGO_EXTRAARGS | `mongodb.extraArgs` |
338
+ | IOTA_SINGLE_MODE | `singleConfigurationMode` |
339
+ | IOTA_APPEND_MODE | `appendMode` |
340
+ | IOTA_POLLING_EXPIRATION | `pollingExpiration` |
341
+ | IOTA_POLLING_DAEMON_FREQ | `pollingDaemonFrequency` |
342
+ | IOTA_AUTOCAST | `autocast` |
343
+ | IOTA_MULTI_CORE | `multiCore` |
344
+ | IOTA_JSON_LD_CONTEXT | `jsonLdContext` |
345
+ | IOTA_FALLBACK_TENANT | `fallbackTenant` |
346
+ | IOTA_FALLBACK_PATH | `fallbackPath` |
347
+ | IOTA_DEFAULT_EXPRESSION_LANGUAGE | `defaultExpressionLanguage` |
348
+ | IOTA_EXPLICIT_ATTRS | `explicitAttrs` |
349
+ | IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION | `defaultEntityNameConjunction` |
350
+ | IOTA_RELAX_TEMPLATE_VALIDATION | `relaxTemplateValidation` |
349
351
 
350
352
  Note:
351
353
 
package/doc/usermanual.md CHANGED
@@ -25,7 +25,7 @@ More values will be added in the future to the library. The applications using t
25
25
  Registry just by using the following function:
26
26
 
27
27
  ```javascript
28
- iotagentLib.statsRegistry.add("statName", statIncrementalValue, callback);
28
+ iotagentLib.statsRegistry.add('statName', statIncrementalValue, callback);
29
29
  ```
30
30
 
31
31
  The first time this function is invoked, it will add the new stat to the registry. Subsequent calls will add the value
@@ -80,7 +80,7 @@ In order to use the library, add the following dependency to your package.json f
80
80
  In order to use this library, first you must require it:
81
81
 
82
82
  ```javascript
83
- var iotagentLib = require("iotagent-node-lib");
83
+ var iotagentLib = require('iotagent-node-lib');
84
84
  ```
85
85
 
86
86
  The library supports four groups of features, one for each direction of the communication: client-to-server and
@@ -265,16 +265,16 @@ Once all the updates have taken place, the callback must be invoked with the upd
265
265
 
266
266
  ```javascript
267
267
  callback(null, {
268
- type: "TheType",
268
+ type: 'TheType',
269
269
  isPattern: false,
270
- id: "EntityID",
270
+ id: 'EntityID',
271
271
  attributes: [
272
272
  {
273
- name: "lumniscence",
274
- type: "Lumens",
275
- value: "432",
276
- },
277
- ],
273
+ name: 'lumniscence',
274
+ type: 'Lumens',
275
+ value: '432'
276
+ }
277
+ ]
278
278
  });
279
279
  ```
280
280
 
@@ -303,16 +303,16 @@ The callback must be invoked with the updated Context Element, using the informa
303
303
 
304
304
  ```javascript
305
305
  callback(null, {
306
- type: "TheType",
306
+ type: 'TheType',
307
307
  isPattern: false,
308
- id: "EntityID",
308
+ id: 'EntityID',
309
309
  attributes: [
310
310
  {
311
- name: "lumniscence",
312
- type: "Lumens",
313
- value: "432",
314
- },
315
- ],
311
+ name: 'lumniscence',
312
+ type: 'Lumens',
313
+ value: '432'
314
+ }
315
+ ]
316
316
  });
317
317
  ```
318
318
 
@@ -686,6 +686,38 @@ unexpectedly dead, a new process is created automatically to keep always the max
686
686
  - iotAgent: The IoT Agent Objects, used to start the agent.
687
687
  - callback: The callback function.
688
688
 
689
+ ##### iotagentLib.request()
690
+
691
+ ###### Signature
692
+
693
+ ```javascript
694
+ function request(options, callback)
695
+ ```
696
+
697
+ ###### Description
698
+
699
+ Make a direct HTTP request using the underlying request library (currently [got](https://github.com/sindresorhus/got)),
700
+ this is useful when creating agents which use an HTTP transport for their southbound commands, and removes the need for
701
+ the custom IoT Agent to import its own additional request library
702
+
703
+ ###### Params
704
+
705
+ - options: definition of the request (see
706
+ [got options](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md) for more details). The
707
+ following attributes are currently exposed.
708
+ - `method` - HTTP Method
709
+ - `searchParams` - query string params
710
+ - `qs` - alias for query string params
711
+ - `headers`
712
+ - `responseType` - either `text` or `json`. `json` is the default
713
+ - `json` - a supplied JSON object as the request body
714
+ - `body` - any ASCII text as the request body. It takes precedence over `json` if both are provided at the same
715
+ time (not recommended).
716
+ - `url` - the request URL
717
+ - `uri` - alternative alias for the request URL.
718
+ - callback: The callback currently returns an `error` Object, the `response` and `body`. The `body` is parsed to a
719
+ JSON object if the `responseType` is JSON.
720
+
689
721
  #### Generic middlewares
690
722
 
691
723
  This collection of utility middlewares is aimed to be used to north of the IoT Agent Library, as well as in other
@@ -9,6 +9,7 @@ RUN yum update -y && yum install -y wget \
9
9
  && yum install -y epel-release \
10
10
  && yum update -y epel-release \
11
11
  && yum install -y mosquitto \
12
+ && cp /etc/mosquitto/mosquitto.conf /etc/mosquitto/mosquitto.conf.orig \
12
13
  && chmod 755 /bin/startMosquitto.sh \
13
14
  && mkdir /var/log/mosquitto \
14
15
  && chown mosquitto:mosquitto /var/log/mosquitto \
@@ -2,6 +2,7 @@ Thi directory containts the Dockerfile (and associated files) for a container of
2
2
  This container is provide as a help for users to test with MQTT, but it is just an auxiliary material in this repository.
3
3
 
4
4
  The following releases matches with eclipse-mosquitto version:
5
+ - 1.6.0 uses mosquitto-1.6.10-1.el7.x86_64
5
6
  - 1.5.0 uses mosquitto-1.6.10-1.el7.x86_64
6
7
  - 1.4.0 uses mosquitto-1.6.10-1.el7.x86_64
7
8
  - 1.3.0 uses mosquitto-1.6.8-1.el7.x86_64
@@ -1,18 +1,20 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- if [ "${CONGIF_FROM_ENV}" = true ] ; then
3
+ if [ "${CONGIF_FROM_ENV}" = true ] ; then
4
+ cp /etc/mosquitto/mosquitto.conf.orig /etc/mosquitto/mosquitto.conf
4
5
  echo "log_timestamp true" >> /etc/mosquitto/mosquitto.conf
5
6
  echo "log_timestamp_format %Y-%m-%dT%H:%M:%S" >> /etc/mosquitto/mosquitto.conf
6
7
  echo 'listener 9001' >> /etc/mosquitto/mosquitto.conf
7
8
  echo 'protocol websockets' >> /etc/mosquitto/mosquitto.conf
8
9
  echo 'listener 1883' >> /etc/mosquitto/mosquitto.conf
9
- echo 'protocol mqtt' >> /etc/mosquitto/mosquitto.conf
10
+ echo 'protocol mqtt' >> /etc/mosquitto/mosquitto.conf
10
11
  if ! [ -z "${IOTA_PASS}" ] ; then
11
12
  # Only if IOTA_PASS is set and not empty MQTT user/pass authentication is used
12
13
  touch /etc/mosquitto/pwfile
13
14
  sed -i '$ i acl_file /etc/mosquitto/aclfile\npassword_file /etc/mosquitto/pwfile' /etc/mosquitto/mosquitto.conf
14
- mv /root/aclfile /etc/mosquitto/aclfile
15
- mosquitto_passwd -b /etc/mosquitto/pwfile iota ${IOTA_PASS}
15
+ cp -f /root/aclfile /etc/mosquitto/aclfile
16
+ sed -i 's/user iota/user '${IOTA_USER}'/g' /etc/mosquitto/aclfile
17
+ mosquitto_passwd -b /etc/mosquitto/pwfile ${IOTA_USER} ${IOTA_PASS}
16
18
  fi
17
19
  fi
18
20
 
@@ -25,7 +25,7 @@ const fs = require('fs');
25
25
  const clUtils = require('command-shell-lib');
26
26
  const migrationLib = require('./migration');
27
27
  const constants = require('../constants');
28
- const request = require('request');
28
+ const request = require('../request-shim');
29
29
  const async = require('async');
30
30
  const mu = require('mu2');
31
31
  let config;
@@ -37,6 +37,7 @@ const iotManager = require('./services/common/iotManagerService');
37
37
  const contextServer = require('./services/northBound/northboundServer');
38
38
  const errors = require('./errors');
39
39
  const constants = require('./constants');
40
+ const request = require('./request-shim');
40
41
  const logger = require('logops');
41
42
  const config = require('./commonConfig');
42
43
  const cluster = require('cluster');
@@ -325,6 +326,7 @@ exports.setDataQueryHandler = contextServer.setQueryHandler;
325
326
  exports.setConfigurationHandler = contextServer.setConfigurationHandler;
326
327
  exports.setRemoveConfigurationHandler = contextServer.setRemoveConfigurationHandler;
327
328
  exports.setProvisioningHandler = contextServer.setProvisioningHandler;
329
+ exports.setUpdatingHandler = contextServer.setUpdatingHandler;
328
330
  exports.setRemoveDeviceHandler = contextServer.setRemoveDeviceHandler;
329
331
  exports.setNotificationHandler = contextServer.setNotificationHandler;
330
332
  exports.addUpdateMiddleware = ngsi.addUpdateMiddleware;
@@ -372,3 +374,4 @@ exports.constants = constants;
372
374
  exports.logModule = logger;
373
375
  exports.configModule = config;
374
376
  exports.startServer = startServer;
377
+ exports.request = request;
@@ -57,7 +57,15 @@ const map = {
57
57
  bitwisemask: (i, mask, op, shf) =>
58
58
  (op === '&' ? parseInt(i) & mask : op === '|' ? parseInt(i) | mask : op === '^' ? parseInt(i) ^ mask : i) >>
59
59
  shf,
60
- slice: (arr, init, end) => arr.slice(init, end)
60
+ slice: (arr, init, end) => arr.slice(init, end),
61
+ addset: (arr, x) => {
62
+ return Array.from(new Set(arr).add(x));
63
+ },
64
+ removeset: (arr, x) => {
65
+ let s = new Set(arr);
66
+ s.delete(x);
67
+ return Array.from(s);
68
+ }
61
69
  };
62
70
 
63
71
  exports.map = map;
@@ -23,6 +23,9 @@
23
23
 
24
24
  const mongoose = require('mongoose');
25
25
  const Schema = mongoose.Schema;
26
+ const Group = require('./Group');
27
+
28
+ mongoose.Schema.Types.ExplicitAttrsType = Group.ExplicitAttrsType;
26
29
 
27
30
  const Device = new Schema({
28
31
  id: String,
@@ -49,7 +52,7 @@ const Device = new Schema({
49
52
  internalAttributes: Object,
50
53
  autoprovision: Boolean,
51
54
  expressionLanguage: String,
52
- explicitAttrs: Boolean,
55
+ explicitAttrs: Group.ExplicitAttrsType,
53
56
  ngsiVersion: String
54
57
  });
55
58
 
@@ -24,6 +24,23 @@
24
24
  const mongoose = require('mongoose');
25
25
  const Schema = mongoose.Schema;
26
26
 
27
+ class ExplicitAttrsType extends mongoose.SchemaType {
28
+ constructor(key, options) {
29
+ super(key, options, 'ExplicitAttrsType');
30
+ }
31
+ // `cast()` takes a parameter that can be anything. You need to
32
+ // validate the provided `val` and throw a `CastError` if you
33
+ // can't convert it.
34
+ cast(val) {
35
+ if (!(typeof val === 'boolean' || typeof val === 'string')) {
36
+ throw new Error('ExplicitAttrsType: ' + val + ' is not Boolean or String');
37
+ }
38
+ return val;
39
+ }
40
+ }
41
+
42
+ mongoose.Schema.Types.ExplicitAttrsType = ExplicitAttrsType;
43
+
27
44
  const Group = new Schema({
28
45
  url: String,
29
46
  resource: String,
@@ -43,7 +60,7 @@ const Group = new Schema({
43
60
  internalAttributes: Array,
44
61
  autoprovision: Boolean,
45
62
  expressionLanguage: String,
46
- explicitAttrs: Boolean,
63
+ explicitAttrs: ExplicitAttrsType,
47
64
  defaultEntityNameConjunction: String,
48
65
  ngsiVersion: String
49
66
  });
@@ -55,3 +72,4 @@ function load(db) {
55
72
  }
56
73
 
57
74
  module.exports.load = load;
75
+ module.exports.ExplicitAttrsType = ExplicitAttrsType;
@@ -28,15 +28,16 @@
28
28
  const Parser = require('jison').Parser;
29
29
  const errors = require('../errors');
30
30
  const logger = require('logops');
31
+ const fillService = require('../services/common/domain').fillService;
31
32
  const _ = require('underscore');
32
- const logContext = {
33
+ let logContext = {
33
34
  op: 'IoTAgentNGSI.Expression'
34
35
  };
35
36
  const grammar = {
36
37
  lex: {
37
38
  rules: [
38
39
  ['\\s+', '/* skip whitespace */'],
39
- ['@[a-zA-Z0-9]+\\b', 'return "VARIABLE";'],
40
+ ['@[a-zA-Z0-9_]+\\b', 'return "VARIABLE";'],
40
41
  ['[0-9]+(?:\\.[0-9]+)?\\b', 'return "NUMBER";'],
41
42
  ['\\*', 'return "*";'],
42
43
  ['\\/', 'return "/";'],
@@ -156,6 +157,7 @@ function processExpression(context) {
156
157
 
157
158
  /* eslint-disable-next-line no-unused-vars */
158
159
  function applyExpression(expression, context, typeInformation) {
160
+ logContext = fillService(logContext, typeInformation);
159
161
  const expressionList = expression.match(/\$\{.*?\}/g) || [];
160
162
  const substitutions = expressionList.map(processExpression(context));
161
163
  let expressionResult = expression;
@@ -214,14 +216,14 @@ function expressionApplier(context, typeInformation) {
214
216
  function contextAvailable(expression, context) {
215
217
  let error;
216
218
  try {
217
- const variablesList = expression.match(/@[a-zA-Z0-9]+/g) || [];
219
+ const variablesList = expression.match(/@[a-zA-Z0-9_]+/g) || [];
218
220
  const variables = variablesList.map(function (item) {
219
221
  return item.substr(1);
220
222
  });
221
223
  const keys = Object.keys(context);
222
224
  let validContext = _.difference(variables, keys).length === 0;
223
225
  if (!validContext) {
224
- logger.warn(
226
+ logger.info(
225
227
  logContext,
226
228
  'For expression "[%s]" context "[%j]" does not have element to match',
227
229
  expression,
@@ -96,7 +96,13 @@ function update(entity, typeInformation, callback) {
96
96
  parser = jexlParser;
97
97
  }
98
98
  let expressionAttributes = [];
99
- const ctx = parser.extractContext(attributes);
99
+ let attributesCtxt = [...attributes]; // just copy
100
+ if (typeInformation.static) {
101
+ typeInformation.static.forEach(function (att) {
102
+ attributesCtxt.push(att);
103
+ });
104
+ }
105
+ const ctx = parser.extractContext(attributesCtxt);
100
106
 
101
107
  if (typeInformation.active) {
102
108
  expressionAttributes = parser.processExpressionAttributes(typeInformation, typeInformation.active, ctx);
@@ -107,6 +113,7 @@ function update(entity, typeInformation, callback) {
107
113
  }
108
114
 
109
115
  try {
116
+ logger.debug(context, 'expressionPlugin entity %j', entity);
110
117
  let attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
111
118
  attsArray = processEntityUpdateNgsi2(attsArray);
112
119
  entity = utils.createNgsi2Entity(entity.id, entity.type, attsArray, true);
@@ -30,9 +30,10 @@
30
30
  const jexl = require('jexl');
31
31
  const errors = require('../errors');
32
32
  const logger = require('logops');
33
+ const fillService = require('../services/common/domain').fillService;
33
34
  const config = require('../commonConfig');
34
35
  const baseTranformsMap = require('../jexlTranformsMap.js').map;
35
- const logContext = {
36
+ let logContext = {
36
37
  op: 'IoTAgentNGSI.JEXL'
37
38
  };
38
39
 
@@ -96,6 +97,7 @@ function extractContext(attributeList) {
96
97
  }
97
98
 
98
99
  function applyExpression(expression, context, typeInformation) {
100
+ logContext = fillService(logContext, typeInformation);
99
101
  const result = parse(expression, context);
100
102
  logger.debug(logContext, 'applyExpression "[%j]" over "[%j]" result "[%j]" ', expression, context, result);
101
103
  const expressionResult = result !== undefined ? result : expression;
@@ -0,0 +1,111 @@
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
+
24
+ const got = require('got');
25
+ const logger = require('logops');
26
+ const context = {
27
+ op: 'IoTAgentNGSI.Request'
28
+ };
29
+
30
+ /**
31
+ * Transform the "request" options into "got" options and add additional "got" defaults
32
+ *
33
+ * The following options are currently exposed:
34
+ * - `method` - HTTP Method
35
+ * - `searchParams` - query string params
36
+ * - `qs` - alias for query string params
37
+ * - `headers`
38
+ * - `responseType` - either `text` or `json`. `json` is the default
39
+ * - `json` - a supplied JSON object as the request body
40
+ * - `body` - any ASCII text as the request body
41
+ * - `url` - the request URL
42
+ * - `uri` - alternative alias for the request URL.
43
+ *
44
+ * @param {Object} options Original definition of the request using the request library
45
+ * @return {Object} Updated definition of the request using the got library
46
+ *
47
+ */
48
+ function getOptions(options) {
49
+ const httpOptions = {
50
+ method: options.method,
51
+ searchParams: options.searchParams || options.qs,
52
+ headers: options.headers,
53
+ throwHttpErrors: options.throwHttpErrors || false,
54
+ retry: options.retry || 0,
55
+ responseType: options.responseType || 'json'
56
+ };
57
+
58
+ // got library is not properly documented, so it is not clear which takes precedence
59
+ // among body, json and form (see https://stackoverflow.com/q/70754880/1485926).
60
+ // Thus, we are enforcing our own precedence with the "else if" chain below.
61
+ // Behaviour is consistent with the one described at usermanual.md#iotagentlibrequest
62
+
63
+ if (options.method === 'GET' || options.method === 'HEAD' || options.method === 'OPTIONS') {
64
+ // Do nothing - Never add a body
65
+ } else if (options.body) {
66
+ // body takes precedence over json or form
67
+ httpOptions.body = options.body;
68
+ } else if (options.json) {
69
+ // json takes precedence over form
70
+ httpOptions.json = options.json;
71
+ } else if (options.form) {
72
+ // Note that we don't consider 'form' part of the function API (check usermanual.md#iotagentlibrequest)
73
+ // but we are preparing the code anyway as a safe measure
74
+ httpOptions.form = options.form;
75
+ }
76
+
77
+ return httpOptions;
78
+ }
79
+
80
+ /*
81
+ *
82
+ * Make a direct HTTP request using the underlying request library
83
+ * (currently [got](https://github.com/sindresorhus/got)),
84
+ *
85
+ * This function mimics the interface of the obsolete request library and switches
86
+ * back from promises to callbacks to avoid re-writing large chunks of code.
87
+ * This centralizes all HTTP requests in a single location and is useful
88
+ * when creating agents which use an HTTP transport for their southbound
89
+ * commands, and removes the need for the custom IoT Agent to import its own
90
+ * additonal request library.
91
+ *
92
+ * @param {Object} options Definition of the request .
93
+ * @param {Function} callback The callback function.
94
+ *
95
+ */
96
+
97
+ function request(options, callback) {
98
+ const httpOptions = getOptions(options);
99
+ logger.debug(context, 'Options: %s', JSON.stringify(options, null, 4));
100
+ got(options.url || options.uri, httpOptions)
101
+ .then((response) => {
102
+ logger.debug(context, 'Response %s', JSON.stringify(response.body, null, 4));
103
+ return callback(null, response, response.body);
104
+ })
105
+ .catch((error) => {
106
+ logger.debug(context, 'Error: %s', JSON.stringify(error, null, 4));
107
+ return callback(error);
108
+ });
109
+ }
110
+
111
+ module.exports = request;
@@ -71,7 +71,7 @@ function traceRequest(req, res, next) {
71
71
 
72
72
  /* eslint-disable-next-line no-unused-vars */
73
73
  function changeLogLevel(req, res, next) {
74
- const levels = ['INFO', 'ERROR', 'FATAL', 'DEBUG', 'WARNING'];
74
+ const levels = ['INFO', 'ERROR', 'FATAL', 'DEBUG', 'WARN', 'WARNING'];
75
75
 
76
76
  if (!req.query.level) {
77
77
  res.status(400).json({
@@ -82,7 +82,11 @@ function changeLogLevel(req, res, next) {
82
82
  error: 'invalid log level'
83
83
  });
84
84
  } else {
85
- logger.setLevel(req.query.level.toUpperCase());
85
+ let newLevel = req.query.level.toUpperCase();
86
+ if (newLevel === 'WARNING') {
87
+ newLevel = 'WARN';
88
+ }
89
+ logger.setLevel(newLevel);
86
90
  res.status(200).send('');
87
91
  }
88
92
  }