Skip to content

Commit

Permalink
Merge pull request #4595 from telefonicaid/hardening/jexl-transformat…
Browse files Browse the repository at this point in the history
…ions

ADD improved and new transformations
  • Loading branch information
mapedraza authored Aug 1, 2024
2 parents c7e65a4 + 32703aa commit a37740a
Show file tree
Hide file tree
Showing 9 changed files with 776 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- Fix: custom notification ngsi patching evaluation priority based in evalPriority builtin metadata (#4556)
- Fix: wrong date values should not allowed in subscription's expires field (#4541)
- Fix: do not raise DB alarm in case of wrong GeoJSON in client request
- Upgrade cjexl version from 0.3.0 to 0.4.0 (new transformations: now, getTime and toIsoString)
- Upgrade Debian version from 12.4 to 12.6 in Dockerfile
2 changes: 1 addition & 1 deletion ci/deb/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ rm -Rf /tmp/builder || true && mkdir -p /tmp/builder/{db1,db2,db,bu}
if [ -z "${REPO_ACCESS_TOKEN}" ]; then
echo "Builder: no REPO_ACCESS_TOKEN, skipping cjexl lib download"
else
bash /opt/fiware-orion/get_cjexl.sh 0.3.0 $REPO_ACCESS_TOKEN
bash /opt/fiware-orion/get_cjexl.sh 0.4.0 $REPO_ACCESS_TOKEN
fi

if [ -n "${branch}" ]; then
Expand Down
66 changes: 65 additions & 1 deletion doc/manuals/orion-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
- [`keys`](#keys)
- [`arrSum`](#arrsum)
- [`arrAvg`](#arravg)
- [`now`](#now)
- [`toIsoString`](#toisostring)
- [`getTime`](#gettime)
- [Failsafe cases](#failsafe-cases)
- [Known limitations](#known-limitations)
- [Oneshot Subscriptions](#oneshot-subscriptions)
Expand Down Expand Up @@ -2684,7 +2687,7 @@ foo bar

#### substring

Returns a substring between two positions.
Returns a substring between two positions or `null` in case of wrong parameters (eg. final position is longer than string, final position is leeser than initial position, etc.)

Extra arguments:
* Initial position
Expand Down Expand Up @@ -3146,6 +3149,67 @@ results in
3
```

#### now

Returns the current time (plus a number of seconds specified as argument) as seconds since Unix epoch time.

Extra arguments: none

Example (being current time August 1st, 2024 at 9:31:02):

```
0|now
```

results in

```
1722504662
```

It can be checked at https://www.epochconverter.com that time corresponds to August 1st, 2024 at 9:31:02

#### toIsoString

Returns the [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) corresponding to a given timestamp (as seconds since Unix epoch time) passed as argument.

Extra arguments: none

Example (being context `{"c": 1720606949}`):

```
c|toIsoString
```

results in

```
"2024-07-10T10:22:29+00:00"
```

It can be checked at https://www.epochconverter.com that 1720606949 corresponds to 2024-07-10T10:22:29+00:00


#### getTime

Returns the timestamp (as seconds since Unix epoch time) correspoding to the [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) passed as argument.

Extra arguments: none

Example (being context `{"c": "2024-07-10T10:22:29+00:00"}`):

```
c|getTime
```

results in

```
1720606949
```

It can be checked at https://www.epochconverter.com that 1720606949 corresponds to 2024-07-10T10:22:29+00:00

### Failsafe cases

As failsafe behaviour, evaluation returns `null` in the following cases:
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ RUN --mount=type=secret,id=repo_token,dst=/run/secrets/repo_token \
git clone https://github.com/${GIT_NAME}/fiware-orion && \
cd fiware-orion && \
git checkout ${GIT_REV_ORION} && \
bash get_cjexl.sh 0.3.0 $(cat /run/secrets/repo_token) && \
bash get_cjexl.sh 0.4.0 $(cat /run/secrets/repo_token) && \
make && \
make install && \
# reduce size of installed binaries
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ RUN --mount=type=secret,id=repo_token,dst=/run/secrets/repo_token \
git clone https://github.com/${GIT_NAME}/fiware-orion && \
cd fiware-orion && \
git checkout ${GIT_REV_ORION} && \
bash get_cjexl.sh 0.3.0 $(cat /run/secrets/repo_token) && \
bash get_cjexl.sh 0.4.0 $(cat /run/secrets/repo_token) && \
# patch bash and mktemp statement in build script, as in alpine is slightly different
sed -i 's/mktemp \/tmp\/compileInfo.h.XXXX/mktemp/g' scripts/build/compileInfo.sh && \
sed -i 's/bash/ash/g' scripts/build/compileInfo.sh && \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ payload='{
"AA",
"AB",
"AC",
"AD"
"AD",
"AE",
"AF",
"AG"
],
"httpCustom": {
"url": "http://127.0.0.1:'${LISTENER_PORT}'/notify",
Expand Down Expand Up @@ -205,6 +208,18 @@ payload='{
"AD": {
"type": "Number",
"value": "${AD|len}"
},
"AE": {
"type": "Number",
"value": "${AE|now}"
},
"AF": {
"type": "Text",
"value": "${AF|toIsoString}"
},
"AG": {
"type": "Number",
"value": "${AG|getTime}"
}
}
}
Expand Down Expand Up @@ -344,6 +359,18 @@ payload='{
"AD": {
"type": "StructuredValue",
"value": [1, 2, 3]
},
"AE": {
"type": "Number",
"value": 0
},
"AF": {
"type": "Number",
"value": 1722500129
},
"AG": {
"type": "Number",
"value": "1979-11-13T18:01:14+00:00"
}
}'
orionCurl --url /v2/entities --payload "$payload"
Expand Down Expand Up @@ -383,7 +410,7 @@ Content-Length: 0
==================================================
POST http://127.0.0.1:REGEX(\d+)/notify
Fiware-Servicepath: /
Content-Length: 1627
Content-Length: 1809
User-Agent: orion/REGEX(\d+\.\d+\.\d+.*)
Ngsiv2-Attrsformat: normalized
Host: 127.0.0.1:REGEX(\d+)
Expand Down Expand Up @@ -422,6 +449,21 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1
"type": "Number",
"value": 3
},
"AE": {
"metadata": {},
"type": "Number",
"value": REGEX(\d+)
},
"AF": {
"metadata": {},
"type": "Text",
"value": "2024-08-01T08:15:29+00:00"
},
"AG": {
"metadata": {},
"type": "Number",
"value": 311364074
},
"B": {
"metadata": {},
"type": "Text",
Expand Down
Loading

0 comments on commit a37740a

Please sign in to comment.