Skip to content
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

Fix/check ngsi version response configuration #502

Merged
merged 3 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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