azure-cli
Version:
Microsoft Azure Cross Platform Command Line tool
1,249 lines (408 loc) • 94.7 kB
JavaScript
/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ "use strict"; var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var util = require("util");
var profile = require("../../../util/profile");
var utils = require("../../../util/utils");
var iotHubUtils = require("./iothubUtils");
var resourceUtils = require("../resource/resourceUtils");
var tagUtils = require("../tag/tagUtils");
var moment = require("moment");
var $ = utils.getLocaleString;
var SKU = ["F1","S1","S2","S3",];
var OPERATIONSMONITORINGCATEGORIES = ["Connections","DeviceTelemetry","C2DCommands","DeviceIdentityOperations","FileUploadOperations",];
var OPERATIONSMONITORINGDIAGLEVELS = ["None","Error","Information",];
exports.init = function(cli) {
var log = cli.output;
var iotHub = cli.category("iothub").description($("Commands to manage your Azure IoT hubs"));
iotHub.command("create [resource-group] [name] [location] [sku-name] [units]").description($("Create a new IoT hub")).usage("<resource-group> <name> <location> <sku-name> <units> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group.")).option("-n --name <name>", $("The name of the new IoT hub.")).option("-l --location <location>", $("The location (azure region/datacenter) where the IoT hub will be provisioned.")).option("-k --sku-name <skuName>", util.format($("The name of the sku, one of: [%s] etc. For the latest full list refer to the pricing page for IoT Hub."), SKU.join(", "))).option("-u --units <units>", $("The number of provisioned units. Range : F1 [1-1] : S1, S2 [1-200] : S3 [1-10].")).option("-e --enable-dm [enableDm]", $("The flag which indicates whether the Device Management feature is enabled for this IoT hub. One of true, false. Default : false")).option("-p --d2c-partitions [d2cPartitions]", $("The number of partitions for your device-to-cloud events. Range : F1 [2-2] Rest of the Skus [2-128]. Default : 2")).option("-r --d2c-retention-time-in-days [d2cRetentionTimeInDays]", $("The number of days for which the device-to-cloud events will be maintained. Range : [1-7]. Default : 1.")).option("-d --c2d-max-delivery-count [c2dMaxDeliveryCount]", $("The number of times the IoT hub will attempt to deliver a cloud-to-device message to a device. Range : [1-100]. Default : 10.")).option("-c --c2d-ttl [c2dTtl]", $("The amount of time for which a cloud to device mesage is available for the device to consume before it is expired by IoT hub. Range : [1-48 hours]. Default : 1 hour.")).option("-f --feedback-lock-duration [feedbackLockDuration]", $("The lock duration for the feedback messages. Range : [5 seconds - 5 minutes]. Default : 1 minute.")).option("-F --feedback-ttl [feedbackTtl]", $("The amount of time a feedback mesage is available for the device to consume before it is expired by IotHub. Range : [1-48 hours]. Default : 1 hour.")).option("-m --feedback-max-delivery-count [feedbackMaxDeliveryCount]", $("The number of times the IoT hub will attempt to deliver a cloud-device feedback message to a device. Range : [1-100]. Default : 1.")).option("-x --enable-fileupload-notifications [enableFileuploadNotifications]", $("The flag that specifies if the file upload notifications should be turned on, One of true, false. Default : false.")).option("-S --fileupload-storage-connectionstring [fileuploadStorageConnectionstring]", $("The storage connection string where the files are to be uploaded. Default : null.")).option("-C --fileupload-container-name [fileuploadContainerName]", $("The storage container name where the files are to be uploaded. Default : null.")).option("-T --fileupload-sas-uri-ttl [fileuploadSasUriTtl]", $("The amount of time for which the SAS Uri generated by IoT hub is valid before it expires. Range : [1-24 hours]. Default : 1 hour.")).option("-N --fileupload-notification-ttl [fileuploadNotificationTtl]", $("The amount of time for which a file upload notification is available for the service to consume before it is expired by IoT hub. Range : [1-48 hours]. Default : 1 hour.")).option("-D --fileupload-notification-max-delivery-count [fileuploadNotificationMaxDeliveryCount]", $("The number of times the IoT hub will attempt to deliver a file notification message. Range [1-100]. Default : 10.")).option("-t --tags [tags]", $((("The tags to set to the resource group. Can be multiple" + "In the format of 'name=value'. name is required and value is optional") + "For example, -t 'tag1=value1;tag2'."))).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __1(resourceGroup, name, location, skuName, units, options, _) { var features, defaultStorageEndpoints, tagsToSet, subscription, client, iotHubCreateParams, progress, result; var __frame = { name: "__1", line: 66 }; return __func(_, this, arguments, __1, 6, __frame, function __$__1() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
if (!location) {
return _(null, cli.missingArgument("location")); } ;
if (!skuName) {
return _(null, cli.missingArgument("sku-name")); } ;
if (!units) {
return _(null, cli.missingArgument("units")); } ;
features = "None";
if ((options.enableDm == "true")) {
features = "DeviceManagement"; } ;
if (!options.d2cPartitions) {
options.d2cPartitions = iotHubUtils.iotHubDefaults.d2cPartitionCount; } ;
if (!options.d2cRetentionTimeInDays) {
options.d2cRetentionTimeInDays = iotHubUtils.iotHubDefaults.d2cRetentionTimeInDays; } ;
if (!options.c2dMaxDeliveryCount) {
options.c2dMaxDeliveryCount = iotHubUtils.iotHubDefaults.c2dMaxDeliveryCount; } ;
if (!options.c2dTtl) {
options.c2dTtl = iotHubUtils.iotHubDefaults.c2dTtl; } ;
if (!options.feedbackLockDuration) {
options.feedbackLockDuration = iotHubUtils.iotHubDefaults.feedbackLockDuration; } ;
if (!options.feedbackTtl) {
options.feedbackTtl = iotHubUtils.iotHubDefaults.feedbackTtl; } ;
if (!options.feedbackMaxDeliveryCount) {
options.feedbackMaxDeliveryCount = iotHubUtils.iotHubDefaults.feedbackMaxDeliveryCount; } ;
if ((options.enableFileuploadNotifications == "true")) {
if (!options.fileuploadStorageConnectionstring) {
return _(null, cli.missingArgument("fileuploadStorageConnectionstring")); } ; } ;
if (!options.fileuploadSasUriTtl) {
options.fileuploadSasUriTtl = iotHubUtils.iotHubDefaults.fileuploadSasUriTtl; } ;
if (!options.fileuploadNotificationTtl) {
options.fileuploadNotificationTtl = iotHubUtils.iotHubDefaults.fileuploadNotificationTtl; } ;
if (!options.fileuploadNotificationMaxDeliveryCount) {
options.fileuploadNotificationMaxDeliveryCount = iotHubUtils.iotHubDefaults.fileuploadNotificationMaxDeliveryCount; } ;
defaultStorageEndpoints = null;
if (options.fileuploadStorageConnectionstring) {
if (!options.fileuploadContainerName) {
return _(null, cli.missingArgument("fileuploadContainerName")); } ;
defaultStorageEndpoints = {
$default: {
connectionString: options.fileuploadStorageConnectionstring,
containerName: options.fileuploadContainerName,
sasTtlAsIso8601: moment.duration(options.fileuploadSasUriTtl) } }; } ;
tagsToSet = null;
if (options.tags) {
tagsToSet = iotHubUtils.parseTagsArgument("tags", options.tags); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
iotHubCreateParams = {
name: name,
location: location,
subscriptionid: options.subscription,
resourcegroup: resourceGroup,
tags: tagsToSet,
sku: {
name: skuName,
capacity: Number(units) },
properties: {
enableFileuploadNotifications: options.enableFileuploadNotifications,
features: features,
eventHubEndpoints: {
events: {
retentionTimeInDays: Number(options.d2cRetentionTimeInDays),
partitionCount: Number(options.d2cPartitions) },
operationsMonitoringEvents: {
retentionTimeInDays: Number(options.d2cRetentionTimeInDays),
partitionCount: Number(options.d2cPartitions) } },
cloudToDevice: {
maxDeliveryCount: Number(options.c2dMaxDeliveryCount),
defaultTtlAsIso8601: moment.duration(options.c2dTtl),
feedback: {
maxDeliveryCount: Number(options.feedbackMaxDeliveryCount),
ttlAsIso8601: moment.duration(options.feedbackTtl),
lockDurationAsIso8601: moment.duration(options.feedbackLockDuration) } },
messagingEndPoints: {
fileNotifications: {
maxDeliveryCount: Number(options.fileuploadNotificationMaxDeliveryCount),
ttlAsIso8601: moment.duration(options.fileuploadNotificationTtl),
lockDurationAsIso8601: moment.duration(iotHubUtils.iotHubDefaults.defaultLockDuration) } } } };
if (options.fileuploadStorageConnectionstring) {
iotHubCreateParams.properties.storageEndpoints = defaultStorageEndpoints; } ;
progress = cli.interaction.progress(util.format($("Creating IoT hub %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__1() {
return client.iotHubResource.createOrUpdate(resourceGroup, name, iotHubCreateParams, __cb(_, __frame, 163, 39, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__1() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__1() {
if (result) {
showResource(result); } ; _(); }); }); }); });
iotHub.command("list [resource-group]").description($("Get all IoT hubs in a subcription or a resource group")).usage("<resource-group> [options]").option("-g --resource-group [resourceGroup]", $("The name of the resource group")).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __2(resourceGroup, options, _) { var subscription, client, progress, iotHubs; var __frame = { name: "__2", line: 247 }; return __func(_, this, arguments, __2, 2, __frame, function __$__2() {
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
progress = cli.interaction.progress($("Listing IoT hubs")); return (function __$__2(__then) {
if (resourceGroup) { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() {
return client.iotHubResource.listByResourceGroup(resourceGroup, __cb(_, __frame, 13, 42, function ___(__0, __1) { iotHubs = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__2() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, __then); }); } else { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__2() {
return client.iotHubResource.listBySubscription(__cb(_, __frame, 19, 42, function ___(__0, __2) { iotHubs = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__2() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, __then); }); } ; })(function __$__2() {
cli.interaction.formatOutput(iotHubs, function(iotHubs) {
if ((iotHubs.length === 0)) {
log.info($("No IoT hubs found."));
return; } ;
log.table(iotHubs, function(row, iotHub) {
row.cell($("Name"), iotHub.name);
row.cell($("Group"), iotHub.resourcegroup);
row.cell($("Location"), iotHub.location);
row.cell($("Sku"), iotHub.sku.name);
row.cell($("Units"), iotHub.sku.capacity); }); }); _(); }); }); });
iotHub.command("show [resource-group] [name]").description($("Get an IoT hub")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group.")).option("-n --name <name>", $("The name of the IoT hub.")).option("-s --subscription [subscription]", $("The subscription identifier.")).execute(function __3(resourceGroup, name, options, _) { var subscription, client, progress, result; var __frame = { name: "__3", line: 301 }; return __func(_, this, arguments, __3, 3, __frame, function __$__3() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
progress = cli.interaction.progress($("Getting IoT hub")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() {
return client.iotHubResource.get(resourceGroup, name, __cb(_, __frame, 28, 39, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__3() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__3() {
if (result) {
showResource(result); } ; _(); }); }); }); });
iotHub.command("show-quota-metrics [resource-group] [name]").description($("Get the IoT hub Quota Metrics")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group.")).option("-n --name <name>", $("The name of the IoT hub.")).option("-s --subscription [subscription]", $("The subscription identifier.")).execute(function __4(resourceGroup, name, options, _) { var subscription, client, progress, quotaMetrics; var __frame = { name: "__4", line: 348 }; return __func(_, this, arguments, __4, 3, __frame, function __$__4() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
progress = cli.interaction.progress($("Getting IoT hub Quota Metrics")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() {
return client.iotHubResource.getQuotaMetrics(resourceGroup, name, __cb(_, __frame, 24, 45, function ___(__0, __1) { quotaMetrics = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__4() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__4() {
cli.interaction.formatOutput(quotaMetrics, function(quotaMetrics) {
if ((quotaMetrics.length === 0)) {
log.info($("No quota metrics found."));
return; } ;
log.table(quotaMetrics, function(row, metric) {
row.cell($("Quota Metric Name"), metric.name);
if ((metric.name == "TotalDeviceCount")) {
row.cell($("MaxValue"), "Unlimited"); }
else {
row.cell($("MaxValue"), metric.maxValue); } ;
row.cell($("Current Value"), metric.currentValue); }); }); _(); }); }); }); });
iotHub.command("show-registry-stats [resource-group] [name]").description($("Get the IoT hub Registry Statistics")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __5(resourceGroup, name, options, _) { var subscription, client, progress, stats; var __frame = { name: "__5", line: 410 }; return __func(_, this, arguments, __5, 3, __frame, function __$__5() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
progress = cli.interaction.progress($("Getting IoT hub Registry Statistics")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__5() {
return client.iotHubResource.getStats(resourceGroup, name, __cb(_, __frame, 27, 38, function ___(__0, __1) { stats = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__5() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__5() {
if (stats) {
cli.output.json(stats); } ; _(); }); }); }); });
iotHub.command("delete [resource-group] [name]").description($("Delete an IoT hub")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub to be deleted")).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __6(resourceGroup, name, options, _) { var subscription, client, progress, result; var __frame = { name: "__6", line: 456 }; return __func(_, this, arguments, __6, 3, __frame, function __$__6() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
progress = cli.interaction.progress(util.format($("Deleting IoT hub %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() {
return client.iotHubResource.deleteMethod(resourceGroup, name, __cb(_, __frame, 25, 39, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__6() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__6() { _(); }); }); }); });
var iotHubIpFilterRules = cli.category("iothub").category("ipfilter-rules").description($("Commands to manage the IP filter rules of an IoT hub"));
iotHubIpFilterRules.command("list [resource-group] [name]").description($("List the IoT hub IP filter rules")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-s --subscription [subscription]", $("The subscription identifier")).fileRelatedOption("-f --output-file [output-file]", $("the path to the JSON-formatted output IP filter rules file in the file system")).execute(function __7(resourceGroup, name, options, _) { var subscription, client, progress, iothubDescription, fs; var __frame = { name: "__7", line: 500 }; return __func(_, this, arguments, __7, 3, __frame, function __$__7() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
progress = cli.interaction.progress($("Getting the IP filter rules.")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__7() {
return client.iotHubResource.get(resourceGroup, name, __cb(_, __frame, 27, 50, function ___(__0, __1) { iothubDescription = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__7() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__7() { return (function __$__7(__then) {
if (iothubDescription) { return (function __$__7(__then) {
if (options.outputFile) { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__7() {
fs = require("fs");
fs.writeFileSync(options.outputFile, JSON.stringify(iothubDescription.properties.ipFilterRules, null, 2)); __then(); }); })(function ___(e, __result) { __catch(function __$__7() { if (e) {
log.error((("Could not write to file " + options.outputFile) + " Error Details :"));
return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, __then); }); } else { __then(); } ; })(function __$__7() {
cli.interaction.formatOutput(iothubDescription.properties.ipFilterRules, function(ipFilterRules) {
log.table(ipFilterRules, function(row, rule) {
row.cell($("FilterName"), rule.filterName);
row.cell($("Action"), rule.action);
row.cell($("IpMask"), rule.ipMask); }); }); __then(); }); } else { __then(); } ; })(_); }); }); }); });
iotHubIpFilterRules.command("set [resource-group] [name] [inputFile]").description($("set the IoT hub IP filter rules")).usage("<resourceGroup> <name> <inputFile> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-s --subscription [subscription]", $("The subscription identifier")).fileRelatedOption("-f --input-file <inputFile>", $("the path to the JSON-formatted input IP filter rules file in the file system")).execute(function __8(resourceGroup, name, inputFile, options, _) { var subscription, client, progress, iothubDescription, fs, jsonFile, result; var __frame = { name: "__8", line: 567 }; return __func(_, this, arguments, __8, 4, __frame, function __$__8() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
if (!inputFile) {
return _(null, cli.missingArgument("inputFile")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
progress = cli.interaction.progress($("Getting the IP filter rules.")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__8() {
return client.iotHubResource.get(resourceGroup, name, __cb(_, __frame, 31, 50, function ___(__0, __1) { iothubDescription = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__8() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__8() { return (function __$__8(__then) {
if (iothubDescription) { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__8() {
fs = require("fs");
jsonFile = fs.readFileSync(inputFile);
iothubDescription.properties.ipFilterRules = JSON.parse(utils.stripBOM(jsonFile)); __then(); }); })(function ___(e, __result) { __catch(function __$__8() { if (e) {
log.error((("Could not read from file " + options.outputFile) + " Error Details :"));
return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, __then); }); } else { __then(); } ; })(function __$__8() {
progress = cli.interaction.progress(util.format($("Updating IoT hub %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__8() {
return client.iotHubResource.createOrUpdate(resourceGroup, name, iothubDescription, __cb(_, __frame, 58, 39, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__8() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__8() {
if (result) {
showResource(result); } ; _(); }); }); }); }); }); }); });
var iotHubd2cproperties = cli.category("iothub").category("device-to-cloud-properties").description($("Commands to manage the Device to Cloud Properties of an IoT hub"));
iotHubd2cproperties.command("set [resource-group] [name]").description($("Set the Device to Cloud properties of an IoT hub")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-r --d2c-retention-time-in-days [d2cRetentionTimeInDays]", $("The number of days for which the device-to-cloud events will be maintained, between 1 and 7")).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __9(resourceGroup, name, options, _) { var subscription, client, iotHubDescription, progress, result; var __frame = { name: "__9", line: 652 }; return __func(_, this, arguments, __9, 3, __frame, function __$__9() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
return client.iotHubResource.get(resourceGroup, name, __cb(_, __frame, 25, 52, function ___(__0, __1) { iotHubDescription = __1;
if (!iotHubDescription) {
return _(notFoundError(resourceGroup, name)); } ;
if (options.d2cRetentionTimeInDays) {
iotHubDescription.properties.eventHubEndpoints["events"].retentionTimeInDays = Number(options.d2cRetentionTimeInDays);
iotHubDescription.properties.eventHubEndpoints["operationsMonitoringEvents"].retentionTimeInDays = Number(options.d2cRetentionTimeInDays); } ;
progress = cli.interaction.progress(util.format($("Updating IoT hub %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__9() {
return client.iotHubResource.createOrUpdate(resourceGroup, name, iotHubDescription, __cb(_, __frame, 47, 39, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__9() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__9() {
if (result) {
showResource(result); } ; _(); }); }); }, true)); }); });
var iotHubc2dproperties = cli.category("iothub").category("cloud-to-device-properties").description($("Commands to manage the Cloud to Device Properties of an IoT hub"));
iotHubc2dproperties.command("set [resource-group] [name]").description($("Set the Cloud to Device properties of an IoT hub")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-d --c2d-max-delivery-count [c2dMaxDeliveryCount]", $("The number of times the IoT hub will attempt to deliver a cloud-to-device message to a device, between 1 and 100")).option("-c --c2d-ttl [c2dTtl]", $("The amount of time for which a mesage is available for the device to consume before it is expired by IoT hub, between 1 and 48 hours")).option("-f --feedback-lock-duration [feedbackLockDuration]", $("The lock duration of the feedback messages, between 5 seconds and 5 minutes")).option("-F --feedback-ttl [feedbackTtl]", $("The amount of time a feedback mesage is available for the device to consume before it is expired by IoT hub, between 1 and 48 hours")).option("-m --feedback-max-delivery-count [feedbackMaxDeliveryCount]", $("The number of times the IoT hub will attempt to deliver a cloud-device feedback message to a device, between 1 and 100")).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __10(resourceGroup, name, options, _) { var subscription, client, iotHubDescription, progress, result; var __frame = { name: "__10", line: 726 }; return __func(_, this, arguments, __10, 3, __frame, function __$__10() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
return client.iotHubResource.get(resourceGroup, name, __cb(_, __frame, 25, 52, function ___(__0, __1) { iotHubDescription = __1;
if (!iotHubDescription) {
return _(notFoundError(resourceGroup, name)); } ;
if (options.c2dMaxDeliveryCount) {
iotHubDescription.properties.cloudToDevice.maxDeliveryCount = Number(options.c2dMaxDeliveryCount); } ;
if (options.c2dTtl) {
iotHubDescription.properties.cloudToDevice.defaultTtlAsIso8601 = moment.duration(options.c2dTtl); } ;
if (options.feedbackLockDuration) {
iotHubDescription.properties.cloudToDevice.feedback.lockDurationAsIso8601 = moment.duration(options.feedbackLockDuration); } ;
if (options.feedbackTtl) {
iotHubDescription.properties.cloudToDevice.feedback.ttlAsIso8601 = moment.duration(options.feedbackTtl); } ;
if (options.feedbackMaxDeliveryCount) {
iotHubDescription.properties.cloudToDevice.feedback.maxDeliveryCount = Number(options.feedbackMaxDeliveryCount); } ;
progress = cli.interaction.progress(util.format($("Updating IoT hub %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__10() {
return client.iotHubResource.createOrUpdate(resourceGroup, name, iotHubDescription, __cb(_, __frame, 62, 39, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__10() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__10() {
if (result) {
showResource(result); } ; _(); }); }); }, true)); }); });
var iotHubfuproperties = cli.category("iothub").category("file-upload-properties").description($("Commands to manage the File Upload Properties of an IoT hub"));
iotHubfuproperties.command("set [resource-group] [name]").description($("Set the File upload Properties of an IoT hub")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-x --enable-fileupload-notifications [enableFileuploadNotifications]", $("The flag that specifies if the file upload notifications should be turned on, one of true, false")).option("-S --fileupload-storage-connectionstring [fileuploadStorageConnectionstring]", $("The storage connection string where the files are to be uploaded")).option("-C --fileupload-container-name [fileuploadContainerName]", $("The storage container name where the files are to be uploaded")).option("-T --fileupload-sas-uri-ttl [fileuploadSasUriTtl]", $("The amount of time for which the SAS Uri generated by IoT hub is valid before it expires, between 1 and 24 hours")).option("-N --fileupload-notification-ttl [fileuploadNotificationTtl]", $("The amount of time for which a file upload notification is available for the service to consume before it is expired by IoT hub, between 1 and 48 hours")).option("-D --fileupload-notification-max-delivery-count [fileuploadNotificationMaxDeliveryCount]", $("The number of times the IoT hub will attempt to deliver a file notification message, between 1 and 100")).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __11(resourceGroup, name, options, _) { var subscription, client, iotHubDescription, messagingEndpoints, progress, result; var __frame = { name: "__11", line: 816 }; return __func(_, this, arguments, __11, 3, __frame, function __$__11() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
return client.iotHubResource.get(resourceGroup, name, __cb(_, __frame, 25, 52, function ___(__0, __1) { iotHubDescription = __1;
if (!iotHubDescription) {
return _(notFoundError(resourceGroup, name)); } ;
if (options.enableFileuploadNotifications) {
if ((options.enableFileuploadNotifications == "true")) {
iotHubDescription.properties.enableFileuploadNotifications = true; } else {
if ((options.enableFileuploadNotifications == "false")) {
iotHubDescription.properties.enableFileuploadNotifications = false; }
else {
return _(null, cli.unknownOption((options.enableFileuploadNotifications + " for enableFileuploadNotifications. Should be true or false."))); } ; } ; } ;
if (options.fileuploadContainerName) {
if (!options.fileuploadStorageConnectionstring) {
return _(null, cli.missingArgument("fileuploadStorageConnectionstring")); } ; } ;
if (options.fileuploadStorageConnectionstring) {
if (!options.fileuploadContainerName) {
return _(null, cli.missingArgument("fileuploadContainerName")); } ;
iotHubDescription.properties.storageEndpoints["$default"].connectionString = options.fileuploadStorageConnectionstring;
iotHubDescription.properties.storageEndpoints["$default"].containerName = options.fileuploadContainerName; } ;
if (options.fileuploadSasUriTtl) {
iotHubDescription.properties.storageEndpoints["$default"].sasTtlAsIso8601 = moment.duration(options.fileuploadSasUriTtl); } ;
if ((options.fileuploadNotificationTtl || options.fileuploadNotificationMaxDeliveryCount)) {
if ((iotHubDescription.properties.enableFileuploadNotifications === true)) {
if ((iotHubDescription.properties.messagingEndpoints === null)) {
if (!options.fileuploadNotificationTtl) {
options.fileuploadNotificationTtl = iotHubUtils.iotHubDefaults.fileuploadNotificationTtl; } ;
if (!options.fileuploadNotificationMaxDeliveryCount) {
options.fileuploadNotificationMaxDeliveryCount = iotHubUtils.iotHubDefaults.fileuploadNotificationMaxDeliveryCount; } ; }
else {
if (!options.fileuploadNotificationTtl) {
options.fileuploadNotificationTtl = iotHubDescription.properties.messagingEndpoints["fileNotifications"].ttlAsIso8601; } ;
if (!options.fileuploadNotificationMaxDeliveryCount) {
options.fileuploadNotificationMaxDeliveryCount = iotHubDescription.properties.messagingEndpoints["fileNotifications"].maxDeliveryCount; } ; } ;
messagingEndpoints = {
fileNotifications: {
maxDeliveryCount: Number(options.fileuploadNotificationMaxDeliveryCount),
ttlAsIso8601: moment.duration(options.fileuploadNotificationTtl),
lockDurationAsIso8601: moment.duration(iotHubUtils.iotHubDefaults.defaultLockDuration) } };
iotHubDescription.properties.messagingEndpoints = messagingEndpoints; } ; } ;
progress = cli.interaction.progress(util.format($("Updating IoT hub %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__11() {
return client.iotHubResource.createOrUpdate(resourceGroup, name, iotHubDescription, __cb(_, __frame, 103, 39, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__11() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__11() {
if (result) {
showResource(result); } ; _(); }); }); }, true)); }); });
var iotHubtags = cli.category("iothub").category("tags").description($("Commands to manage the tags of an Iot hub"));
iotHubtags.command("set [resource-group] [name]").description($("Set tags on the IoT hub")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-t --tags [tags]", $((("The tags to set to the resource group. The tags specified here will replace the existing ones and not append to them. Can be multiple" + "In the format of 'name=value'. Name is required and value is optional") + "For example, -t 'tag1=value1;tag2'."))).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __12(resourceGroup, name, options, _) { var subscription, client, iotHubDescription, progress, result; var __frame = { name: "__12", line: 944 }; return __func(_, this, arguments, __12, 3, __frame, function __$__12() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
return client.iotHubResource.get(resourceGroup, name, __cb(_, __frame, 25, 52, function ___(__0, __1) { iotHubDescription = __1;
if (!iotHubDescription) {
return _(notFoundError(resourceGroup, name)); } ;
if (options.tags) {
iotHubDescription.tags = iotHubUtils.parseTagsArgument("tags", options.tags); } ;
progress = cli.interaction.progress(util.format($("Updating IoT hub %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__12() {
return client.iotHubResource.createOrUpdate(resourceGroup, name, iotHubDescription, __cb(_, __frame, 46, 39, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__12() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__12() {
if (result) {
showResource(result); } ; _(); }); }); }, true)); }); });
var iotHubsku = cli.category("iothub").category("sku").description($("Commands to manage the sku related information of an IoT hub"));
iotHubsku.command("list [resource-group] [name]").description($("List the Valid IoT hub Skus")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __13(resourceGroup, name, options, _) { var subscription, client, progress, skus; var __frame = { name: "__13", line: 1013 }; return __func(_, this, arguments, __13, 3, __frame, function __$__13() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
progress = cli.interaction.progress($("Getting the valid skus.")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__13() {
return client.iotHubResource.getValidSkus(resourceGroup, name, __cb(_, __frame, 24, 37, function ___(__0, __1) { skus = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__13() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__13() {
cli.interaction.formatOutput(skus, function(skus) {
if ((skus.length === 0)) {
log.info($("No valid skus found."));
return; } ;
log.table(skus, function(row, skuDesc) {
row.cell($("Sku Name"), skuDesc.sku.name);
row.cell($("MinUnits"), skuDesc.capacity.minimum);
row.cell($("MaxUnits"), skuDesc.capacity.maximum); }); }); _(); }); }); }); });
iotHubsku.command("show [resource-group] [name]").description($("Get sku info for an IoT hub")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __14(resourceGroup, name, options, _) { var subscription, client, iotHubDescription; var __frame = { name: "__14", line: 1069 }; return __func(_, this, arguments, __14, 3, __frame, function __$__14() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
return client.iotHubResource.get(resourceGroup, name, __cb(_, __frame, 25, 52, function ___(__0, __1) { iotHubDescription = __1;
if (!iotHubDescription) {
return _(notFoundError(resourceGroup, name)); } ;
log.info($(("Sku : " + iotHubDescription.sku.name)));
log.info($(("Units : " + iotHubDescription.sku.capacity))); _(); }, true)); }); });
iotHubsku.command("set [resource-group] [name]").description($("Set sku for an IoT hub")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-k --sku-name <skuName>", util.format($("The name of the sku, one of: [%s]"), SKU.join(", "))).option("-u --units <units>", $("The number of provisioned units")).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __15(resourceGroup, name, options, _) { var subscription, client, iotHubDescription, progress, result; var __frame = { name: "__15", line: 1120 }; return __func(_, this, arguments, __15, 3, __frame, function __$__15() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
if (!options.skuName) {
return _(null, cli.missingArgument("skuName")); } ;
if (!options.units) {
return _(null, cli.missingArgument("units")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
return client.iotHubResource.get(resourceGroup, name, __cb(_, __frame, 33, 52, function ___(__0, __1) { iotHubDescription = __1;
if (!iotHubDescription) {
return _(notFoundError(resourceGroup, name)); } ;
iotHubDescription.sku.name = options.skuName;
iotHubDescription.sku.capacity = Number(options.units);
progress = cli.interaction.progress(util.format($("Updating IoT hub %s"), name)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__15() {
return client.iotHubResource.createOrUpdate(resourceGroup, name, iotHubDescription, __cb(_, __frame, 53, 39, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__15() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__15() {
if (result) {
showResource(result); } ; _(); }); }); }, true)); }); });
var iotHubehcg = cli.category("iothub").category("ehconsumergroup").description($("Commands to manage the event hub consumer groups of an IoT hub"));
iotHubehcg.command("list [resource-group] [name]").description($("List the event hub consumer groups of an IoT hub")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The name of the IoT hub")).option("-e --eh-endpoint-type <ehEndpointType>", $("The type of the event hub endpoint. One of events, operationsMonitoringEvents")).option("-s --subscription [subscription]", $("The subscription identifier")).execute(function __16(resourceGroup, name, options, _) { var subscription, client, progress, ehConsumerGroups; var __frame = { name: "__16", line: 1197 }; return __func(_, this, arguments, __16, 3, __frame, function __$__16() {
if (!resourceGroup) {
return _(null, cli.missingArgument("resource-group")); } ;
if (!name) {
return _(null, cli.missingArgument("name")); } ;
if (!options.ehEndpointType) {
return _(null, cli.missingArgument("eh-endpoint-type")); } ;
subscription = profile.current.getSubscription(options.subscription);
client = utils.getiotHubClient(subscription);
progress = cli.interaction.progress($("Getting the event hub consumer groups.")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__16() {
return client.iotHubResource.listEventHubConsumerGroups(resourceGroup, name, options.ehEndpointType, __cb(_, __frame, 28, 49, function ___(__0, __1) { ehConsumerGroups = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__16() {
progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__16() {
cli.interaction.formatOutput(ehConsumerGroups, function(ehConsumerGroups) {
if ((ehConsumerGroups.length === 0)) {
log.info($("No event hub consumer groups found."));
return; } ;
log.table(ehConsumerGroups, function(row, ehConsumerGroup) {
row.cell($("EH Consumer Group Name"), ehConsumerGroup); }); }); _(); }); }); }); });
iotHubehcg.command("create [resource-group] [name]").description($("Add an Event Hub consumer groups for an IoT hub")).usage("<resourceGroup> <name> [options]").option("-g --resource-group <resourceGroup>", $("The name of the resource group")).option("-n --name <name>", $("The nam