Skip to content

Commit

Permalink
Merge pull request #502 from telefonicaid/fix/check_ngsi_version_resp…
Browse files Browse the repository at this point in the history
…onse_configuration

Fix/check ngsi version response configuration
  • Loading branch information
fgalan authored Oct 19, 2020
2 parents 4759402 + b55a467 commit e73c2e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 9 additions & 7 deletions lib/iotaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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()
Expand Down Expand Up @@ -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') {
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit e73c2e9

Please sign in to comment.