This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
iothub-explorer-list.js
43 lines (34 loc) · 1.72 KB
/
iothub-explorer-list.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
#!/usr/bin/env node
// 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 program = require('commander');
var serviceError = require('./common.js').serviceError;
var createDeviceJSONObject = require('./common.js').createDeviceJSONObject;
var getHostFromSas = require('./common.js').getHostFromSas;
var getSas = require('./common.js').getSas;
var Registry = require('azure-iothub').Registry;
var prettyjson = require('prettyjson');
var showDeprecationText = require('./common.js').showDeprecationText;
showDeprecationText('az iot hub device-identity list');
program
.description('List the device identities currently in your IoT hub device registry')
.option('-l, --login <connection-string>', 'use the connection string provided as argument to use to authenticate with your IoT hub')
.option('-d, --display <property-filter>', 'filter the properties of the device that should be displayed using a comma-separated list of property names')
.option('-r, --raw', 'use this flag to return raw output instead of pretty-printed output')
.option('-c, --connection-string', '[deprecated] The connection string is now displayed by default')
.parse(process.argv);
var sas = getSas(program.login);
var registry = Registry.fromSharedAccessSignature(sas);
registry.list(function (err, devices) {
if (err) serviceError(err);
else {
var host = getHostFromSas(sas);
var results = [];
devices.forEach(function (device) {
results.push(createDeviceJSONObject(device, host, program.display, program.raw));
});
results = program.raw ? JSON.stringify(results) : prettyjson.render(results);
console.log(results);
}
});