Skip to content

Commit

Permalink
Merge pull request #744 from telefonicaid/task/ensure_device_apikey_i…
Browse files Browse the repository at this point in the history
…n_already_provisioned_devices

ensure apikey from measure/group in already provisioned device
  • Loading branch information
fgalan authored Sep 5, 2023
2 parents 8fbafc6 + 11bc12e commit e9c37c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1 @@

- Fix: ensure device apikey in already provisioned device (iota-node-lib#1430)
13 changes: 13 additions & 0 deletions lib/iotaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ function createConfigurationNotification(results) {
function findOrCreate(deviceId, transport, group, callback) {
iotAgentLib.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
) {
config
.getLogger()
.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
iotAgentLib.updateRegister(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 e9c37c7

Please sign in to comment.