From 2d1be108bb78d1b13dc78d0e6db42b608ce3ff71 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 5 Sep 2023 11:49:12 +0200 Subject: [PATCH 1/7] use apikey to find device --- lib/iotaUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/iotaUtils.js b/lib/iotaUtils.js index 84f55fad..2a94ce8b 100644 --- a/lib/iotaUtils.js +++ b/lib/iotaUtils.js @@ -63,8 +63,8 @@ function getEffectiveApiKey(service, subservice, device, callback) { } } -function findOrCreate(deviceId, transport, group, callback) { - iotAgentLib.getDeviceSilently(deviceId, group.service, group.subservice, function (error, device) { +function findOrCreate(deviceId, transport, apikey, group, callback) { + iotAgentLib.getDeviceSilently(deviceId, apikey, group.service, group.subservice, function (error, device) { if (!error && device) { callback(null, device, group); } else if (error.name === 'DEVICE_NOT_FOUND') { @@ -219,7 +219,7 @@ function retrieveDevice(deviceId, apiKey, transport, callback) { async.waterfall( [ apply(iotAgentLib.getConfigurationSilently, config.getConfig().iota.defaultResource, apiKey), - apply(findOrCreate, deviceId, transport), + apply(findOrCreate, deviceId, transport, apiKey), // group.apikey and apikey are the same mergeDeviceWithConfiguration ], callback From 435d4d0cac4c5515ab33b44aa51acdc9c0e8c0e6 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 5 Sep 2023 17:25:46 +0200 Subject: [PATCH 2/7] use updateDevice --- lib/iotaUtils.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/iotaUtils.js b/lib/iotaUtils.js index 82111f11..c570624b 100644 --- a/lib/iotaUtils.js +++ b/lib/iotaUtils.js @@ -75,11 +75,12 @@ function findOrCreate(deviceId, transport, apikey, group, callback) { .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); + iotAgentLib.updateDevice(device, function (error) { + callback(null, device, group); }); + } else { + callback(null, device, group); } - callback(null, device, group); } else if (error.name === 'DEVICE_NOT_FOUND') { const newDevice = { id: deviceId, From d9fac84857d41c5e1bcb726492da482bf1897bf6 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 6 Sep 2023 13:18:11 +0200 Subject: [PATCH 3/7] update CNR --- CHANGES_NEXT_RELEASE | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index f5f0d296..6c119b39 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1,2 @@ +- Fix: try to use apikey from measure/group to find device in first attempt (iota-node-lib#1426) - Fix: ensure device apikey in already provisioned device (iota-node-lib#1430) From df257532bcc36b0dd8512e5727dc74ea6028c3a6 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 11 Sep 2023 09:24:54 +0200 Subject: [PATCH 4/7] fix linter error --- lib/iotaUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iotaUtils.js b/lib/iotaUtils.js index c570624b..e3ccc430 100644 --- a/lib/iotaUtils.js +++ b/lib/iotaUtils.js @@ -76,7 +76,7 @@ function findOrCreate(deviceId, transport, apikey, group, callback) { .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.updateDevice(device, function (error) { - callback(null, device, group); + callback(error, device, group); }); } else { callback(null, device, group); From c14014f359e4a0049cce9279103121a873a0662d Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 11 Sep 2023 09:51:07 +0200 Subject: [PATCH 5/7] 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 6c119b39..99cacfde 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,2 +1,2 @@ -- Fix: try to use apikey from measure/group to find device in first attempt (iota-node-lib#1426) +- Fix: try to use apikey from measure/group to find, update and remove device in first attempt (iota-node-lib#1426) - Fix: ensure device apikey in already provisioned device (iota-node-lib#1430) From fd8bb4648e3a12be4c29cd669c07768a818d4476 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 11 Sep 2023 10:05:51 +0200 Subject: [PATCH 6/7] 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 99cacfde..5c3335a7 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,2 +1,2 @@ - Fix: try to use apikey from measure/group to find, update and remove device in first attempt (iota-node-lib#1426) -- Fix: ensure device apikey in already provisioned device (iota-node-lib#1430) +- Fix: ensure device apikey in already provisioned device (iota-node-lib#1430,#1435) From d5b84903526046eed8ae1ceeb810313549eb05af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Mon, 11 Sep 2023 10:09:40 +0200 Subject: [PATCH 7/7] 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 5c3335a7..9169e9e9 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,2 +1,2 @@ - Fix: try to use apikey from measure/group to find, update and remove device in first attempt (iota-node-lib#1426) -- Fix: ensure device apikey in already provisioned device (iota-node-lib#1430,#1435) +- Fix: ensure device apikey in already provisioned device (iota-node-lib#1430, iota-node-lib#1435)