-
Notifications
You must be signed in to change notification settings - Fork 226
/
create_enrollment_group.js
58 lines (52 loc) · 1.84 KB
/
create_enrollment_group.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
55
56
57
58
// 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 fs = require('fs');
var provisioningServiceClient = require('azure-iot-provisioning-service').ProvisioningServiceClient;
var argv = require('yargs')
.usage('Usage: $0 --connectionstring <DEVICE PROVISIONING CONNECTION STRING> --certificagte <PATH TO CERTIFICATE> ')
.option('connectionstring', {
alias: 'c',
describe: 'The connection string for the Device Provisioning instance',
type: 'string',
demandOption: true
})
.option('certificate', {
alias: 'ce',
describe: 'certificated used for group enrollment',
type: 'string',
demandOption: true
})
.argv;
var connectionString = argv.connectionString;
var certificate = argv.certificate;
var serviceClient = provisioningServiceClient.fromConnectionString(connectionString);
var enrollment = {
enrollmentGroupId: 'first',
attestation: {
type: 'x509',
x509: {
signingCertificates: {
primary: {
certificate: fs.readFileSync(certificate, 'utf-8').toString()
}
}
}
},
provisioningStatus: 'disabled'
};
serviceClient.createOrUpdateEnrollmentGroup(enrollment, function (err, enrollmentResponse) {
if (err) {
console.log('error creating the group enrollment: ' + err);
} else {
console.log("enrollment record returned: " + JSON.stringify(enrollmentResponse, null, 2));
enrollmentResponse.provisioningStatus = 'enabled';
serviceClient.createOrUpdateEnrollmentGroup(enrollmentResponse, function (err, enrollmentResponse) {
if (err) {
console.log('error updating the group enrollment: ' + err);
} else {
console.log("updated enrollment record returned: " + JSON.stringify(enrollmentResponse, null, 2));
}
});
}
});