Skip to content

Commit

Permalink
Merge ce50d89 into c460e64
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Apr 4, 2024
2 parents c460e64 + ce50d89 commit cea9645
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- ADD: allow devices with the same device_id in the same service and subservice but different apikey (#1589)
6 changes: 3 additions & 3 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ parameters. The specific parameters that can be configured for a given config gr
### Devices

A device contains the information that connects a physical device to a particular entity in the Context Broker. Devices
are identified by a `device_id`, and they are associated to an existing config group based in `apiKey` matching or
`type` matching (in the case `apiKey` matching fails). For instance, let's consider a situation in which a config group
has been provisioned with `type=X`/`apiKey=111` and no other config group has been provisioned.
are identified by a `device_id`, and they are associated to an existing config group based in `apiKey` matching. For
instance, let's consider a situation in which a config group has been provisioned with `type=X`/`apiKey=111` and no
other config group has been provisioned.

The IoT Agents offer a provisioning API where devices can be preregistered, so all the information about service and
subservice mapping, security information and attribute configuration can be specified in a per device way instead of
Expand Down
5 changes: 4 additions & 1 deletion lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ class DuplicateDeviceId {
constructor(device) {
this.name = 'DUPLICATE_DEVICE_ID';
this.message =
'A device with the same pair (Service, DeviceId) was found:' + device.id + ' and ' + JSON.stringify(device);
'A device with the same info (DeviceId, ApiKey, Service, Subservice) was found:' +
device.id +
' and ' +
JSON.stringify(device);
this.code = 409;
}
}
Expand Down
9 changes: 1 addition & 8 deletions lib/services/devices/deviceRegistryMongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,7 @@ function getDeviceById(id, apikey, service, subservice, callback) {
function getDevice(id, apikey, service, subservice, callback) {
getDeviceById(id, apikey, service, subservice, function (error, data) {
if (error) {
// Try without apikey: apikey will be added to device later
getDeviceById(id, null, service, subservice, function (error, data) {
if (error) {
callback(error);
} else {
callback(null, data);
}
});
callback(error);
} else {
callback(null, data);
}
Expand Down
1 change: 1 addition & 0 deletions lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ function findOrCreate(deviceId, apikey, group, callback) {
} else if (error.name === 'DEVICE_NOT_FOUND') {
const newDevice = {
id: deviceId,
apikey: apikey,
service: group.service,
subservice: group.subservice,
type: group.type
Expand Down

0 comments on commit cea9645

Please sign in to comment.