Skip to content

Commit

Permalink
Merge pull request #697 from telefonicaid/fix/use_trust_cbHost_from_d…
Browse files Browse the repository at this point in the history
…eviceGroup

Use trust and cbHost from deviceGroup in typeInformation
  • Loading branch information
fgalan authored Nov 21, 2018
2 parents 7da6d83 + eb3dd3f commit 2f986b7
Show file tree
Hide file tree
Showing 9 changed files with 414 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Fix: use trust and cbHost from deviceGroup (#685)
Fix: multientity multimeasure with the same att name
Add missed conf env vars about authentication (#704)
Add timestamp in device and group provision (#655)
Expand All @@ -8,8 +9,8 @@ Fix: object_id fields are not introduced in CB requests by alias plugin (#660)
Add: uses provisioned timezone to generate TimeInstant values (#672)
Using precise dependencies (~=) in packages.json
Fix: updating dependencies due to known vulnerabilities in the previous ones
async: 1.5.2 -> 2.6.1
body-parser: ~1.11.0 -> ~1.18.3
async: 1.5.2 -> 2.6.1
body-parser: ~1.11.0 -> ~1.18.3
express: ~4.11.2 -> ~4.16.4
jison: 0.4.17 -> 0.4.18
moment: ~2.19.4 -> ~2.22.2
Expand Down
1 change: 1 addition & 0 deletions lib/services/common/iotManagerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function register(callback) {
return {
apikey: service.apikey,
token: service.trust,
cbHost: service.cbHost,
entity_type: service.type,
resource: service.resource,
service: service.service,
Expand Down
12 changes: 12 additions & 0 deletions lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ function createInitialEntityNgsi2(deviceData, newDevice, callback) {
}
};

if (deviceData.cbHost && deviceData.cbHost.indexOf('://') !== -1) {
options.url = deviceData.cbHost + '/v2/entities?options=upsert';
} else if (deviceData.cbHost && deviceData.cbHost.indexOf('://') === -1) {
options.url = 'http://' + deviceData.cbHost + '/v2/entities?options=upsert';
}

jsonConcat(options.json, formatAttributesNgsi2(deviceData.active, false));
jsonConcat(options.json, formatAttributesNgsi2(deviceData.staticAttributes, true));
jsonConcat(options.json, formatCommandsNgsi2(deviceData.commands));
Expand Down Expand Up @@ -429,6 +435,12 @@ function updateEntityNgsi2(deviceData, updatedDevice, callback) {
}
};

if (deviceData.cbHost && deviceData.cbHost.indexOf('://') !== -1) {
options.url = deviceData.cbHost + '/v2/entities/' + String(deviceData.name) + '/attrs';
} else if (deviceData.cbHost && deviceData.cbHost.indexOf('://') === -1) {
options.url = 'http://' + deviceData.cbHost + '/v2/entities/' + String(deviceData.name) + '/attrs';
}

jsonConcat(options.json, formatAttributesNgsi2(deviceData.active, false));
jsonConcat(options.json, formatAttributesNgsi2(deviceData.staticAttributes, true));
jsonConcat(options.json, formatCommandsNgsi2(deviceData.commands));
Expand Down
6 changes: 5 additions & 1 deletion lib/services/devices/registrationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ function sendUnregistrationsNgsi2(deviceData, callback) {
'fiware-servicepath': deviceData.subservice
}
};

if (deviceData.cbHost && deviceData.cbHost.indexOf('://') !== -1) {
options.url = deviceData.cbHost + '/v2/registrations/' + deviceData.registrationId;
} else if (deviceData.cbHost && deviceData.cbHost.indexOf('://') === -1) {
options.url = 'http://' + deviceData.cbHost + '/v2/registrations/' + deviceData.registrationId;
}
if (deviceData.registrationId) {
logger.debug(context, 'Sending device unregistrations to Context Broker at [%s]', options.url);
logger.debug(context, 'Using the following request:\n\n%s\n\n', JSON.stringify(options, null, 4));
Expand Down
10 changes: 8 additions & 2 deletions lib/services/ngsi/ngsiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function createRequestObject(url, typeInformation, token) {
if (config.getConfig().authentication && config.getConfig().authentication.enabled) {
headers[config.getConfig().authentication.header] = token;
}

logger.debug(context, 'typeInformation %j', typeInformation);
if (typeInformation) {
if (typeInformation.service) {
headers['fiware-service'] = typeInformation.service;
Expand All @@ -215,8 +215,10 @@ function createRequestObject(url, typeInformation, token) {
serviceContext.subservice = typeInformation.subservice;
}

if (typeInformation.cbHost) {
if (typeInformation.cbHost && typeInformation.cbHost.indexOf('://') !== -1) {
cbHost = typeInformation.cbHost;
} else if (typeInformation.cbHost && typeInformation.cbHost.indexOf('://') === -1) {
cbHost = 'http://' + typeInformation.cbHost;
}
}

Expand Down Expand Up @@ -791,6 +793,10 @@ function executeWithDeviceInformation(operationFunction) {
}
} else {
typeInformation = deviceInformation;
if (deviceGroup && deviceGroup.trust && deviceGroup.cbHost) {
typeInformation.trust = deviceGroup.trust;
typeInformation.cbHost = deviceGroup.cbHost;
}
}

if (config.getConfig().authentication && config.getConfig().authentication.enabled) {
Expand Down
8 changes: 6 additions & 2 deletions lib/services/ngsi/subscriptionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ function subscribeNgsi1(device, triggers, content, callback) {
store = false;
}

if (device.cbHost) {
if (device.cbHost && device.cbHost.indexOf('://') !== -1) {
options.uri = device.cbHost + '/v1/subscribeContext';
} else if (device.cbHost && device.cbHost.indexOf('://') === -1) {
options.uri = 'http://' + device.cbHost + '/v1/subscribeContext';
} else {
options.uri = config.getConfig().contextBroker.url + '/v1/subscribeContext';
Expand Down Expand Up @@ -239,7 +241,9 @@ function subscribeNgsi2(device, triggers, content, callback) {
store = false;
}

if (device.cbHost) {
if (device.cbHost && device.cbHost.indexOf('://') !== -1) {
options.uri = device.cbHost + '/v2/subscriptions';
} else if (device.cbHost && device.cbHost.indexOf('://') === -1) {
options.uri = 'http://' + device.cbHost + '/v2/subscriptions';
} else {
options.uri = config.getConfig().contextBroker.url + '/v2/subscriptions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{
"apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732",
"token": "8970A9078A803H3BL98PINEQRW8342HBAMS",
"cbHost":"http://unexistentHost:1026",
"entity_type": "SensorMachine",
"resource": "/deviceTest",
"service": "theService",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{
"apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732",
"token": "8970A9078A803H3BL98PINEQRW8342HBAMS",
"cbHost":"http://unexistentHost:1026",
"entity_type": "SensorMachine",
"resource": "/deviceTest",
"service": "theService",
Expand Down
Loading

0 comments on commit 2f986b7

Please sign in to comment.