Skip to content

Commit 44c500e

Browse files
authored
Merge pull request #567 from telefonicaid/task/apply_autoprovision_flag
Task/apply autoprovision flag
2 parents aa5741b + 0f280c4 commit 44c500e

18 files changed

+98
-75
lines changed

CHANGES_NEXT_RELEASE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Add: check autoprovision flag before register device
12
- Fix: upgrade underscore dep from 1.9.1 to 1.12.1 due to vulnerability
23
- (Only tests) Fix: ensure service of groups, device and commands is stored in mongo in lowercase (iota-node-lib#1023)
34
- Add MQTT options `clean` and `clientId` (env vars IOTA_MQTT_CLEAN and IOTA_MQTT_CLIENT_ID) (#414, #466, #497)

lib/iotaUtils.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,34 @@ function findOrCreate(deviceId, transport, group, callback) {
174174
if (!newDevice.transport) {
175175
newDevice.transport = transport;
176176
}
177-
if ('timestamp' in group) {
177+
if ('timestamp' in group && group.timestamp !== undefined) {
178178
newDevice.timestamp = group.timestamp;
179179
}
180-
iotAgentLib.register(newDevice, function (error, device) {
181-
callback(error, device, group);
182-
});
180+
if ('ngsiVersion' in group && group.ngsiVersion !== undefined) {
181+
newDevice.ngsiVersion = group.ngsiVersion;
182+
}
183+
if ('explicitAttrs' in group && group.explicitAttrs !== undefined) {
184+
newDevice.explicitAttrs = group.explicitAttrs;
185+
}
186+
if ('expressionLanguage' in group && group.expressionLanguage !== undefined) {
187+
newDevice.expressionLanguage = group.expressionLanguage;
188+
}
189+
// Check autoprovision flag in order to register or not device
190+
if (group.autoprovision === undefined || group.autoprovision === true) {
191+
iotAgentLib.register(newDevice, function (error, device) {
192+
callback(error, device, group);
193+
});
194+
} else {
195+
config
196+
.getLogger()
197+
.info(
198+
context,
199+
'Device %j not provisioned due autoprovision is disabled by its conf %j',
200+
newDevice,
201+
group
202+
);
203+
callback(new errors.DeviceNotFound(deviceId));
204+
}
183205
} else {
184206
callback(error);
185207
}

test/unit/ngsiv2/HTTP_commands_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('HTTP: Commands', function () {
9191
contextBrokerMock
9292
.matchHeader('fiware-service', 'smartgondor')
9393
.matchHeader('fiware-servicepath', '/gardens')
94-
.post(
94+
.patch(
9595
'/v2/entities/Second%20MQTT%20Device/attrs?type=AnMQTTDevice',
9696
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/updateStatus1.json')
9797
)
@@ -100,7 +100,7 @@ describe('HTTP: Commands', function () {
100100
contextBrokerMock
101101
.matchHeader('fiware-service', 'smartgondor')
102102
.matchHeader('fiware-servicepath', '/gardens')
103-
.post(
103+
.patch(
104104
'/v2/entities/Second%20MQTT%20Device/attrs?type=AnMQTTDevice',
105105
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/updateStatus6.json')
106106
)

test/unit/ngsiv2/HTTP_reveice_measures-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('HTTP: Measure reception ', function () {
130130
contextBrokerMock
131131
.matchHeader('fiware-service', 'smartgondor')
132132
.matchHeader('fiware-servicepath', '/gardens')
133-
.post(
133+
.patch(
134134
'/v2/entities/Second%20MQTT%20Device/attrs',
135135
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes.json')
136136
)
@@ -195,7 +195,7 @@ describe('HTTP: Measure reception ', function () {
195195
contextBrokerMock
196196
.matchHeader('fiware-service', 'smartgondor')
197197
.matchHeader('fiware-servicepath', '/gardens')
198-
.post(
198+
.patch(
199199
'/v2/entities/e0130101/attrs',
200200
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures3.json')
201201
)
@@ -268,7 +268,7 @@ describe('HTTP: Measure reception ', function () {
268268
contextBrokerMock
269269
.matchHeader('fiware-service', 'smartgondor')
270270
.matchHeader('fiware-servicepath', '/gardens')
271-
.post(
271+
.patch(
272272
'/v2/entities/e0130101/attrs',
273273
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
274274
)
@@ -341,7 +341,7 @@ describe('HTTP: Measure reception ', function () {
341341
contextBrokerMock
342342
.matchHeader('fiware-service', 'smartgondor')
343343
.matchHeader('fiware-servicepath', '/gardens')
344-
.post(
344+
.patch(
345345
'/v2/entities/e0130101/attrs',
346346
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures3.json')
347347
)
@@ -414,7 +414,7 @@ describe('HTTP: Measure reception ', function () {
414414
contextBrokerMock
415415
.matchHeader('fiware-service', 'smartgondor')
416416
.matchHeader('fiware-servicepath', '/gardens')
417-
.post(
417+
.patch(
418418
'/v2/entities/e0130101/attrs',
419419
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
420420
)
@@ -475,7 +475,7 @@ describe('HTTP: Measure reception ', function () {
475475
contextBrokerUnprovMock
476476
.matchHeader('fiware-service', 'smartgondor')
477477
.matchHeader('fiware-servicepath', '/gardens')
478-
.post(
478+
.patch(
479479
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
480480
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice.json')
481481
)

test/unit/ngsiv2/HTTP_reveice_measures-test2.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('HTTP: Measure reception ', function () {
144144
contextBrokerMock
145145
.matchHeader('fiware-service', 'smartgondor')
146146
.matchHeader('fiware-servicepath', '/gardens')
147-
.post(
147+
.patch(
148148
'/v2/entities/Second%20MQTT%20Device/attrs',
149149
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes2.json')
150150
)
@@ -153,7 +153,7 @@ describe('HTTP: Measure reception ', function () {
153153
contextBrokerMock
154154
.matchHeader('fiware-service', 'smartgondor')
155155
.matchHeader('fiware-servicepath', '/gardens')
156-
.post(
156+
.patch(
157157
'/v2/entities/Second%20MQTT%20Device/attrs',
158158
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes.json')
159159
)
@@ -223,7 +223,7 @@ describe('HTTP: Measure reception ', function () {
223223
contextBrokerMock
224224
.matchHeader('fiware-service', 'smartgondor')
225225
.matchHeader('fiware-servicepath', '/gardens')
226-
.post(
226+
.patch(
227227
'/v2/entities/e0130101/attrs',
228228
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
229229
)
@@ -233,7 +233,7 @@ describe('HTTP: Measure reception ', function () {
233233
contextBrokerMock
234234
.matchHeader('fiware-service', 'smartgondor')
235235
.matchHeader('fiware-servicepath', '/gardens')
236-
.post(
236+
.patch(
237237
'/v2/entities/e0130101/attrs',
238238
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures2.json')
239239
)
@@ -310,7 +310,7 @@ describe('HTTP: Measure reception ', function () {
310310
contextBrokerMock
311311
.matchHeader('fiware-service', 'smartgondor')
312312
.matchHeader('fiware-servicepath', '/gardens')
313-
.post(
313+
.patch(
314314
'/v2/entities/e0130101/attrs',
315315
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
316316
)
@@ -320,7 +320,7 @@ describe('HTTP: Measure reception ', function () {
320320
contextBrokerMock
321321
.matchHeader('fiware-service', 'smartgondor')
322322
.matchHeader('fiware-servicepath', '/gardens')
323-
.post(
323+
.patch(
324324
'/v2/entities/e0130101/attrs',
325325
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures2.json')
326326
)
@@ -387,7 +387,7 @@ describe('HTTP: Measure reception ', function () {
387387
contextBrokerUnprovMock
388388
.matchHeader('fiware-service', 'smartgondor')
389389
.matchHeader('fiware-servicepath', '/gardens')
390-
.post(
390+
.patch(
391391
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
392392
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice2.json')
393393
)
@@ -397,7 +397,7 @@ describe('HTTP: Measure reception ', function () {
397397
contextBrokerUnprovMock
398398
.matchHeader('fiware-service', 'smartgondor')
399399
.matchHeader('fiware-servicepath', '/gardens')
400-
.post(
400+
.patch(
401401
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
402402
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice.json')
403403
)

test/unit/ngsiv2/MQTT_commands_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('MQTT: Commands', function () {
102102
contextBrokerMock
103103
.matchHeader('fiware-service', 'smartgondor')
104104
.matchHeader('fiware-servicepath', '/gardens')
105-
.post(
105+
.patch(
106106
'/v2/entities/Second%20MQTT%20Device/attrs?type=AnMQTTDevice',
107107
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/updateStatus1.json')
108108
)

test/unit/ngsiv2/MQTT_receive_measures-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('MQTT: Measure reception ', function () {
112112
contextBrokerMock
113113
.matchHeader('fiware-service', 'smartgondor')
114114
.matchHeader('fiware-servicepath', '/gardens')
115-
.post(
115+
.patch(
116116
'/v2/entities/Second%20MQTT%20Device/attrs',
117117
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes.json')
118118
)
@@ -177,7 +177,7 @@ describe('MQTT: Measure reception ', function () {
177177
contextBrokerUnprovMock
178178
.matchHeader('fiware-service', 'smartgondor')
179179
.matchHeader('fiware-servicepath', '/gardens')
180-
.post(
180+
.patch(
181181
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
182182
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice.json')
183183
)
@@ -228,7 +228,7 @@ describe('MQTT: Measure reception ', function () {
228228
contextBrokerMock
229229
.matchHeader('fiware-service', 'smartgondor')
230230
.matchHeader('fiware-servicepath', '/gardens')
231-
.post(
231+
.patch(
232232
'/v2/entities/Second%20MQTT%20Device/attrs',
233233
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unknownMeasures.json')
234234
)
@@ -268,7 +268,7 @@ describe('MQTT: Measure reception ', function () {
268268
contextBrokerMock
269269
.matchHeader('fiware-service', 'smartgondor')
270270
.matchHeader('fiware-servicepath', '/gardens')
271-
.post(
271+
.patch(
272272
'/v2/entities/Second%20MQTT%20Device/attrs',
273273
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timestampMeasure.json')
274274
)
@@ -310,7 +310,7 @@ describe('MQTT: Measure reception ', function () {
310310
contextBrokerMock
311311
.matchHeader('fiware-service', 'smartgondor')
312312
.matchHeader('fiware-servicepath', '/gardens')
313-
.post(
313+
.patch(
314314
'/v2/entities/Second%20MQTT%20Device/attrs',
315315
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasure.json')
316316
)

test/unit/ngsiv2/MQTT_receive_measures-test2.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('MQTT: Measure reception ', function () {
112112
contextBrokerMock
113113
.matchHeader('fiware-service', 'smartgondor')
114114
.matchHeader('fiware-servicepath', '/gardens')
115-
.post(
115+
.patch(
116116
'/v2/entities/Second%20MQTT%20Device/attrs',
117117
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes.json')
118118
)
@@ -122,7 +122,7 @@ describe('MQTT: Measure reception ', function () {
122122
contextBrokerMock
123123
.matchHeader('fiware-service', 'smartgondor')
124124
.matchHeader('fiware-servicepath', '/gardens')
125-
.post(
125+
.patch(
126126
'/v2/entities/Second%20MQTT%20Device/attrs',
127127
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes2.json')
128128
)
@@ -215,7 +215,7 @@ describe('MQTT: Measure reception ', function () {
215215
contextBrokerUnprovMock
216216
.matchHeader('fiware-service', 'smartgondor')
217217
.matchHeader('fiware-servicepath', '/gardens')
218-
.post(
218+
.patch(
219219
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
220220
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice.json')
221221
)
@@ -225,7 +225,7 @@ describe('MQTT: Measure reception ', function () {
225225
contextBrokerUnprovMock
226226
.matchHeader('fiware-service', 'smartgondor')
227227
.matchHeader('fiware-servicepath', '/gardens')
228-
.post(
228+
.patch(
229229
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
230230
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice2.json')
231231
)
@@ -288,7 +288,7 @@ describe('MQTT: Measure reception ', function () {
288288
contextBrokerMock
289289
.matchHeader('fiware-service', 'smartgondor')
290290
.matchHeader('fiware-servicepath', '/gardens')
291-
.post(
291+
.patch(
292292
'/v2/entities/Second%20MQTT%20Device/attrs',
293293
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unknownMeasures.json')
294294
)
@@ -298,7 +298,7 @@ describe('MQTT: Measure reception ', function () {
298298
contextBrokerMock
299299
.matchHeader('fiware-service', 'smartgondor')
300300
.matchHeader('fiware-servicepath', '/gardens')
301-
.post(
301+
.patch(
302302
'/v2/entities/Second%20MQTT%20Device/attrs',
303303
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unknownMeasures2.json')
304304
)
@@ -350,7 +350,7 @@ describe('MQTT: Measure reception ', function () {
350350
contextBrokerMock
351351
.matchHeader('fiware-service', 'smartgondor')
352352
.matchHeader('fiware-servicepath', '/gardens')
353-
.post(
353+
.patch(
354354
'/v2/entities/Second%20MQTT%20Device/attrs',
355355
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timestampMeasure.json')
356356
)
@@ -360,7 +360,7 @@ describe('MQTT: Measure reception ', function () {
360360
contextBrokerMock
361361
.matchHeader('fiware-service', 'smartgondor')
362362
.matchHeader('fiware-servicepath', '/gardens')
363-
.post(
363+
.patch(
364364
'/v2/entities/Second%20MQTT%20Device/attrs',
365365
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timestampMeasure2.json')
366366
)

test/unit/ngsiv2/amqpBinding-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('AMQP Transport binding: measures', function () {
103103
contextBrokerMock
104104
.matchHeader('fiware-service', 'smartgondor')
105105
.matchHeader('fiware-servicepath', '/gardens')
106-
.post(
106+
.patch(
107107
'/v2/entities/Second%20MQTT%20Device/attrs',
108108
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP.json')
109109
)
@@ -145,7 +145,7 @@ describe('AMQP Transport binding: measures', function () {
145145
contextBrokerUnprovMock
146146
.matchHeader('fiware-service', 'TestService')
147147
.matchHeader('fiware-servicepath', '/testingPath')
148-
.post(
148+
.patch(
149149
'/v2/entities/SensorMachine:JSON_UNPROVISIONED/attrs',
150150
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedMeasure.json')
151151
)
@@ -172,7 +172,7 @@ describe('AMQP Transport binding: measures', function () {
172172
contextBrokerMock
173173
.matchHeader('fiware-service', 'smartgondor')
174174
.matchHeader('fiware-servicepath', '/gardens')
175-
.post(
175+
.patch(
176176
'/v2/entities/Second%20MQTT%20Device/attrs',
177177
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP.json')
178178
)
@@ -216,7 +216,7 @@ describe('AMQP Transport binding: measures', function () {
216216
contextBrokerMock
217217
.matchHeader('fiware-service', 'smartgondor')
218218
.matchHeader('fiware-servicepath', '/gardens')
219-
.post(
219+
.patch(
220220
'/v2/entities/Second%20MQTT%20Device/attrs',
221221
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure.json')
222222
)

test/unit/ngsiv2/amqpBinding-test2.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('AMQP Transport binding: multiple measures', function () {
103103
contextBrokerMock
104104
.matchHeader('fiware-service', 'smartgondor')
105105
.matchHeader('fiware-servicepath', '/gardens')
106-
.post(
106+
.patch(
107107
'/v2/entities/Second%20MQTT%20Device/attrs',
108108
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP.json')
109109
)
@@ -113,7 +113,7 @@ describe('AMQP Transport binding: multiple measures', function () {
113113
contextBrokerMock
114114
.matchHeader('fiware-service', 'smartgondor')
115115
.matchHeader('fiware-servicepath', '/gardens')
116-
.post(
116+
.patch(
117117
'/v2/entities/Second%20MQTT%20Device/attrs',
118118
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP2.json')
119119
)
@@ -140,7 +140,7 @@ describe('AMQP Transport binding: multiple measures', function () {
140140
contextBrokerMock
141141
.matchHeader('fiware-service', 'smartgondor')
142142
.matchHeader('fiware-servicepath', '/gardens')
143-
.post(
143+
.patch(
144144
'/v2/entities/Second%20MQTT%20Device/attrs',
145145
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure.json')
146146
)
@@ -150,7 +150,7 @@ describe('AMQP Transport binding: multiple measures', function () {
150150
contextBrokerMock
151151
.matchHeader('fiware-service', 'smartgondor')
152152
.matchHeader('fiware-servicepath', '/gardens')
153-
.post(
153+
.patch(
154154
'/v2/entities/Second%20MQTT%20Device/attrs',
155155
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure2.json')
156156
)

0 commit comments

Comments
 (0)