An NGSI-LD wrapper for use with NGSI-v2 Context Brokers. It understands the NGSI-LD endpoints and inputs, converts them to NGSI-v2, makes a request to
the NGSI-v2 broker behind it and transforms responses back to NGSI-LD using a fixed JSON-LD @context. It supports the NGSI-LD federationOps endpoints only
and is designed to be used as a registered source with NGSI-LD Context Brokers in federation mode.
This is the CitComAI-Hub fork of jason-fox/lepus. It
serves the NGSI-v2 data of the València City Council platform (VLCi, https://cb.vlci.valencia.es:10027) as NGSI-LD in the CitCom data
space. On top of upstream it adds:
- Keystone v3 authentication. With
AUTH_URL,AUTH_USERandAUTH_PASSWORD, Lepus gets a token from Keystone and sends it to the NGSI-v2 broker asX-Auth-Token. TheFiware-Serviceis the Keystone domain and theFiware-ServicePaththe project. Tokens are cached per domain and project until they expire, and they are never logged. WithoutAUTH_URLno token is requested, as upstream. - Tenant and servicePath of every request. NGSI-LD has no servicePath, so Lepus deduces it from the entity type with a map
(
LEPUS_SERVICE_PATHS, by defaultlib/entityServicePaths.js), and usesLEPUS_DEFAULT_TENANTwhen the request has noNGSILD-Tenant. Only these headers are forwarded, never the client'sHostorAuthorization. See Configuration. - Only the data that was authorized. In a data space the policy of an offer authorizes an entity type, and NGSI-v2 would let a
client go around it. Lepus closes both ways (see Access control):
- A read by ID returns the entity only if it is of the type named in the ID (
urn:ngsi-ld:<type>:<id>). Any?type=of the client is replaced by that type, so an entity of another type is a404. - Lepus serves only the servicePaths in the map.
?scopeQ=can choose among the servicePaths of the entity type of the request; any other one gets a400and the request never reaches the broker.
- A read by ID returns the entity only if it is of the type named in the ID (
- Plain NGSI-v2 IDs. VLCi IDs are not URNs (e.g.
wastecontainer:6205...). Lepus returns them asurn:ngsi-ld:<type>:<id>in every format (keyValuesandsimplifiedtoo) and, withNGSI_V2_PLAIN_IDS=true, strips that prefix again from the IDs of the requests, so an entity can be read by the ID Lepus returned. - Smart Data Models
@context. When reading entities as JSON-LD, the@contextis the one of the Smart Data Models subject that contains the entity type (e.g.dataModel.WasteManagementforWasteContainer), taken from the official list of data models. If the type is not there,USER_CONTEXT_URLis used. The list is downloaded once a day; if the download fails,USER_CONTEXT_URLis used and the download is tried again after 5 minutes. - Entities that conform to NGSI-LD and Smart Data Models. On reads, attributes with a
nullvalue are left out (NGSI-LD has no null values) and some VLCi attributes are returned as their data model defines them. No data is invented. See Smart Data Models conformance. - Timeouts that work.
NGSI_V2_TIMEOUTandLEPUS_RELAY_TIMEOUTwere ignored upstream; here they apply to every request. - Configuration out of the repository.
.envis ignored (template:.env.example) anddeploy/kubernetesdeploys Lepus with a ConfigMap and a Secret. - Image published to GHCR by
.github/workflows/publish.yml. See Publishing a new version.
Known limitations:
- When an entity type has several servicePaths, a request reads one of them: the first one, or the one named in
?scopeQ=. NGSI_V2_PLAIN_IDSstrips the prefix from the path and theid=parameter, not from the bodies of batch operations.- The Smart Data Models adaptations are written for the VLCi data, in
lib/sdmConformance.js. They are code, not configuration.
In the CitCom data space, Lepus is deployed by the providers/townhall_vlc/lepus layer of
dataspace-on-upv.
Give me the Stores with the name "Einkauf" in NGSI-LD format
curl -L 'https://<lepus-context-broker>/ngsi-ld/v1/entities?type=Store&q=name%22Einkauf%22' \
-H 'Link: <http://context/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
-H 'Accept: application/ld+json'is transformed to Give me the Stores with the name "Einkauf" in NGSI-v2 format
curl -L 'https://<ngsi-v2-context-broker>/v2/entities?type=Store&q=nameEinkauf' \
-H 'Accept: application/json'All NGSI-v2 response attributes are converted to Property or Relationship (or subtype) and a fixed @context added to the body or Link header.
The following endpoints are supported as defined in the latest NGSI-LD Specification
- GET
/entities/- Query entities - §5.7.2; §6.4.3.2 - POST
/entities/- Entity creation - §5.6.1; §6.4.3.1 - DELETE
/entities/- Purge Entities
- GET
/entities/{entityId}- Entity retrieval by ID - §5.7.1; §6.5.3.1 - PATCH
/entities/{entityId}- Merge Entity - §5.6.17; §6.5.3.4 - PUT
/entities/{entityId}- Replace Entity - §5.6.17; §6.5.3.3 - DELETE
/entities/{entityId}- Entity retrieval by ID - §5.6.6; §6.5.3.2
- POST
/entities/{entityId}/attrs- Append Entity attributes - §5.6.3; §6.6.3.1 - PATCH
/entities/{entityId}/attrs- Update Entity attributes - §5.6.2; §6.6.3.2
- DELETE
/entities/{entityId}/{attr}- Delete Entity attribute - §5.6.5; §6.7.3.2 - PUT
/entities/{entityId}/{attr}- Replace Entity attribute - §5.6.19; §6.7.3.3
- POST
/subscriptions/- Create Subscription - §5.8.1; §6.10.3.1 - GET
/subscriptions/- Retrieve list of Subscriptions - §5.8.4; §6.10.3.2 - GET
/subscriptions/{subscriptionId}- Subscription retrieval by ID - §5.8.3; §6.11.3.1 - PATCH
/subscriptions/{subscriptionId}- Subscription update by ID - §5.8.2; §6.11.3.2 - DELETE
/subscriptions/{subscriptionId}- Subscription deletion by ID - §5.8.5; §6.11.3.3
- GET
/types/- Retrieve available entity types - §5.7.5; §5.7.6; §6.25.3.1 - GET
/types/{type}- Details about available entity type - §5.7.7; §6.26.3.1
- GET
/attributes/- Available attributes - §5.7.8; §5.7.9; §6.27.3.1 - GET
/attributes/{attrId}- Details about available attribute - §5.7.10; §6.28.3.1
- POST
/entityOperations/create- Batch Entity creation - §5.6.7; 6.14.3.1 - POST
/entityOperations/upsert- Batch Entity create or update (upsert) - §5.6.8; §6.15.3.1 - POST
/entityOperations/update- Batch Entity update - §5.6.9; §6.16.3.1 - POST
/entityOperations/delete- Batch Entity deletion - §5.6.10; §6.17.3.1
- POST
/entityOperations/query- Query entities based on POST - §5.7.2; §6.23.3.1 ❌- POST
/entityOperations/merge- Batch Entity merge - §5.6.20; §6.31.3.1 ❌
Internally
- POST
/notify/receives NGSI-v2 notifications and forwards then as NGSI-LD
To use the wrapper, run:
cp .env.example .env
docker compose upSet the local endpoints and any authentication credentials in .env before starting. This file is for local npm/Compose use only; Kubernetes configuration is documented separately below.
Then insert some data into an NGSI-v2 broker such as Telefónica's Orion Context Broker
curl -L 'http://localhost:1026/v2/entities/' \
-H 'Content-Type: application/json' \
-d '{
"id": "urn:ngsi-ld:Store:001",
"type": "Store",
"address": {
"type": "PostalAddress",
"value": {
"streetAddress": "Bornholmer Straße 65",
"addressRegion": "Berlin",
"addressLocality": "Prenzlauer Berg",
"postalCode": "10439"
},
"metadata": {
"verified": {
"value": true,
"type": "Boolean"
}
}
},
"location": {
"type": "geo:json",
"value": {
"type": "Point",
"coordinates": [13.3986, 52.5547]
}
},
"name": {
"type": "Text",
"value": "Bösebrücke Einkauf"
}
}'curl -L 'http://localhost:1026/v2/entities/' \
-H 'Content-Type: application/json' \
-d '{
"type": "Store",
"id": "urn:ngsi-ld:Store:002",
"address": {
"type": "PostalAddress",
"value": {
"streetAddress": "Friedrichstraße 44",
"addressRegion": "Berlin",
"addressLocality": "Kreuzberg",
"postalCode": "10969"
},
"metadata": {
"verified": {
"value": true,
"type": "Boolean"
}
}
},
"location": {
"type": "geo:json",
"value": {
"type": "Point",
"coordinates": [13.3903, 52.5075]
}
},
"name": {
"type": "Text",
"value": "Checkpoint Markt"
}
}'Now query Lepus Accept: application/ld+json as if it is an NGSI-LD source - e.g.
curl -L 'http://<lepus-context-broker>/ngsi-ld/v1/types' \
-H 'Link: <http://context/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
-H 'Accept: application/ld+json'returns NGSI-LD with a fixed @context
{
"id": "urn:ngsi-ld:EntityTypeList:a1993de4-83e0-44c9-990b-be2e84b31df1",
"type": "EntityTypeList",
"typeList": [
"Store"
],
"@context": [
"https://fiware.github.io/tutorials.Step-by-Step/tutorials-context.jsonld",
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.8.jsonld"
]
}Alternatively query Lepus with Accept: application/json
curl -iX 'https://<lepus-context-broker>/ngsi-ld/v1/types' \
-H 'Link: <https://<lepus-context-broker>/context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
-H 'Accept: application/json'Returns
Link: <https://<lepus-context-broker>/context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
{
"id": "urn:ngsi-ld:EntityTypeList:a1993de4-83e0-44c9-990b-be2e84b31df1",
"type": "EntityTypeList",
"typeList": [
"Store"
]
}And https://<lepus-context-broker>/context.jsonld returns NGSI-LD with a fixed @context
{
"@context": [
"https://fiware.github.io/tutorials.Step-by-Step/tutorials-context.jsonld",
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.8.jsonld"
]
}Configuration is provided to the application as environment variables. When running npm start, bin/www loads them from a local .env file. Docker Compose passes the application settings declared under the lepus service; its .env is only used locally for Compose interpolation. Neither local .env file is used by Kubernetes.
- DEBUG - for debug output - e.g.
DEBUG=adapter:* - LEPUS_PORT - port used for interactions - defaults to
3000 - LEPUS_ALIAS - host alias for Lepus
- LEPUS_RELAY_TIMEOUT maximum length of time to forward the NGSI-LD notification
- LEPUS_URL for the location of Lepus itself - e.g.
LEPUS_URL=http://<lepus> - LEPUS_MULTI_CORE - whether to use multiple cores
- INCLUDE_VALUE_TYPE - include the NGSI-v2 attribute
typein the returned payload - NGSI_V2_CONTEXT_BROKER for the NGSI-v2 Orion Context Broker URL - e.g.
NGSI_V2_CONTEXT_BROKER=http://orion2:1026 - NGSI_V2_TIMEOUT maximum length of time to access the NGSI-v2 Orion Context Broker URL in milliseconds
- USER_CONTEXT_URL for the fixed JSON-LD
@contextto be supplied - e.g.USER_CONTEXT_URL=https://fiware.github.io/tutorials.Step-by-Step/tutorials-context.jsonld - CORE_CONTEXT_URL for the fixed core NGSI-LD
@contextto be supplied - e.g.CORE_CONTEXT_URL=https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.8.jsonld - AUTH_URL, AUTH_USER and AUTH_PASSWORD for Keystone v3 authentication. Keep credentials out of source control and container images. Without
AUTH_URLno token is requested. - LEPUS_DEFAULT_TENANT - NGSI-v2
Fiware-Serviceused when the request has noNGSILD-Tenantheader - e.g.LEPUS_DEFAULT_TENANT=tef_vlci - NGSI_V2_PLAIN_IDS -
truewhen the NGSI-v2 IDs are not URNs. Lepus returns them asurn:ngsi-ld:<type>:<id>and, with this option, strips that prefix again from the IDs of the requests (path andid=), so entities can be read by the ID Lepus returned - defaults tofalse - LEPUS_SERVICE_PATHS - JSON object with the NGSI-v2
Fiware-ServicePathof each entity type (a string, or a list when the type has several) - e.g.LEPUS_SERVICE_PATHS={"WasteContainer":"/residuos_contenedores_vlc"}. Lepus serves only these servicePaths - defaults tolib/entityServicePaths.js
NGSI-LD has no servicePath, but NGSI-v2 and its Keystone projects do. For every request Lepus sends Fiware-Service (the NGSILD-Tenant header or LEPUS_DEFAULT_TENANT) and Fiware-ServicePath. The servicePath is the one mapped to the entity type of the request, which is taken from ?type=, the entity ID urn:ngsi-ld:<type>:... or the body; a type that is not in the map uses /. With Keystone, they are the domain and the project of the token. Other client headers, such as Authorization, are not forwarded to the NGSI-v2 broker.
Lepus does not authenticate its clients. In a data space it runs behind the gateway of the connector, which checks the token and the policy of the offer the client bought. That policy authorizes an entity type (ngsi-ld:entityType in odrl-pap), read from the last segment of the path (urn:ngsi-ld:<type>:<id>) or else from ?type=. Lepus makes the NGSI-v2 broker keep to what the policy checked:
- Reads by ID. NGSI-v2 reads an entity by its ID without looking at its type, so the buyer of one dataset could read an entity of another one with a forged ID (
/entities/urn:ngsi-ld:WasteContainer:<air quality id>). Lepus sends the broker the type named in the ID, replacing any?type=of the client, and the broker answers404when the entity is of another type. When the last segment names no type (e.g./entities/{entityId}/attrs/{attr}), the?type=that the policy checked is forwarded as it is. - servicePaths. The map lists the servicePaths that may be offered, and Lepus serves nothing else.
?scopeQ=must be one of the servicePaths mapped to the entity type of the request (/for a type that is not in the map). Any other value gets400 BadRequestDataand the request is not sent to the broker. Keep internal servicePaths out of the map: the default one leaves out the EMT air quality sensors of VLCi (/calidad_aire_emt_vlc) on purpose.
The entities read from VLCi are adapted by lib/sdmConformance.js before they are returned, in the normalized, concise and keyValues formats (the read of a single attribute, /attrs/{attr}, is not adapted):
| Entity type | Attribute | In VLCi | Returned by Lepus |
|---|---|---|---|
| Any | Any | null |
The attribute is left out |
WasteContainer |
refDevice |
One reference | A list of references |
WasteContainer |
category |
Superficie |
ground |
WasteContainer |
fillingLevel |
Sometimes a number in a string ("0") |
The number |
TrafficFlowObserved |
intensity |
-1 when there is no measurement |
The attribute is left out |
Each rule is a format change or the removal of a "no data" value. What would need new data is not fixed: 5 WasteContainer entities have no location in VLCi and do not conform.
tools/sdm-audit checks the entities that a running Lepus returns against the official schemas, pinned to a commit of each Smart Data Models repository. With v1.6 and the VLCi data of 2026-11-12: AirQualityObserved 33 of 33, TrafficFlowObserved 386 of 386, WasteContainer 538 of 543. Run it again after changing the adaptations or the data.
For Kubernetes, configure non-secret settings in the ConfigMap and credentials in a Secret; see the Kubernetes deployment guide. The manifest uses the ghcr.io/citcomai-hub/lepus image.
Since Lepus does not understand JSON-LD directly, registrations must be created within an LD context broker using the "key": "jsonldContext"
to preprocess all interactions:
curl -L 'http://localhost:9090/ngsi-ld/v1/csourceRegistrations/' \
-H 'Content-Type: application/json' \
-H 'Link: <https://<lepus-context-broker>/context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
-d ' {
"type": "ContextSourceRegistration",
"information": [
{
"entities": [
{
"type": "Shelf"
}
]
}
],
"contextSourceInfo":[
{
"key": "jsonldContext",
"value": "https://<lepus-context-broker>/context.jsonld"
}
],
"mode": "inclusive",
"operations": [
"federationOps"
],
"endpoint": "https://<lepus-context-broker>"
}'The image is ghcr.io/citcomai-hub/lepus. It belongs to the CitComAI-Hub organization and is public, so clusters pull it without a pull
secret. It is built and pushed by .github/workflows/publish.yml when a v* tag is pushed: the
workflow runs the unit tests, builds the Dockerfile and publishes :<tag> and :sha-<commit>, linked to this repository. Nobody needs
to log in to GHCR.
-
Merge the changes to
masterand push them:git push citcom-vlc master -
Tag
masterwith a new version and push the tag. Use a new tag every time: a pod does not pull again a tag it already has.git tag -a v1.7 -m "Lepus v1.7" git push citcom-vlc v1.7
-
Follow the run in Actions. When it finishes, the image is available:
docker pull ghcr.io/citcomai-hub/lepus:v1.7 -
Update the deployments to the new tag:
- CitCom data space:
lepus_image_taginproviders/townhall_vlc/lepus/envs/dev.tfvarsof dataspace-on-upv, through a pull request, and then apply that layer. deploy/kubernetes/lepus.yaml: theimageof the Deployment.
- CitCom data space:
The workflow can also be run by hand from Actions (Run workflow); then it only publishes :sha-<commit>.
MIT © 2023-2025 FIWARE Foundation e.V.