-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathcreate_individual_symmetric_enrollment.js
54 lines (49 loc) · 1.65 KB
/
create_individual_symmetric_enrollment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var provisioningServiceClient = require('azure-iot-provisioning-service').ProvisioningServiceClient;
var argv = require('yargs')
.usage('Usage: $0 --deviceid <DEVICE ID> --connectionstring <DEVICE PROVISIONING CONNECTION STRING> --webhookurl <URL OF THE AZURE FUNCTION>')
.option('deviceid', {
alias: 'd',
describe: 'Unique identifier for the device that shall be created',
type: 'string',
demandOption: true
})
.option('connectionstring', {
alias: 'c',
describe: 'The connection string for the Device Provisioning instance',
type: 'string',
demandOption: true
})
.option('webhookurl', {
alias: 'w',
describe: 'web url of the azure function',
type: 'string',
demandOption: true
})
.argv;
var deviceID = argv.deviceid;
var connectionString = argv.connectionstring;
var webHookUrl = argv.webhookurl;
var serviceClient = provisioningServiceClient.fromConnectionString(connectionString);
var enrollment = {
registrationId: deviceID,
deviceID: deviceID,
attestation: {
type: 'symmetricKey'
},
provisioningStatus: 'enabled',
allocationPolicy: 'custom',
customAllocationDefinition: {
webhookUrl: webHookUrl,
apiVersion: '2019-03-31'
}
};
serviceClient.createOrUpdateIndividualEnrollment(enrollment, function (err, enrollmentResponse) {
if (err) {
console.log('error creating the individual enrollment: ' + err);
} else {
console.log("enrollment record returned: " + JSON.stringify(enrollmentResponse, null, 2));
}
});