Skip to content

[e2e testing] NGSI-LD #849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 150 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
055d343
Basic NSGI-LD Measures
jason-fox Feb 7, 2020
4d30d69
NGSI-LD Tests
jason-fox Feb 7, 2020
f1d0201
Fix tests - disable some additional NGSI-LD test fails.
jason-fox Feb 7, 2020
03779ba
Increase test coverage
jason-fox Feb 7, 2020
68b5f65
Linting codebase
jason-fox Feb 7, 2020
a732017
Add `observedAt` support
jason-fox Feb 10, 2020
ff76dfe
Handle Date, DateTime and Time as mandated by the NGSI-LD specification
jason-fox Feb 10, 2020
3e02f3e
Handle GeoJSON parsing as mandated by the NGSI-LD specification
jason-fox Feb 10, 2020
d8a64e3
Correct type attribute
jason-fox Feb 10, 2020
637451d
Calculate temporal properties using the UTC timezone
jason-fox Feb 10, 2020
73a350c
Use single quote
jason-fox Feb 10, 2020
f525477
Calculate temporal properties using the UTC timezone for observedAt A…
jason-fox Feb 10, 2020
866d901
Add unitCode support.
jason-fox Feb 10, 2020
aab10c3
Standardize timestamps to UTC.
jason-fox Feb 10, 2020
40875e3
Prettify tests and update tests to use ES6
jason-fox Feb 11, 2020
caf1896
Merge branch 'feature/ngsi-ld-measure' into feature/time-and-geo
jason-fox Feb 11, 2020
dd81751
Merge commit '09048b9f0a799bff3ee394790c23c47bec5af727' into feature/…
jason-fox Feb 11, 2020
a2b334a
Tidy JSON response mocks
jason-fox Feb 11, 2020
ae20a71
Merge branch 'feature/ngsi-ld-measure' into feature/time-and-geo
jason-fox Feb 11, 2020
00878fa
Remove observedAt from Entity root.
jason-fox Feb 20, 2020
bd63653
Add multimeasures support
jason-fox Feb 25, 2020
1234ede
Fixing lint errors
jason-fox Feb 25, 2020
4ad7b8a
Formatting tests as ES6
jason-fox Feb 25, 2020
dfd0be0
Capitalize file names
jason-fox Feb 25, 2020
8ea1221
Capitalize file names
jason-fox Feb 25, 2020
b0943b2
Enable travis
jason-fox Feb 25, 2020
93bf97b
Capitalize file path to fix Coverage
jason-fox Feb 25, 2020
c836260
Capitalize file path to fix Coverage
jason-fox Feb 25, 2020
b41a18a
Changes after review.
jason-fox Feb 26, 2020
41342e6
Changes after review. (feature/ngsi-ld-measure)
jason-fox Feb 26, 2020
bebf658
Changes after review. (feature/ngsi-ld-measure)
jason-fox Feb 26, 2020
2d849b0
Amend JavaDoc
jason-fox Feb 26, 2020
44eb834
Merge branch 'feature/ngsi-ld-measure' into feature/time-and-geo
jason-fox Feb 26, 2020
78c9f59
Merge branch 'feature/time-and-geo' into feature/ngsi-ld-multimeasure
jason-fox Feb 26, 2020
75467bb
Linting. Tidy Whitespace on modified files
jason-fox Feb 27, 2020
603e024
Modify indent
jason-fox Feb 27, 2020
64f0123
Basic Command support
jason-fox Feb 27, 2020
a027234
More JavaDoc NGSI-v2 => NSGI-LD
jason-fox Feb 27, 2020
7d78950
More JavaDoc NGSI-v2 => NSGI-LD
jason-fox Feb 27, 2020
11742cc
More JavaDoc NGSI-v2 => NSGI-LD
jason-fox Feb 27, 2020
51cda9e
More JavaDoc NGSI-v2 => NSGI-LD
jason-fox Feb 27, 2020
2594bc8
Fix expectations to match responses from a real context broker.
jason-fox Feb 28, 2020
c70d9ed
More JavaDoc - add missing headers
jason-fox Feb 28, 2020
ec47097
Merge branch 'feature/ngsi-ld-measure' into feature/time-and-geo
jason-fox Feb 28, 2020
2de60eb
Merge branch 'feature/time-and-geo' into feature/ngsi-ld-multimeasure
jason-fox Feb 28, 2020
6f7a077
More JavaDoc - add missing headers
jason-fox Feb 28, 2020
a5c650a
And error handler JavaDoc
jason-fox Feb 28, 2020
fd5c5d9
Merge branch 'feature/ngsi-ld-measure' into feature/time-and-geo
jason-fox Feb 28, 2020
74e42ab
Merge branch 'feature/time-and-geo' into feature/ngsi-ld-multimeasure
jason-fox Feb 28, 2020
91235cd
Merge branch 'feature/ngsi-ld-multimeasure' into feature/ngsi-ld-command
jason-fox Feb 28, 2020
cc42cb7
Merge pull request #841 from jason-fox/feature/ngsi-ld-measure
fgalan Mar 2, 2020
3cc3064
Merge branch 'master' into feature/842_ngsi_ld
fgalan Mar 2, 2020
d32eedf
Add default NGSI-LD Tenant and NGSI-LD Path headers.
jason-fox Mar 2, 2020
09e5b88
Add JavaDoc
jason-fox Mar 2, 2020
f863c19
Add return
jason-fox Mar 2, 2020
c30d072
Merge commit '3cc306477f414c4600cf0f7f807c9574dd046cbb' into feature/…
jason-fox Mar 2, 2020
1a5aaae
More JavaDoc
jason-fox Mar 2, 2020
1da050b
Updated CNR
jason-fox Mar 2, 2020
fa90072
Adding basic documentation.
jason-fox Mar 2, 2020
3751368
Add lazy attribute support
jason-fox Mar 2, 2020
9d5edb8
Fix test - add missing handler
jason-fox Mar 2, 2020
9428a5e
Enabling more tests and linting
jason-fox Mar 2, 2020
60b5292
Update doc/architecture.md
jason-fox Mar 3, 2020
5aa3a0b
Update doc/architecture.md
jason-fox Mar 3, 2020
03bb0fe
Update doc/installationguide.md
jason-fox Mar 3, 2020
6cd5300
Update doc/api.md
jason-fox Mar 3, 2020
16455aa
Update doc/architecture.md
jason-fox Mar 3, 2020
7991863
Update doc/advanced-topics.md
jason-fox Mar 3, 2020
3d72455
Remove dead code - replace with comment
jason-fox Mar 3, 2020
c0c9d0d
Enabling tests
jason-fox Mar 3, 2020
6605627
try ES6
jason-fox Mar 3, 2020
c6d0d9b
Transform to ES6 for modules refactored due to NGSI-LD changes.
jason-fox Mar 3, 2020
2f2caea
Move version checking flag to initialization.
jason-fox Mar 3, 2020
41bbe29
Merge branch 'feature/ngsi-ld-command' into feature/ngsi-ld
jason-fox Mar 3, 2020
30edc54
remove files added in error.
jason-fox Mar 3, 2020
283ac4b
Linting - remove unused files.
jason-fox Mar 3, 2020
448716b
remove semi-colon
jason-fox Mar 4, 2020
82e1d30
Merge pull request #843 from jason-fox/feature/time-and-geo
fgalan Mar 4, 2020
e8cdfeb
Merge commit '82e1d30e79df34fb63bdb6517e66ba969fad0774' into feature/…
jason-fox Mar 4, 2020
845c220
Update CNR
jason-fox Mar 4, 2020
3a90e27
Updating JavaDocs
jason-fox Mar 4, 2020
cbf6cef
Update lib/services/common/genericMiddleware.js
jason-fox Mar 4, 2020
8399d52
Merge pull request #847 from jason-fox/feature/ngsi-ld-multimeasure
fgalan Mar 4, 2020
b292f1c
Merge commit '8399d52cc34cec0acad20624da0e8f26d31d024f' into feature/…
jason-fox Mar 4, 2020
accb670
Update CNR
jason-fox Mar 4, 2020
104526f
Document new configuration variables.
jason-fox Mar 4, 2020
9da6a10
Update doc/installationguide.md
jason-fox Mar 9, 2020
263588b
Add header
jason-fox Mar 9, 2020
cac4d5f
Format JSON
jason-fox Mar 9, 2020
e099b84
Remove text
jason-fox Mar 10, 2020
24e08f5
Merge pull request #848 from jason-fox/feature/ngsi-ld-command
fgalan Mar 10, 2020
a89d021
Merge commit '24e08f5e5b3a1a0f8018ab25c0ae22c4e56738a2' into feature-…
jason-fox Mar 10, 2020
e5e0474
Update CNR
jason-fox Mar 10, 2020
66a31ea
Remove debug console.error statements
jason-fox Mar 10, 2020
5c8a2df
Merge pull request #850 from jason-fox/feature-ngsi-ld-es6
fgalan Mar 11, 2020
8102bc7
Update doc/installationguide.md
fgalan Mar 12, 2020
1aedb33
Update lib/plugins/expressionParser.js
fgalan Mar 12, 2020
4c1627f
REFACTOR CNR
fgalan Mar 12, 2020
56ca556
Update doc/installationguide.md
fgalan Mar 12, 2020
42294e3
Update doc/installationguide.md
fgalan Mar 12, 2020
4a18164
Merge branch 'master' into feature/842_ngsi_ld
fgalan Mar 18, 2020
247d085
Merge branch 'master' into feature/842_ngsi_ld
fgalan May 6, 2020
7040490
Merge branch 'master' into feature/842_ngsi_ld
fgalan Jun 4, 2020
66242bd
Fixing merge conflicts
jason-fox Jul 17, 2020
b5a737e
Tidying merge
jason-fox Jul 17, 2020
59d40a4
Fix incorrect parameter
jason-fox Jul 17, 2020
ddd52ef
Fix for test
jason-fox Jul 17, 2020
2b06ad4
Make missing params public
jason-fox Jul 17, 2020
ddb8cfe
Update api.md
jason-fox Jul 20, 2020
21a657a
Update installationguide.md
jason-fox Jul 20, 2020
b023f95
Merge pull request #881 from jason-fox/feature/842_ngsi_ld
fgalan Jul 20, 2020
4ed7426
Merge branch 'master' into feature/842_ngsi_ld
fgalan Jul 20, 2020
53e46a2
Merge pull request #882 from jason-fox/feature/add-public
fgalan Jul 21, 2020
c84ceb8
Merge branch 'master' into feature/842_ngsi_ld
fgalan Jul 23, 2020
af4a350
feat: allow to provide a list of JSON-LD @context
bobeal Jun 22, 2020
8cd7834
fix: NGSI-LD v1.2.1 and v1.3.1 success response codes on entities cre…
bobeal Aug 5, 2020
a02a8e5
doc: add a note explaining how to pass a list of contexts from env var
bobeal Aug 10, 2020
c715c32
fix: switch to a comma separated list of contexts
bobeal Aug 11, 2020
8ebb49b
feat: add tests around response codes handling
bobeal Aug 11, 2020
265351d
feat: handle extra whitespace in IOTA_JSON_LD_CONTEXT env var
bobeal Aug 12, 2020
e487d17
Add common NGSI-LD constants
jason-fox Sep 7, 2020
9d65c09
Remove unused constants
jason-fox Sep 8, 2020
9f2c8e4
Bug fix - command result.
jason-fox Sep 8, 2020
13c5db3
Fixing test expectations
jason-fox Sep 8, 2020
bd172c0
Merge pull request #898 from jason-fox/patch-3
fgalan Sep 8, 2020
4c9313a
Merge pull request #897 from jason-fox/patch-2
fgalan Sep 8, 2020
0637bbd
Merge branch 'master' into feature/842_ngsi_ld
jason-fox Sep 8, 2020
1407de0
DEBUG => FATAL
jason-fox Sep 8, 2020
c31fbdc
Remove package-lock.json
jason-fox Sep 8, 2020
b969f3e
Merge pull request #886 from easy-global-market/feature/allow-multipl…
fgalan Sep 9, 2020
80fef8e
Merge pull request #900 from jason-fox/feature/842_ngsi_ld
fgalan Sep 9, 2020
ec539ca
Merge branch 'master' into feature/842_ngsi_ld
jason-fox Sep 9, 2020
4b57c17
doc: add comments to explain handled response codes when batch upsert…
bobeal Sep 10, 2020
b7d0e90
Merge pull request #887 from easy-global-market/bug/response-codes-on…
fgalan Sep 10, 2020
2c5e872
Merge pull request #902 from jason-fox/feature/842_ngsi_ld
fgalan Sep 10, 2020
f248b89
Linting
jason-fox Sep 10, 2020
7103039
Merge pull request #903 from jason-fox/feature/842_ngsi_ld
fgalan Sep 10, 2020
55f6f71
Merge branch 'master' into feature/842_ngsi_ld
jason-fox Sep 16, 2020
ce29f81
Merge pull request #909 from jason-fox/feature/842_ngsi_ld
fgalan Sep 16, 2020
603cea6
Merge commit 'master' into feature/842_ngsi_ld
jason-fox Sep 17, 2020
3f18176
Merge pull request #911 from jason-fox/feature/842_ngsi_ld
fgalan Sep 17, 2020
930c5b8
Merge branch 'master' into feature/842_ngsi_ld
fgalan Sep 24, 2020
ce3e3aa
feat: use update mode of batch upsert when updating NGSI-LD entities
bobeal Oct 21, 2020
0d25170
Merge pull request #924 from easy-global-market/feature/use-update-mo…
fgalan Oct 22, 2020
674830e
Merge branch 'master' into feature/842_ngsi_ld
jason-fox Oct 22, 2020
2ac3b07
Merge branch 'master' into feature/842_ngsi_ld
jason-fox Nov 3, 2020
f7f5a52
Merge pull request #929 from jason-fox/feature/842_ngsi_ld
fgalan Nov 4, 2020
90b050b
Merge branch 'master' into feature/842_ngsi_ld
jason-fox Nov 16, 2020
ad2e658
Merge commit 'master' into feature/842_ngsi_ld
jason-fox Nov 18, 2020
7ba7363
Merge pull request #937 from jason-fox/feature/842_ngsi_ld
fgalan Nov 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Add basic NGSI-LD support as experimental feature (#842)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done a little refactor to the NGIS-LD entries in the CNR file.

The line "Lazy attributes" is mine but I guess is correct, as in #842 (comment) see Lazy Attribute checked.

@jason-fox is my understanding correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - Lazy Attributes are mapped to the forwarded GET

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus, NTC (I guess)

- Active measures
- GeoJSON and DateTime, unitCode and observedAt NGSI-LD support
- The NGSI v2 `TimeInstant` element has been mapped onto the NGSI-LD `observedAt` property
- The NGSI v2 `metadata.unitCode` attribute has been mapped onto the NGSI-LD `unitCode` property
- Multi-measures
- Lazy Attributes
- Commands
Update codebase to use ES6
- Remove JSHint and jshint overrides
- Add esLint using standard tamia presets
Expand Down
49 changes: 47 additions & 2 deletions doc/advanced-topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,50 @@ e.g.:
}
```

#### NGSI-LD data and metadata considerations

When provisioning devices for an NGSI-LD Context Broker, `type` values should typically correspond to one of the
following:

- `Property`, `Relationship`, `Geoproperty`
- Native JSON types (e.g. `String`, `Boolean`, `Float` , `Integer` `Number`)
- Temporal Properties (e.g. `Datetime`, `Date` , `Time`)
- GeoJSON types (e.g `Point`, `LineString`, `Polygon`, `MultiPoint`, `MultiLineString`, `MultiPolygon`)

Most NGSI-LD attributes are sent to the Context Broker as _properties_. If a GeoJSON type or native JSON type is
defined, the data will be converted to the appropriate type. Temporal properties should always be expressed in UTC,
using ISO 8601. This ISO 8601 conversion is applied automatically for the `observedAt` _property-of-a-property_ metadata
where present.

Data for any attribute defined as a _relationship_ must be a valid URN.

Note that when the `unitCode` metadata attribute is supplied in the provisioning data under NGSI-LD, the standard
`unitCode` _property-of-a-property_ `String` attribute is created.

Other unrecognised `type` attributes will be passed as NGSI-LD data using the following JSON-LD format:

```json
"<property_name>": {
"type" : "Property",
"value": {
"@type": "<property_type>",
"@value": { string or object}
}
}
```

`null` values will be passed in the following format:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you choose to pass null values in the following format, is it a requirement ? I cannot find this mentionned in the ngsi-ld specification.

Copy link
Contributor

@jason-fox jason-fox May 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a restriction based on the definitions of the ESTI NGSI-LD specification

5.2.1 Introduction

Implementations shall support the data types defined by the clauses below. For
each member defined by each data type (including nested ones) a term shall be
added to the Core @context, as mandated by clause 4.5. None of the members
described admit a null value
, except when they are used in the context of an
update operation (see clause 5.5.8) and implementations shall raise an error of
type BadRequestData if a null value is encountered.

and ...

5.5.8 JSON-LD Merge Patch Behaviour

  • For each member of the Fragment, whose value is null, contained by the target, the target member is removed.

so basically, you cannot store null directly as null since this is the signal to delete an attribute. The work around is not to send a null directly, but to send a JSON-LD object which is equivalent to null.

The attribute type is based on https://schema.org/Intangible

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(late reply)

It's not clear to me, you say you cannot store null but you're still trying to store a null value for the @value of Intangible.
Do I miss something there ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about passing a default value? as you use that only for numbers, 0 seems to be a correct choice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me, you say you cannot store null but you're still trying to store a null value
for the @value of Intangible. Do I miss something there ?

No that is precisely what I am attempting to do. Directly sending "value" : null is not legal NGSI-LD hence the workaround of sending an object equivalent to null - "value": { "@type": "Intangible", "@value": null }

What do you think about passing a default value? as you use that only for numbers, 0
seems to be a correct choice.

But 0 is a real number and may not be appropriate in all cases. To me,null better indicates Undefined.


```json
"<property_name>": {
"type" : "Property",
"value": {
"@type": "Intangible",
"@value": null
}
}
```

### Data mapping plugins

The IoT Agent Library provides a plugin mechanism in order to facilitate reusing code that makes small transformations
Expand Down Expand Up @@ -166,8 +210,9 @@ events in the IoT Agent with the configured type name will be marked as events.

##### Timestamp Processing Plugin (timestampProcess)

This plugin processes the entity attributes looking for a TimeInstant attribute. If one is found, the plugin add a
TimeInstant attribute as metadata for every other attribute in the same request.
This plugin processes the entity attributes looking for a `TimeInstant` attribute. If one is found, for NGSI-v1/NGSIv2,
the plugin adds a `TimeInstant` attribute as metadata for every other attribute in the same request. With NGSI-LD, the
Standard `observedAt` property-of-a-property is used instead.

##### Expression Translation plugin (expressionTransformation)

Expand Down
75 changes: 37 additions & 38 deletions doc/api.md

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions doc/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,15 @@ device to a command update to the device.
As part of the device to entity mapping process the IoT Agent creates and updates automatically a special timestamp.
This timestamp is represented as two different properties of the mapped entity::

- An attribute metadata named `TimeInstant` per dynamic attribute mapped, which captures as an ISO8601 timestamp when
the associated measurement (represented as attribute value) was observed.
- With NGSIv1/NGSI-v2, an attribute metadata named `TimeInstant` (per dynamic attribute mapped, which captures as an
ISO8601 timestamp when the associated measurement (represented as attribute value) was observed. With NGSI-LD, the
Standard `observedAt` property-of-a-property is used instead.

- An entity attribute named `TimeInstant` which captures as an ISO8601 timestamp when the last measurement received
from the device was observed.
- For NGSIv1/NGSI-v2 only, an additional attribute `TimeInstant` is added to the entity which captures as an ISO8601
timestamp when the last measurement received from the device was observed.

If no information about the measurement timestamp is received by the IoT Agent, the arrival time of the measurement will
be used to generate a `TimeInstant` for both the entity and the attribute's metadata.
be used to generate a `TimeInstant` for both the entity attribute and the attribute metadata.

Take into account that:

Expand Down
3 changes: 2 additions & 1 deletion doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ npm run lint:md

### Documentation Spell-checking

Uses the provided `.textlintrc` flag file. To check the markdown documentation for spelling and grammar errors, dead links & etc.
Uses the provided `.textlintrc` flag file. To check the markdown documentation for spelling and grammar errors, dead
links & etc.

```bash
# Use git-bash on Windows
Expand Down
165 changes: 99 additions & 66 deletions doc/installationguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ These are the parameters that can be configured in the global section:
}
```

- If you want to use NGSI-LD (experimental):

```javascript
{
host: '192.168.56.101',
port: '1026',
ngsiVersion: 'ld',
jsonLdContext: 'http://context.json-ld' // or ['http://context1.json-ld','http://context2.json-ld'] if you need more than one
}
```

Where `http://context.json-ld` is the location of the NGSI-LD `@context` element which provides additional information
allowing the computer to interpret the rest of the data with more clarity and depth. Read the
[JSON-LD specification](https://w3c.github.io/json-ld-syntax/#the-context) for more informtaion.

- **server**: configuration used to create the Context Server (port where the IoT Agent will be listening as a Context
Provider and base root to prefix all the paths). The `port` attribute is required. If no `baseRoot` attribute is
used, '/' is used by default. E.g.:
Expand Down Expand Up @@ -129,7 +144,7 @@ used for the same purpose. For instance:

```javascript
{
type: 'mongodb';
type: "mongodb";
}
```

Expand All @@ -152,6 +167,7 @@ used for the same purpose. For instance:
retryTime: 5
}
```

```javascript
{
host: 'mongodb-0,mongodb-1,mongodb-2',
Expand Down Expand Up @@ -213,9 +229,10 @@ used for the same purpose. For instance:
any unexpected error.
- **singleConfigurationMode**: enables the Single Configuration mode for backwards compatibility (see description in
the Overview). Default to false.
- **timestamp**: if this flag is activated, the IoT Agent will add a 'TimeInstant' metadata attribute to all the
attributes updated from device information. This flag is overwritten by `timestamp` flag in group or device
provision.
- **timestamp**: if this flag is activated:
- For NGSIv1/NGSIv2, the IoT Agent will add a `TimeInstant` metadata attribute to all the attributes updated from
device information. This flag is overwritten by `timestamp` flag in group or device
- With NGSI-LD, the standard `observedAt` property-of-a-property is created instead.
- **defaultResource**: default string to use as resource for the registration of new Configurations (if no resource is
provided).
- **defaultKey**: default string to use as API Key for devices that do not belong to a particular Configuration.
Expand All @@ -232,17 +249,25 @@ used for the same purpose. For instance:
the IoTAgent runs in a single thread. For more details about multi-core functionality, please refer to the
[Cluster](https://nodejs.org/api/cluster.html) module in Node.js and
[this section](howto.md#iot-agent-in-multi-thread-mode) of the library documentation.
- **defaultExpressionLanguage**: the default expression language used to
compute expressions, possible values are: `legacy` or `jexl`. When not set or
wrongly set, `legacy` is used as default value.

- **explicitAttrs**: if this flag is activated, only provisioned attributes will be processed to Context Broker.
This flag is overwritten by `explicitAttrs` flag in group or device provision.
- **relaxTemplateValidation**: if this flag is activated, `objectId` attributes for incoming devices are not validated,
and may exceptionally include characters (such as semi-colons) which are
[forbidden](https://fiware-orion.readthedocs.io/en/master/user/forbidden_characters/index.html) according to the NGSI
specification. When provisioning devices, it is necessary that the developer provides valid `objectId`-`name` mappings
whenever relaxed mode is used, to prevent the consumption of forbidden characters.
- **defaultExpressionLanguage**: the default expression language used to compute expressions, possible values are:
`legacy` or `jexl`. When not set or wrongly set, `legacy` is used as default value.
- **fallbackTenant** - For Linked Data Context Brokers which do not support multi-tenancy, this provides an
alternative mechanism for supplying the `NGSILD-Tenant` header. Note that NGSILD-Tenant has not yet been included in
the NGSI-LD standard (it has been proposed for the next update of the standard, but the final decision has yet been
confirmed), take into account it could change. Note that for backwards compatibility with NGSI v2, the
`fiware-service` header is already used as alternative if the `NGSILD-Tenant` header is not supplied.
- **fallbackPath** - For Linked Data Context Brokers which do not support a service path, this provides an alternative
mechanism for suppling the `NGSILD-Path` header. Note that for backwards compatibility with NGSI v2, the
`fiware-servicepath` header is already used as alternative if the `NGSILD-Path` header is not supplied. Note that
NGSILD-Path has not yet been included in the NGSI-LD standard (it has been proposed for the next update of the
standard, but the final decision has yet been confirmed), take into account it could change
- **explicitAttrs**: if this flag is activated, only provisioned attributes will be processed to Context Broker. This
flag is overwritten by `explicitAttrs` flag in group or device provision.
- **relaxTemplateValidation**: if this flag is activated, `objectId` attributes for incoming devices are not
validated, and may exceptionally include characters (such as semi-colons) which are
[forbidden](https://fiware-orion.readthedocs.io/en/master/user/forbidden_characters/index.html) according to the
NGSI specification. When provisioning devices, it is necessary that the developer provides valid `objectId`-`name`
mappings whenever relaxed mode is used, to prevent the consumption of forbidden characters.

### Configuration using environment variables

Expand All @@ -252,54 +277,62 @@ with container-based technologies, like Docker, Heroku, etc...
The following table shows the accepted environment variables, as well as the configuration parameter the variable
overrides.

| Environment variable | Configuration attribute |
| :------------------------ | :------------------------------ |
| IOTA_CB_URL | `contextBroker.url` |
| IOTA_CB_HOST | `contextBroker.host` |
| IOTA_CB_PORT | `contextBroker.port` |
| IOTA_CB_NGSI_VERSION | `contextBroker.ngsiVersion` |
| IOTA_NORTH_HOST | `server.host` |
| IOTA_NORTH_PORT | `server.port` |
| IOTA_PROVIDER_URL | `providerUrl` |
| IOTA_AUTH_ENABLED | `authentication.enabled` |
| IOTA_AUTH_TYPE | `authentication.type` |
| IOTA_AUTH_HEADER | `authentication.header` |
| IOTA_AUTH_URL | `authentication.url` |
| IOTA_AUTH_HOST | `authentication.host` |
| IOTA_AUTH_PORT | `authentication.port` |
| IOTA_AUTH_USER | `authentication.user` |
| IOTA_AUTH_PASSWORD | `authentication.password` |
| IOTA_AUTH_CLIENT_ID | `authentication.clientId` |
| IOTA_AUTH_CLIENT_SECRET | `authentication.clientSecret` |
| IOTA_AUTH_TOKEN_PATH | `authentication.tokenPath` |
| IOTA_AUTH_PERMANENT_TOKEN | `authentication.permanentToken` |
| IOTA_REGISTRY_TYPE | `deviceRegistry.type` |
| IOTA_LOG_LEVEL | `logLevel` |
| IOTA_TIMESTAMP | `timestamp` |
| IOTA_IOTAM_URL | `iotManager.url` |
| IOTA_IOTAM_HOST | `iotManager.host` |
| IOTA_IOTAM_PORT | `iotManager.port` |
| IOTA_IOTAM_PATH | `iotManager.path` |
| IOTA_IOTAM_AGENTPATH | `iotManager.agentPath` |
| IOTA_IOTAM_PROTOCOL | `iotManager.protocol` |
| IOTA_IOTAM_DESCRIPTION | `iotManager.description` |
| IOTA_MONGO_HOST | `mongodb.host` |
| IOTA_MONGO_PORT | `mongodb.port` |
| IOTA_MONGO_DB | `mongodb.db` |
| IOTA_MONGO_REPLICASET | `mongodb.replicaSet` |
| IOTA_MONGO_USER | `mongodb.user` |
| IOTA_MONGO_PASSWORD | `mongodb.password` |
| IOTA_MONGO_AUTH_SOURCE | `mongodb.authSource` |
| IOTA_MONGO_RETRIES | `mongodb.retries` |
| IOTA_MONGO_RETRY_TIME | `mongodb.retryTime` |
| IOTA_MONGO_SSL | `mongodb.ssl ` |
| IOTA_MONGO_EXTRAARGS | `mongodb.extraArgs` |
| IOTA_SINGLE_MODE | `singleConfigurationMode` |
| IOTA_APPEND_MODE | `appendMode` |
| IOTA_POLLING_EXPIRATION | `pollingExpiration` |
| IOTA_POLLING_DAEMON_FREQ | `pollingDaemonFrequency` |
| IOTA_AUTOCAST | `autocast` |
| IOTA_MULTI_CORE | `multiCore` |
| IOTA_DEFAULT_EXPRESSION_LANGUAGE | defaultExpressionLanguage |
| IOTA_EXPLICIT_ATTRS | `explicitAttrs` |
| IOTA_RELAX_TEMPLATE_VALIDATION | `relaxTemplateValidation` |
| Environment variable | Configuration attribute |
| :------------------------------- | :------------------------------ |
| IOTA_CB_URL | `contextBroker.url` |
| IOTA_CB_HOST | `contextBroker.host` |
| IOTA_CB_PORT | `contextBroker.port` |
| IOTA_CB_NGSI_VERSION | `contextBroker.ngsiVersion` |
| IOTA_NORTH_HOST | `server.host` |
| IOTA_NORTH_PORT | `server.port` |
| IOTA_PROVIDER_URL | `providerUrl` |
| IOTA_AUTH_ENABLED | `authentication.enabled` |
| IOTA_AUTH_TYPE | `authentication.type` |
| IOTA_AUTH_HEADER | `authentication.header` |
| IOTA_AUTH_URL | `authentication.url` |
| IOTA_AUTH_HOST | `authentication.host` |
| IOTA_AUTH_PORT | `authentication.port` |
| IOTA_AUTH_USER | `authentication.user` |
| IOTA_AUTH_PASSWORD | `authentication.password` |
| IOTA_AUTH_CLIENT_ID | `authentication.clientId` |
| IOTA_AUTH_CLIENT_SECRET | `authentication.clientSecret` |
| IOTA_AUTH_TOKEN_PATH | `authentication.tokenPath` |
| IOTA_AUTH_PERMANENT_TOKEN | `authentication.permanentToken` |
| IOTA_REGISTRY_TYPE | `deviceRegistry.type` |
| IOTA_LOG_LEVEL | `logLevel` |
| IOTA_TIMESTAMP | `timestamp` |
| IOTA_IOTAM_URL | `iotManager.url` |
| IOTA_IOTAM_HOST | `iotManager.host` |
| IOTA_IOTAM_PORT | `iotManager.port` |
| IOTA_IOTAM_PATH | `iotManager.path` |
| IOTA_IOTAM_AGENTPATH | `iotManager.agentPath` |
| IOTA_IOTAM_PROTOCOL | `iotManager.protocol` |
| IOTA_IOTAM_DESCRIPTION | `iotManager.description` |
| IOTA_MONGO_HOST | `mongodb.host` |
| IOTA_MONGO_PORT | `mongodb.port` |
| IOTA_MONGO_DB | `mongodb.db` |
| IOTA_MONGO_REPLICASET | `mongodb.replicaSet` |
| IOTA_MONGO_USER | `mongodb.user` |
| IOTA_MONGO_PASSWORD | `mongodb.password` |
| IOTA_MONGO_AUTH_SOURCE | `mongodb.authSource` |
| IOTA_MONGO_RETRIES | `mongodb.retries` |
| IOTA_MONGO_RETRY_TIME | `mongodb.retryTime` |
| IOTA_MONGO_SSL | `mongodb.ssl` |
| IOTA_MONGO_EXTRAARGS | `mongodb.extraArgs` |
| IOTA_SINGLE_MODE | `singleConfigurationMode` |
| IOTA_APPEND_MODE | `appendMode` |
| IOTA_POLLING_EXPIRATION | `pollingExpiration` |
| IOTA_POLLING_DAEMON_FREQ | `pollingDaemonFrequency` |
| IOTA_AUTOCAST | `autocast` |
| IOTA_MULTI_CORE | `multiCore` |
| IOTA_JSON_LD_CONTEXT | `jsonLdContext` |
| IOTA_FALLBACK_TENANT | `fallbackTenant` |
| IOTA_FALLBACK_PATH | `fallbackPath` |
| IOTA_DEFAULT_EXPRESSION_LANGUAGE | `defaultExpressionLanguage` |
| IOTA_EXPLICIT_ATTRS | `explicitAttrs` |
| IOTA_RELAX_TEMPLATE_VALIDATION | `relaxTemplateValidation` |

Note:

- If you need to pass more than one JSON-LD context, you can define the IOTA_JSON_LD_CONTEXT environment variable as a
comma separated list of contexts (e.g. `'http://context1.json-ld,http://context2.json-ld'`)
26 changes: 25 additions & 1 deletion lib/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ function processEnvironmentVariables() {
'IOTA_POLLING_DAEMON_FREQ',
'IOTA_MULTI_CORE',
'IOTA_DEFAULT_EXPRESSION_LANGUAGE',
'IOTA_RELAX_TEMPLATE_VALIDATION'
'IOTA_RELAX_TEMPLATE_VALIDATION',
'IOTA_JSON_LD_CONTEXT',
'IOTA_FALLBACK_TENANT',
'IOTA_FALLBACK_PATH'
];
const iotamVariables = [
'IOTA_IOTAM_URL',
Expand Down Expand Up @@ -235,6 +238,14 @@ function processEnvironmentVariables() {
config.contextBroker.ngsiVersion = process.env.IOTA_CB_NGSI_VERSION;
}

if (process.env.IOTA_JSON_LD_CONTEXT) {
config.contextBroker.jsonLdContext = process.env.IOTA_JSON_LD_CONTEXT.split(',').map((ctx) => ctx.trim());
}

config.contextBroker.fallbackTenant =
process.env.IOTA_FALLBACK_TENANT || config.contextBroker.service || 'iotagent';
config.contextBroker.fallbackPath = process.env.IOTA_FALLBACK_PATH || config.contextBroker.subservice || '/';

// North Port Configuration (ensuring the configuration sub-object exists before start using it)
if (config.server === undefined) {
config.server = {};
Expand Down Expand Up @@ -505,6 +516,18 @@ function checkNgsi2() {
return false;
}

/**
* It checks if the configuration file states the use of NGSI-LD
*
* @return {boolean} Result of the checking
*/
function checkNgsiLD() {
if (config.contextBroker && config.contextBroker.ngsiVersion && config.contextBroker.ngsiVersion === 'ld') {
return true;
}

return false;
}
function setSecurityService(newSecurityService) {
securityService = newSecurityService;
}
Expand All @@ -522,6 +545,7 @@ exports.getGroupRegistry = getGroupRegistry;
exports.setCommandRegistry = setCommandRegistry;
exports.getCommandRegistry = getCommandRegistry;
exports.checkNgsi2 = checkNgsi2;
exports.checkNgsiLD = checkNgsiLD;
exports.setSecurityService = setSecurityService;
exports.getSecurityService = getSecurityService;
exports.getSecretData = getSecretData;
Loading