Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use apikey to find, update and remove device #625

Merged
merged 8 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fix: ensure device apikey in already provisioned device (iota-node-lib#1430)
- 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, iota-node-lib#1435)
11 changes: 6 additions & 5 deletions lib/iotaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if (
(!('apikey' in device) || device.apikey === undefined) &&
Expand All @@ -75,11 +75,12 @@ function findOrCreate(deviceId, transport, 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) {
iotAgentLib.updateDevice(device, function (error) {
callback(error, device, group);
});
} else {
callback(null, device, group);
}
callback(null, device, group);
} else if (error.name === 'DEVICE_NOT_FOUND') {
const newDevice = {
id: deviceId,
Expand Down Expand Up @@ -232,7 +233,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
Expand Down
Loading