Skip to content

Commit

Permalink
provide device apikey to getDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Sep 5, 2023
1 parent 70d1d3d commit 7ec6e79
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/services/devices/deviceRegistryMemory.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function listDevices(type, service, subservice, limit, offset, callback) {
});
}

function getDevice(id, service, subservice, callback) {
function getDevice(id, apikey, service, subservice, callback) {
if (registeredDevices[service] && registeredDevices[service][id]) {
callback(null, registeredDevices[service][id]);
} else {
Expand Down
6 changes: 4 additions & 2 deletions lib/services/devices/deviceRegistryMongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,14 @@ function findOneInMongoDB(queryParams, id, callback) {
* @param {String} subservice Division inside the service (optional).
*/
function getDeviceById(id, apikey, service, subservice, callback) {
const queryParams = {
let queryParams = {
id,
apikey,
service,
subservice
};
if (apikey) {
queryParams.apikey = apikey;
}
context = fillService(context, queryParams);
logger.debug(context, 'Looking for device with id [%s].', id);
findOneInMongoDB(queryParams, id, callback);
Expand Down
5 changes: 3 additions & 2 deletions lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ function registerDevice(deviceObj, callback) {
function checkDuplicates(deviceObj, innerCb) {
config.getRegistry().getSilently(
deviceObj.id,
deviceObj.apikey,
deviceObj.service,
deviceObj.subservice,
/* eslint-disable-next-line no-unused-vars */
Expand Down Expand Up @@ -430,7 +431,7 @@ function unregisterDevice(id, service, subservice, callback) {

logger.debug(context, 'Removing device register in Device Service');

config.getRegistry().get(id, service, subservice, function (error, device) {
config.getRegistry().get(id, null, service, subservice, function (error, device) {
if (error) {
callback(error);
} else {
Expand Down Expand Up @@ -530,7 +531,7 @@ function listDevices(service, subservice, limit, offset, callback) {
* @param {String} subservice Subservice inside the service for which the device is requested.
*/
function getDevice(deviceId, service, subservice, callback) {
config.getRegistry().get(deviceId, service, subservice, callback);
config.getRegistry().get(deviceId, null, service, subservice, callback);
}

/**
Expand Down
16 changes: 14 additions & 2 deletions lib/services/devices/devices-NGSI-LD.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,13 @@ function updateRegisterDeviceNgsiLD(deviceObj, entityInfoUpdated, callback) {
if (entityInfoUpdated) {
async.waterfall(
[
apply(config.getRegistry().get, deviceObj.id, deviceObj.service, deviceObj.subservice),
apply(
config.getRegistry().get,
deviceObj.id,
deviceObj.apikey,
deviceObj.service,
deviceObj.subservice
),
apply(extractDeviceDifference, deviceObj),
createInitialEntityNgsiLD,
apply(combineWithNewDevice, deviceObj),
Expand All @@ -382,7 +388,13 @@ function updateRegisterDeviceNgsiLD(deviceObj, entityInfoUpdated, callback) {
} else {
async.waterfall(
[
apply(config.getRegistry().get, deviceObj.id, deviceObj.service, deviceObj.subservice),
apply(
config.getRegistry().get,
deviceObj.id,
deviceObj.apikey,
deviceObj.service,
deviceObj.subservice
),
apply(extractDeviceDifference, deviceObj),
updateEntityNgsiLD,
apply(combineWithNewDevice, deviceObj),
Expand Down
16 changes: 14 additions & 2 deletions lib/services/devices/devices-NGSI-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,13 @@ function updateRegisterDeviceNgsi2(deviceObj, entityInfoUpdated, callback) {
if (entityInfoUpdated) {
async.waterfall(
[
apply(config.getRegistry().get, deviceObj.id, deviceObj.service, deviceObj.subservice),
apply(
config.getRegistry().get,
deviceObj.id,
deviceObj.apikey,
deviceObj.service,
deviceObj.subservice
),
apply(extractDeviceDifference, deviceObj),
createInitialEntityNgsi2,
apply(combineWithNewDevice, deviceObj),
Expand All @@ -437,7 +443,13 @@ function updateRegisterDeviceNgsi2(deviceObj, entityInfoUpdated, callback) {
} else {
async.waterfall(
[
apply(config.getRegistry().get, deviceObj.id, deviceObj.service, deviceObj.subservice),
apply(
config.getRegistry().get,
deviceObj.id,
deviceObj.apikey,
deviceObj.service,
deviceObj.subservice
),
apply(extractDeviceDifference, deviceObj),
updateEntityNgsi2,
apply(combineWithNewDevice, deviceObj),
Expand Down

0 comments on commit 7ec6e79

Please sign in to comment.