diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 6a830f1b..a45e0f20 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,2 +1,3 @@ +FIX: check ngsi version in configuration handler (#500) Add missed global config env vars (IOTA_CONFIG_RETRIEVAL, IOTA_DEFAULT_KEY, IOTA_DEFAULT_TRANSPORT) Update Docker security practices (Add HEALTHCHECK, Use Anonymous User, Use two-stage build) diff --git a/lib/iotaUtils.js b/lib/iotaUtils.js index 12b9c652..f78888e2 100644 --- a/lib/iotaUtils.js +++ b/lib/iotaUtils.js @@ -46,7 +46,7 @@ function getEffectiveApiKey(service, subservice, device, callback) { config.getLogger().debug(context, 'Using device apikey: %s', device.apikey); callback(null, device.apikey); } else { - iotAgentLib.findConfiguration(service, subservice, function(error, group) { + iotAgentLib.findConfiguration(service, subservice, function (error, group) { if (group) { config.getLogger().debug(context, 'Using found group: %j', group); callback(null, group.apikey); @@ -82,14 +82,16 @@ function manageConfiguration(apiKey, deviceId, device, objMessage, sendFunction, } function extractAttributes(results, callback) { - if ( + if (iotAgentLib.configModule.checkNgsi2()) { + callback(null, results); + } else if ( results.contextResponses && results.contextResponses[0] && results.contextResponses[0].contextElement.attributes ) { callback(null, results.contextResponses[0].contextElement.attributes); } else { - callback("Couldn't find any information in Context Broker response"); + callback("Couldn't find any information in Context Broker response: " + JSON.stringify(results)); } } @@ -103,7 +105,7 @@ function manageConfiguration(apiKey, deviceId, device, objMessage, sendFunction, handleSendConfigurationError ); } else if (objMessage.type === 'subscription') { - iotAgentLib.subscribe(device, objMessage.fields, objMessage.fields, function(error) { + iotAgentLib.subscribe(device, objMessage.fields, objMessage.fields, function (error) { if (error) { config .getLogger() @@ -145,7 +147,7 @@ function createConfigurationNotification(results) { } function findOrCreate(deviceId, transport, group, callback) { - iotAgentLib.getDeviceSilently(deviceId, group.service, group.subservice, function(error, device) { + iotAgentLib.getDeviceSilently(deviceId, group.service, group.subservice, function (error, device) { if (!error && device) { callback(null, device, group); } else if (error.name === 'DEVICE_NOT_FOUND') { @@ -169,7 +171,7 @@ function findOrCreate(deviceId, transport, group, callback) { if ('timestamp' in group) { newDevice.timestamp = group.timestamp; } - iotAgentLib.register(newDevice, function(error, device) { + iotAgentLib.register(newDevice, function (error, device) { callback(error, device, group); }); } else { @@ -187,7 +189,7 @@ function findOrCreate(deviceId, transport, group, callback) { */ function retrieveDevice(deviceId, apiKey, transport, callback) { if (apiKey === config.getConfig().defaultKey) { - iotAgentLib.getDevicesByAttribute('id', deviceId, null, null, function(error, devices) { + iotAgentLib.getDevicesByAttribute('id', deviceId, null, null, function (error, devices) { if (error) { callback(error); } else if (devices && devices.length === 1) {