From b0056b91e1537b150969c1c75f9d6583fdb2f64b Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 5 Sep 2023 12:29:59 +0200 Subject: [PATCH 1/3] ensure apikey from measure/group in already provisioned device --- lib/iotaUtils.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/iotaUtils.js b/lib/iotaUtils.js index e5f94d8c..b6fd2cde 100644 --- a/lib/iotaUtils.js +++ b/lib/iotaUtils.js @@ -142,6 +142,17 @@ 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 + ) { + 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 + iotAgentLib.updateRegister(device, function (error, device) { + callback(error, device, group); + }); + } callback(null, device, group); } else if (error.name === 'DEVICE_NOT_FOUND') { const newDevice = { From 9ba16064a14f8aca00476fa1e27452d7ded68248 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 5 Sep 2023 13:09:12 +0200 Subject: [PATCH 2/3] update CNR --- CHANGES_NEXT_RELEASE | 2 +- lib/iotaUtils.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 8b137891..e0278fdb 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1 @@ - +- Ensure device apikey in already provisioned device (iota-node-lib#1430) diff --git a/lib/iotaUtils.js b/lib/iotaUtils.js index b6fd2cde..2b2df76e 100644 --- a/lib/iotaUtils.js +++ b/lib/iotaUtils.js @@ -147,7 +147,9 @@ function findOrCreate(deviceId, transport, group, callback) { 'apikey' in group && group.apikey !== undefined ) { - logger.info(context, 'Update provisioned device %j with measure/group apikey %j', device, group.apikey); + 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); From 11bc12eba19066f0bd05495a44f6a4e9ad9b6aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Tue, 5 Sep 2023 13:45:38 +0200 Subject: [PATCH 3/3] Update CHANGES_NEXT_RELEASE --- CHANGES_NEXT_RELEASE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index e0278fdb..f5f0d296 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1 @@ -- Ensure device apikey in already provisioned device (iota-node-lib#1430) +- Fix: ensure device apikey in already provisioned device (iota-node-lib#1430)