Skip to content

Commit

Permalink
Merge pull request #1431 from telefonicaid/task/ensure_device_apikey_…
Browse files Browse the repository at this point in the history
…in_already_provisioned_devices

ensure apikey from measure/group in already provisioned device
  • Loading branch information
fgalan committed Sep 5, 2023
2 parents cf2cfc3 + fa2e39c commit d90c0d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 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: ensure device apikey in already provisioned device (#1430)
- Upgrade mongodb dev dep from 4.7.0 to 4.17.0
- Upgrade mongoose dep from 5.13.14 to 5.13.20
11 changes: 11 additions & 0 deletions lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,17 @@ function checkRegistry(fn) {
function findOrCreate(deviceId, group, callback) {
getDeviceSilently(deviceId, group.service, group.subservice, function (error, device) {
if (!error && device) {
if (
(!('apikey' in device) || device.apikey === undefined) &&
'apikey' in group &&
group.apikey !== undefined
) {
logger.info(context, 'Update provisioned device %j with measure/group apikey %j', device, group.apikey);
device.apikey = group.apikey; // group apikey is the same of current measure apikey
updateRegisterDevice(device, function (error, device) {
callback(error, device, group);
});
}
callback(null, device, group);
} else if (error.name === 'DEVICE_NOT_FOUND') {
const newDevice = {
Expand Down

0 comments on commit d90c0d7

Please sign in to comment.