/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var __ = require("underscore");


















var util = require("util");

var profile = require("../../util/profile");
var utils = require("../../util/utils");
var validation = require("../../util/validation");
var storageUtil = require("../../util/storage.util");
var resourceLib = require("azure-arm-resource");

var $ = utils.getLocaleString;

exports.init = function(cli) {
  var log = cli.output;
  var isResourceMode = (cli.getMode() === "arm");
  var storage = cli.category("storage");

  var storageAccount = storage.category("account").description($("Commands to manage your Storage accounts"));


  var accountSas = storageAccount.category("sas").description($("Commands to manage shared access signatures of your storage account"));


  var keys = storageAccount.category("keys").description($("Commands to manage your Storage account keys"));


  var usage = { };
  if (isResourceMode) {
    usage = storageAccount.category("usage").description($("Commands to manage your Storage accounts usage")); } ;



  var connectionString = storageAccount.category("connectionstring").description($("Commands to show your Storage connection string"));


  var serviceType = { blob: 0, queue: 1, table: 2, file: 3 };

  function wrapEndpoint(uri, type) {
    if (!uri) {
      return ""; } ;


    if ((((uri.indexOf("//") != -1) && !utils.stringStartsWith(uri, "http://")) && !utils.stringStartsWith(uri, "https://"))) {
      throw new Error($((("The provided URI \"" + uri) + "\" is not supported."))); } ;


    if (!validation.isURL(uri, { require_protocol: false })) {
      throw new Error((("The provided URI \"" + uri) + "\" is invalid.")); } ;


    var tag;
    switch (type) {
    case serviceType.blob: tag = "BlobEndpoint="; break; case serviceType.queue:
      tag = "QueueEndpoint="; break; case serviceType.table:
      tag = "TableEndpoint="; break; case serviceType.file:
      tag = "FileEndpoint="; break; };

    return ((tag + uri) + ";"); };


  function showProgress(message) {
    return cli.interaction.progress(message); };


  function endProgress(progress) {

    if (progress) {
      progress.end(); } ; };



  function createStorageManagementClient(subscriptionOrName) {
    var client;
    if ((__.isString(subscriptionOrName) || !subscriptionOrName)) {
      subscriptionOrName = profile.current.getSubscription(subscriptionOrName); } ;

    if (isResourceMode) {
      client = utils.createStorageResourceProviderClient(subscriptionOrName); }
     else {
      client = utils.createStorageClient(subscriptionOrName); } ;

    return client; };


  function validateResourceGroupName(options, _) { var __frame = { name: "validateResourceGroupName", line: 102 }; return __func(_, this, arguments, validateResourceGroupName, 1, __frame, function __$validateResourceGroupName() {
      return cli.interaction.promptIfNotGiven($("Resource group name: "), options.resourceGroup, __cb(_, __frame, 1, 44, function ___(__0, __1) { options.resourceGroup = __1; _(); }, true)); }); };


  function validateAccountConfiguration(options, storageOptions, isUpdate, _) { var value, title, info, managementService, subscription, client, customDomain; var __frame = { name: "validateAccountConfiguration", line: 106 }; return __func(_, this, arguments, validateAccountConfiguration, 3, __frame, function __$validateAccountConfiguration() {
      value = (isResourceMode ? options.skuName : options.type);
      title = (isResourceMode ? $("SKU Name: ") : $("Account Type: "));
      info = (isResourceMode ? $("Getting SKU") : $("Getting type")); return (function __$validateAccountConfiguration(__then) {


        if (!isUpdate) { return (function __$validateAccountConfiguration(__then) {
            if (value) {
              validation.isValidEnumValue(value, Object.keys(storageUtil.AccountTypeForCreating)); __then(); } else {

              return cli.interaction.chooseIfNotGiven(title, info, value, function(cb) {

                cb(null, Object.keys(storageUtil.AccountTypeForCreating)); }, __cb(_, __frame, 10, 32, function ___(__0, __1) { value = __1; __then(); }, true)); } ; })(function __$validateAccountConfiguration() {


            storageOptions.accountType = storageUtil.getValidValueFromArgument(value, storageUtil.AccountTypeForCreating); __then(); }); } else {
          if (value) {
            validation.isValidEnumValue(value, Object.keys(storageUtil.AccountTypeForChanging));
            storageOptions.accountType = storageUtil.getValidValueFromArgument(value, storageUtil.AccountTypeForChanging); } ; __then(); } ; })(function __$validateAccountConfiguration() {


        if ((isResourceMode && storageOptions.accountType)) {
          storageOptions.sku = { name: storageOptions.accountType };
          delete storageOptions.accountType; } ; return (function __$validateAccountConfiguration(__then) {



          if (!isUpdate) { return (function __$validateAccountConfiguration(__then) {
              if (options.affinityGroup) {
                storageOptions.affinityGroup = options.affinityGroup; __then(); } else { return (function __$validateAccountConfiguration(__then) {

                  if (!isResourceMode) {
                    managementService = utils.createManagementClient(profile.current.getSubscription(options.subscription), log);
                    return cli.interaction.chooseIfNotGiven($("Location: "), $("Getting locations"), options.location, function(cb) {

                      managementService.locations.list(function(err, result) {
                        if (err) { return cb(err); } ;

                        cb(null, result.locations.map(function(location) { return location.name; })); }); }, __cb(_, __frame, 33, 52, function ___(__0, __2) { storageOptions.location = __2; __then(); }, true)); } else {



                    subscription = profile.current.getSubscription(options.subscription);
                    client = new resourceLib.SubscriptionClient(subscription._createCredentials(), subscription.resourceManagerEndpointUrl);

                    return cli.interaction.chooseIfNotGiven($("Location: "), $("Getting locations"), options.location, function(cb) {

                      client.subscriptions.listLocations(subscription.id, function(err, result) {
                        if (err) { return cb(err); } ;

                        cb(null, result.map(function(location) { return location.displayName; })); }); }, __cb(_, __frame, 45, 52, function ___(__0, __3) { storageOptions.location = __3; __then(); }, true)); } ; })(__then); } ; })(__then); } else { __then(); } ; })(function __$validateAccountConfiguration() {






          if (!isResourceMode) {

            if (__.isString(options.description)) {
              storageOptions.description = options.description; } ;



            if (options.label) {
              storageOptions.label = options.label; } ; return _(null); } ;






          if (options.tags) {
            storageOptions.tags = storageUtil.parseKvParameterInvariant(options.tags); } ; return (function __$validateAccountConfiguration(__then) {



            if (!isUpdate) { return (function __$validateAccountConfiguration(__then) {
                if (options.kind) {
                  validation.isValidEnumValue(options.kind, Object.keys(storageUtil.AccountKind)); __then(); } else {

                  return cli.interaction.chooseIfNotGiven($("Kind: "), $("Getting kind"), options.kind, function(cb) {

                    cb(null, Object.keys(storageUtil.AccountKind)); }, __cb(_, __frame, 81, 39, function ___(__0, __4) { options.kind = __4; __then(); }, true)); } ; })(function __$validateAccountConfiguration() {


                storageOptions.kind = storageUtil.getValidValueFromArgument(options.kind, storageUtil.AccountKind); __then(); }); } else { __then(); } ; })(function __$validateAccountConfiguration() { return (function __$validateAccountConfiguration(__then) {





              if ((((isUpdate && options.accessTier)) || ((options.kind && (options.kind.toLowerCase() === storageUtil.AccountKind.BlobStorage.toLowerCase()))))) { return (function __$validateAccountConfiguration(__then) {

                  if (options.accessTier) {
                    validation.isValidEnumValue(options.accessTier, Object.keys(storageUtil.AccessTier)); __then(); } else {

                    return cli.interaction.chooseIfNotGiven($("Access Tier: "), $("Getting access tier"), options.accessTier, function(cb) {

                      cb(null, Object.keys(storageUtil.AccessTier)); }, __cb(_, __frame, 97, 45, function ___(__0, __5) { options.accessTier = __5; __then(); }, true)); } ; })(function __$validateAccountConfiguration() {


                  storageOptions.accessTier = storageUtil.getValidValueFromArgument(options.accessTier, storageUtil.AccessTier); __then(); }); } else {
                if ((!isUpdate && options.accessTier)) {

                  return _(new Error($("The storage account property '--access-tier' cannot be set at this time."))); } ; __then(); } ; })(function __$validateAccountConfiguration() {



              if (options.enableEncryptionService) {
                validation.isValidEnumValue(options.enableEncryptionService, Object.keys(storageUtil.EncryptionService));

                if ((options.disableEncryptionService && (options.disableEncryptionService.toLowerCase() === options.enableEncryptionService.toLowerCase()))) {
                  return _(new Error($("Only one of --enable-encryption-service and --disable-encryption-service can be set for a service"))); } ;

                storageOptions.encryption = { services: { }, keySource: storageUtil.EncryptionKeySource.Storage };
                storageOptions.encryption.services[options.enableEncryptionService.toLowerCase()] = { enabled: true }; } ;


              if (options.disableEncryptionService) {
                validation.isValidEnumValue(options.disableEncryptionService, Object.keys(storageUtil.EncryptionService));
                storageOptions.encryption = { services: { }, keySource: storageUtil.EncryptionKeySource.Storage };
                storageOptions.encryption.services[options.disableEncryptionService.toLowerCase()] = { enabled: false }; } ;



              if (options.customDomain) {
                customDomain = { };
                if ((options.customDomain === storageUtil.SPACE_PARAMETER)) {
                  customDomain.name = ""; }
                 else {
                  customDomain.name = options.customDomain;
                  if ((options.subdomain === true)) {
                    customDomain.useSubDomain = true; } ; } ;


                storageOptions.customDomain = customDomain; } ; _(); }); }); }); }); }); };







  function listAccounts(serviceClient, options, _) { var progress, storageAccounts; var __frame = { name: "listAccounts", line: 250 }; return __func(_, this, arguments, listAccounts, 2, __frame, function __$listAccounts() {
      progress = showProgress($("Getting storage accounts")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$listAccounts() { return (function __$listAccounts(__then) {


              if (isResourceMode) { return (function __$listAccounts(__then) {
                  if (options.resourceGroup) {
                    return serviceClient.storageAccounts.listByResourceGroup(options.resourceGroup, __cb(_, __frame, 6, 71, function ___(__0, __1) { storageAccounts = __.toArray(__1); __then(); }, true)); } else {


                    return serviceClient.storageAccounts.list(__cb(_, __frame, 9, 71, function ___(__0, __2) { storageAccounts = __.toArray(__2); __then(); }, true)); } ; })(__then); } else {


                return serviceClient.storageAccounts.list(__cb(_, __frame, 12, 56, function ___(__0, __3) { storageAccounts = __3.storageAccounts; __then(); }, true)); } ; })(function __$listAccounts() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$listAccounts() {


              endProgress(progress); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$listAccounts() {


          return _(null, storageAccounts); }); }); }); };


  function showAccount(serviceClient, accountName, options, _) { var progress, message, storageAccount; var __frame = { name: "showAccount", line: 271 }; return __func(_, this, arguments, showAccount, 3, __frame, function __$showAccount() {

      message = $("Getting storage account"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$showAccount() { return (function __$showAccount(__then) {


              if (isResourceMode) {
                return validateResourceGroupName(options, __cb(_, __frame, 6, 8, function __$showAccount() {
                  progress = showProgress(message);
                  return serviceClient.storageAccounts.getProperties(options.resourceGroup, accountName, __cb(_, __frame, 8, 55, function ___(__0, __1) { storageAccount = __1; __then(); }, true)); }, true)); } else {

                progress = showProgress(message);
                return serviceClient.storageAccounts.get(accountName, __cb(_, __frame, 11, 55, function ___(__0, __2) { storageAccount = __2.storageAccount; __then(); }, true)); } ; })(function __$showAccount() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$showAccount() {


              endProgress(progress); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$showAccount() {


          return _(null, storageAccount); }); }); }); };


  function createAccount(serviceClient, parameters, options, _) { var progress, message, storageAccount; var __frame = { name: "createAccount", line: 291 }; return __func(_, this, arguments, createAccount, 3, __frame, function __$createAccount() {

      message = $("Creating storage account"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$createAccount() { return (function __$createAccount(__then) {



              if (isResourceMode) {
                return validateResourceGroupName(options, __cb(_, __frame, 7, 8, function __$createAccount() {
                  progress = showProgress(message);
                  return serviceClient.storageAccounts.create(options.resourceGroup, parameters.name, parameters, __cb(_, __frame, 9, 55, function ___(__0, __1) { storageAccount = __1; __then(); }, true)); }, true)); } else {

                progress = showProgress(message);
                return serviceClient.storageAccounts.create(parameters, __cb(_, __frame, 12, 55, function ___(__0, __2) { storageAccount = __2; __then(); }, true)); } ; })(function __$createAccount() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$createAccount() {


              endProgress(progress); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$createAccount() {


          return _(null, storageAccount); }); }); }); };


  function updateAccount(serviceClient, parameters, options, _) { var progress, message, storageAccount; var __frame = { name: "updateAccount", line: 312 }; return __func(_, this, arguments, updateAccount, 3, __frame, function __$updateAccount() {

      message = $("Updating storage account"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$updateAccount() { return (function __$updateAccount(__then) {



              if (isResourceMode) {
                return validateResourceGroupName(options, __cb(_, __frame, 7, 8, function __$updateAccount() {
                  progress = showProgress(message);
                  return serviceClient.storageAccounts.update(options.resourceGroup, parameters.name, parameters, __cb(_, __frame, 9, 45, _, true)); }, true)); } else {

                progress = showProgress(message);
                return serviceClient.storageAccounts.update(parameters.name, parameters, __cb(_, __frame, 12, 45, _, true)); } ; })(function __$updateAccount() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$updateAccount() {


              endProgress(progress); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$updateAccount() {


          return _(null, storageAccount); }); }); }); };


  function deleteAccount(serviceClient, accountName, options, _) { var progress, message, storageAccount; var __frame = { name: "deleteAccount", line: 333 }; return __func(_, this, arguments, deleteAccount, 3, __frame, function __$deleteAccount() {

      message = $("Deleting storage account"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteAccount() { return (function __$deleteAccount(__then) {



              if (isResourceMode) {
                return validateResourceGroupName(options, __cb(_, __frame, 7, 8, function __$deleteAccount() {
                  progress = showProgress(message);
                  return serviceClient.storageAccounts.deleteMethod(options.resourceGroup, accountName, __cb(_, __frame, 9, 55, function ___(__0, __1) { storageAccount = __1; __then(); }, true)); }, true)); } else {

                progress = showProgress(message);
                return serviceClient.storageAccounts.deleteMethod(accountName, __cb(_, __frame, 12, 55, function ___(__0, __2) { storageAccount = __2; __then(); }, true)); } ; })(function __$deleteAccount() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deleteAccount() {


              endProgress(progress); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$deleteAccount() {


          return _(null, storageAccount); }); }); }); };


  function checkNameAvailability(serviceClient, accountName, _) { var progress, message, availability; var __frame = { name: "checkNameAvailability", line: 354 }; return __func(_, this, arguments, checkNameAvailability, 2, __frame, function __$checkNameAvailability() {

      message = $("Checking availability of the storage account name");
      availability = { }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$checkNameAvailability() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$checkNameAvailability() {


                  progress = showProgress(message);
                  return serviceClient.storageAccounts.checkNameAvailability(accountName, __cb(_, __frame, 7, 51, function ___(__0, __1) { availability = __1; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$checkNameAvailability() { if (e) {

                    if (!isResourceMode) {
                      availability.isAvailable = false;
                      availability.reason = e.message;
                      availability.statusCode = e.statusCode;
                      availability.requestId = e.requestId; }
                     else {
                      return _(e); } ; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$checkNameAvailability() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$checkNameAvailability() {


              endProgress(progress); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$checkNameAvailability() {


          if (!isResourceMode) {
            availability.nameAvailable = availability.isAvailable;
            delete availability.isAvailable; } ;


          return _(null, availability); }); }); }); };


  function showSubscriptionUsage(serviceClient, subscriptionId, _) { var progress, message, usage, usageList, i; var __frame = { name: "showSubscriptionUsage", line: 383 }; return __func(_, this, arguments, showSubscriptionUsage, 2, __frame, function __$showSubscriptionUsage() {

      message = $("Showing the subscription usage");
      usage = { subscription: subscriptionId };

      if (!subscriptionId) {
        usage.subscriptionId = profile.current.getSubscription().id; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$showSubscriptionUsage() {



            progress = showProgress(message);
            return serviceClient.usageOperations.list(__cb(_, __frame, 11, 52, function ___(__0, __1) { usageList = __1;
              for (i = 0; (i < usageList.value.length); i++) {
                if ((usageList.value[i].name.value === "StorageAccounts")) {
                  usage.used = usageList.value[i].currentValue;
                  usage.limit = usageList.value[i].limit;
                  break; } ; }; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$showSubscriptionUsage() {



              endProgress(progress); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$showSubscriptionUsage() {

          return _(null, usage); }); }); }); };


  function getAccountKeys(serviceClient, accountName, options, _) { var progress, message, keys; var __frame = { name: "getAccountKeys", line: 408 }; return __func(_, this, arguments, getAccountKeys, 3, __frame, function __$getAccountKeys() {

      message = $("Getting storage account keys"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getAccountKeys() { return (function __$getAccountKeys(__then) {



              if (isResourceMode) {
                return validateResourceGroupName(options, __cb(_, __frame, 7, 8, function __$getAccountKeys() {
                  progress = showProgress(message);
                  return serviceClient.storageAccounts.listKeys(options.resourceGroup, accountName, __cb(_, __frame, 9, 45, function ___(__0, __1) { keys = __1; __then(); }, true)); }, true)); } else {

                progress = showProgress(message);
                return serviceClient.storageAccounts.getKeys(accountName, __cb(_, __frame, 12, 45, function ___(__0, __2) { keys = __2; __then(); }, true)); } ; })(function __$getAccountKeys() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$getAccountKeys() {


              endProgress(progress); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$getAccountKeys() {


          return _(null, keys); }); }); }); };


  function regenerateAccountKeys(serviceClient, accountName, options, _) { var progress, message, keys, keyType, parameters; var __frame = { name: "regenerateAccountKeys", line: 429 }; return __func(_, this, arguments, regenerateAccountKeys, 3, __frame, function __$regenerateAccountKeys() {

      message = $("Renewing storage account key"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$regenerateAccountKeys() { return (function __$regenerateAccountKeys(__then) {




              if (isResourceMode) {
                return validateResourceGroupName(options, __cb(_, __frame, 8, 8, function __$regenerateAccountKeys() {
                  progress = showProgress(message);
                  keyType = (options.primary ? "key1" : "key2");
                  return serviceClient.storageAccounts.regenerateKey(options.resourceGroup, accountName, keyType, __cb(_, __frame, 11, 45, function ___(__0, __1) { keys = __1; __then(); }, true)); }, true)); } else {

                keyType = (options.primary ? "primary" : "secondary");
                parameters = { name: accountName, keyType: keyType };
                progress = showProgress(message);
                return serviceClient.storageAccounts.regenerateKeys(parameters, __cb(_, __frame, 16, 45, function ___(__0, __2) { keys = __2; __then(); }, true)); } ; })(function __$regenerateAccountKeys() { _(null, null, true); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$regenerateAccountKeys() {


              endProgress(progress); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$regenerateAccountKeys() {


          return _(null, keys); }); }); }); };


  function parseResourceGroupNameFromId(id) {
    if (!id) { return ""; } ;
    var keyword = "/resourceGroups/";
    var startIndex = (id.indexOf(keyword) + keyword.length);
    var endIndex = id.indexOf("/", startIndex);
    return id.substring(startIndex, endIndex); };


  storageAccount.listCommand = function storageAccount_listCommand__1(options, _) { var service, storageAccounts; var __frame = { name: "storageAccount_listCommand__1", line: 462 }; return __func(_, this, arguments, storageAccount_listCommand__1, 1, __frame, function __$storageAccount_listCommand__1() {
      service = createStorageManagementClient(options.subscription);

      return listAccounts(service, options, __cb(_, __frame, 3, 26, function ___(__0, __1) { storageAccounts = __1;

        storageAccounts.forEach(function(storageAccount) {
          storageAccount.resourceGroup = parseResourceGroupNameFromId(storageAccount.id); });


        cli.interaction.formatOutput(storageAccounts, function(outputData) {
          if ((outputData.length === 0)) {
            log.info($("No storage accounts defined")); }
           else {
            log.table(outputData, function(row, item) {
              row.cell($("Name"), item.name);
              if (isResourceMode) {
                row.cell($("SKU Name"), item.sku.name);
                row.cell($("SKU Tier"), item.sku.tier);
                row.cell($("Access Tier"), (item.accessTier ? item.accessTier : ""));
                row.cell($("Kind"), item.kind);
                if (item.encryption) {
                  var encryptionServices = "";
                  Object.keys(item.encryption.services).forEach(function(service) {
                    encryptionServices += (service + " "); });

                  row.cell($("Encrypted Service"), encryptionServices); }
                 else {
                  row.cell($("Encrypted Service"), ""); } ;

                row.cell($("Location"), item.location);
                row.cell($("Resource Group"), item.resourceGroup); }
               else {
                row.cell($("Type"), item.properties.accountType);
                row.cell($("Label"), (item.properties.label ? item.properties.label : ""));
                row.cell($("Location"), (item.properties.location || (((item.properties.affinityGroup || "")) + ((item.properties.geoPrimaryRegion ? ((" (" + item.properties.geoPrimaryRegion) + ")") : "")))));


                row.cell($("Resource Group"), item.extendedProperties.ResourceGroup); } ; }); } ; }); _(); }, true)); }); };






  storageAccount.showCommand = function storageAccount_showCommand__2(name, options, _) { var service, storageAccount; var __frame = { name: "storageAccount_showCommand__2", line: 506 }; return __func(_, this, arguments, storageAccount_showCommand__2, 2, __frame, function __$storageAccount_showCommand__2() {
      service = createStorageManagementClient(options.subscription);

      return showAccount(service, name, options, __cb(_, __frame, 3, 25, function ___(__0, __1) { storageAccount = __1;

        if (storageAccount) {
          storageAccount.resourceGroup = parseResourceGroupNameFromId(storageAccount.id);
          cli.interaction.formatOutput(storageAccount, function(outputData) {
            log.data($("Name:"), outputData.name);
            if (isResourceMode) {
              log.data($("Url:"), outputData.id);
              log.data($("Type:"), outputData.type);
              log.data($("SKU Name:"), outputData.sku.name);
              log.data($("SKU Tier:"), outputData.sku.tier);
              log.data($("Kind:"), outputData.kind);
              if ((outputData.kind.toLowerCase() == storageUtil.AccountKind.BlobStorage.toLowerCase())) {
                log.data($("Access Tier:"), outputData.accessTier); } ;

              log.data($("Resource Group:"), outputData.resourceGroup);
              log.data($("Location:"), outputData.location);
              log.data($("Provisioning State:"), outputData.provisioningState);
              log.data($("Primary Location:"), outputData.primaryLocation);
              log.data($("Primary Status:"), outputData.statusOfPrimary);
              if (outputData.encryption) {
                cli.interaction.logEachData($("Encryption:"), outputData.encryption.services); } ;

              if (outputData.customDomain) {
                log.data($("Custom Domain:"), outputData.customDomain.name); } ;

              log.data($("Secondary Location:"), outputData.secondaryLocation);
              log.data($("Creation Time:"), (outputData.creationTime ? outputData.creationTime.toUTCString() : ""));
              cli.interaction.logEachData($("Primary Endpoints:"), outputData.primaryEndpoints);
              if (outputData.tags) {
                cli.interaction.logEachData($("Tags:"), outputData.tags); } ; }

             else {
              log.data($("Url:"), outputData.uri);

              cli.interaction.logEachData($("Account Properties:"), outputData.properties);
              cli.interaction.logEachData($("Extended Properties:"), outputData.extendedProperties);
              cli.interaction.logEachData($("Capabilities:"), outputData.capabilities); } ; }); }


         else {
          log.info($("No storage account found")); } ; _(); }, true)); }); };



  storageAccount.createCommand = function storageAccount_createCommand__3(name, options, _) { var service, storageOptions, availability; var __frame = { name: "storageAccount_createCommand__3", line: 554 }; return __func(_, this, arguments, storageAccount_createCommand__3, 2, __frame, function __$storageAccount_createCommand__3() {
      service = createStorageManagementClient(options.subscription);
      storageOptions = {
        name: name,
        label: (options.label ? options.label : name) };


      return checkNameAvailability(service, name, __cb(_, __frame, 7, 23, function ___(__0, __1) { availability = __1;
        if (!availability.nameAvailable) {

          if ((availability.reason === "AlreadyExists")) {
            return _(new Error(util.format($("The storage account named \"%s\" is already taken"), name))); } else {
            if ((availability.reason === "AccountNameInvalid")) {
              return _(new Error((availability.message || util.format($("The storage account name \"%s\" is not in valid format"), name)))); }
             else {

              return _(new Error(((availability.message || availability.reason) || util.format($("The storage account named \"%s\" is already taken or not valid"), name)))); } ; } ; } ;



        return validateAccountConfiguration(options, storageOptions, false, __cb(_, __frame, 20, 4, function __$storageAccount_createCommand__3() {

          return createAccount(service, storageOptions, options, __cb(_, __frame, 22, 4, function __$storageAccount_createCommand__3() { _(); }, true)); }, true)); }, true)); }); };


  storageAccount.updateCommand = function storageAccount_updateCommand__4(name, options, _) { var service, storageOptions; var __frame = { name: "storageAccount_updateCommand__4", line: 579 }; return __func(_, this, arguments, storageAccount_updateCommand__4, 2, __frame, function __$storageAccount_updateCommand__4() {
      service = createStorageManagementClient(options.subscription);
      storageOptions = { name: name };

      return validateAccountConfiguration(options, storageOptions, true, __cb(_, __frame, 4, 4, function __$storageAccount_updateCommand__4() {

        return updateAccount(service, storageOptions, options, __cb(_, __frame, 6, 4, function __$storageAccount_updateCommand__4() { _(); }, true)); }, true)); }); };


  storageAccount.deleteCommand = function storageAccount_deleteCommand__5(name, options, _) { var service; var __frame = { name: "storageAccount_deleteCommand__5", line: 588 }; return __func(_, this, arguments, storageAccount_deleteCommand__5, 2, __frame, function __$storageAccount_deleteCommand__5() {
      service = createStorageManagementClient(options.subscription); return (function __$storageAccount_deleteCommand__5(_) {

        var __1 = !options.quiet; if (!__1) { return _(null, __1); } ; return cli.interaction.confirm(util.format($("Delete storage account %s? [y/n] "), name), __cb(_, __frame, 3, 43, function ___(__0, __3) { var __2 = !__3; return _(null, __2); }, true)); })(__cb(_, __frame, -587, 21, function ___(__0, __2) { return (function __$storageAccount_deleteCommand__5(__then) { if (__2) { return _(null); } else { __then(); } ; })(function __$storageAccount_deleteCommand__5() {



          return deleteAccount(service, name, options, __cb(_, __frame, 7, 4, function __$storageAccount_deleteCommand__5() { _(); }, true)); }); }, true)); }); };


  storageAccount.checkCommand = function storageAccount_checkCommand__6(name, options, _) { var service, availability; var __frame = { name: "storageAccount_checkCommand__6", line: 598 }; return __func(_, this, arguments, storageAccount_checkCommand__6, 2, __frame, function __$storageAccount_checkCommand__6() {
      service = createStorageManagementClient();
      return checkNameAvailability(service, name, __cb(_, __frame, 2, 23, function ___(__0, __1) { availability = __1;

        cli.interaction.formatOutput(availability, function(outputData) {
          log.data($("Availability:"), outputData.nameAvailable.toString());
          if (!outputData.nameAvailable) {
            log.data($("Reason:"), outputData.reason);
            if (outputData.message) {
              log.data($("Message:"), outputData.message); } ; } ; }); _(); }, true)); }); };





  usage.usageCommand = function usage_usageCommand__7(subscription, options, _) { var service, usage; var __frame = { name: "usage_usageCommand__7", line: 613 }; return __func(_, this, arguments, usage_usageCommand__7, 2, __frame, function __$usage_usageCommand__7() {
      service = createStorageManagementClient(subscription);
      return showSubscriptionUsage(service, subscription, __cb(_, __frame, 2, 16, function ___(__0, __1) { usage = __1;

        cli.interaction.formatOutput(usage, function(outputData) {
          log.data($("Subscription:"), outputData.subscriptionId);
          log.data($("Used:"), outputData.used);
          log.data($("Limit:"), outputData.limit); }); _(); }, true)); }); };



  accountSas.createCommand = function accountSas_createCommand__8(services, resourceTypes, permissions, expiry, options, _) { var start, output, progress, sharedAccessPolicy; var __frame = { name: "accountSas_createCommand__8", line: 624 }; return __func(_, this, arguments, accountSas_createCommand__8, 5, __frame, function __$accountSas_createCommand__8() {
      return cli.interaction.promptIfNotGiven($("Services: "), services, __cb(_, __frame, 1, 31, function ___(__0, __1) { services = __1;
        storageUtil.validateAccountSasServices(services);

        return cli.interaction.promptIfNotGiven($("Resource Types: "), resourceTypes, __cb(_, __frame, 4, 36, function ___(__0, __2) { resourceTypes = __2;
          storageUtil.validateAccountSasResourceTypes(resourceTypes);

          return cli.interaction.promptIfNotGiven($("Permissions: "), permissions, __cb(_, __frame, 7, 34, function ___(__0, __3) { permissions = __3;
            storageUtil.validateAccountSasPermissions(permissions);

            return cli.interaction.promptIfNotGiven($("Expiry: "), expiry, __cb(_, __frame, 10, 29, function ___(__0, __4) { expiry = __4;
              expiry = utils.parseDateTime(expiry);


              if (options.start) {
                start = utils.parseDateTime(options.start); } ;


              output = { sas: "" };
              progress = showProgress("Creating shared access signature"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$accountSas_createCommand__8() {

                    sharedAccessPolicy = storageUtil.getAccountSharedAccessPolicy(services, resourceTypes, permissions, options.protocol, options.ipRange, start, expiry, options.policy);
                    output.sas = storageUtil.generateAccountSharedAccessSignature(options, sharedAccessPolicy); _(null, null, true); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$accountSas_createCommand__8() {

                      endProgress(progress); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$accountSas_createCommand__8() {


                  cli.interaction.formatOutput(output, function(outputData) {
                    log.data($("Shared Access Signature"), outputData.sas); }); _(); }); }); }, true)); }, true)); }, true)); }, true)); }); };



  keys.listCommand = function keys_listCommand__9(name, options, _) { var service, keys; var __frame = { name: "keys_listCommand__9", line: 656 }; return __func(_, this, arguments, keys_listCommand__9, 2, __frame, function __$keys_listCommand__9() {
      service = createStorageManagementClient(options.subscription);

      return getAccountKeys(service, name, options, __cb(_, __frame, 3, 15, function ___(__0, __1) { keys = __1;

        if (keys) {
          if (isResourceMode) {
            log.table(keys.keys, function(row, item) {
              row.cell($("Name"), item.keyName);
              row.cell($("Key"), item.value);
              row.cell($("Permissions"), item.permissions); }); }

           else {
            cli.interaction.formatOutput(keys, function(outputData) {
              log.data($("Primary:"), outputData.primaryKey);
              log.data($("Secondary:"), outputData.secondaryKey); }); } ; }


         else {
          log.info($("No storage account keys found")); } ; _(); }, true)); }); };



  keys.renewCommand = function keys_renewCommand__10(name, options, _) { var service, keys; var __frame = { name: "keys_renewCommand__10", line: 679 }; return __func(_, this, arguments, keys_renewCommand__10, 2, __frame, function __$keys_renewCommand__10() {
      service = createStorageManagementClient(options.subscription);

      if ((!options.primary && !options.secondary)) {
        return _(new Error($("Need to specify either --primary or --secondary"))); } else {
        if ((options.primary && options.secondary)) {
          return _(new Error($("Only one of primary or secondary keys can be renewed at a time"))); } ; } ;


      return regenerateAccountKeys(service, name, options, __cb(_, __frame, 9, 15, function ___(__0, __1) { keys = __1;

        if (keys) {
          if (isResourceMode) {
            log.table(keys.keys, function(row, item) {
              row.cell($("Name"), item.keyName);
              row.cell($("Key"), item.value);
              row.cell($("Permissions"), item.permissions); }); }

           else {
            cli.interaction.formatOutput(keys, function(outputData) {
              log.data($("Primary:"), outputData.primaryKey);
              log.data($("Secondary:"), outputData.secondaryKey); }); } ; }


         else {
          log.info($("No storage account keys found")); } ; _(); }, true)); }); };



  connectionString.showCommand = function connectionString_showCommand__11(name, options, _) { var service, keys, connection; var __frame = { name: "connectionString_showCommand__11", line: 708 }; return __func(_, this, arguments, connectionString_showCommand__11, 2, __frame, function __$connectionString_showCommand__11() {
      service = createStorageManagementClient(options.subscription);
      return getAccountKeys(service, name, options, __cb(_, __frame, 2, 15, function ___(__0, __1) { keys = __1;
        connection = { string: "" };
        connection.string = ("DefaultEndpointsProtocol=" + ((options.useHttp ? "http;" : "https;")));
        connection.string += wrapEndpoint(options.blobEndpoint, serviceType.blob);
        connection.string += wrapEndpoint(options.queueEndpoint, serviceType.queue);
        connection.string += wrapEndpoint(options.tableEndpoint, serviceType.table);
        connection.string += wrapEndpoint(options.fileEndpoint, serviceType.file);
        connection.string += (("AccountName=" + name) + ";");
        connection.string += ("AccountKey=" + ((keys.primaryKey || keys.keys[0].value)));
        cli.interaction.formatOutput(connection, function(outputData) {
          log.data($("connectionstring:"), outputData.string); }); _(); }, true)); }); };



  Object.getPrototypeOf(storage).appendSubscriptionAndResourceGroupOption = function() {
    if (isResourceMode) {
      this.option("-g, --resource-group <resourceGroup>", $("the resource group name")); } ;

    this.option("-s, --subscription <id>", $("the subscription id"));
    return this; };



  storageAccount.command("list").description($("List storage accounts")).appendSubscriptionAndResourceGroupOption().execute(storageAccount.listCommand);





  storageAccount.command("show <name>").description($("Show a storage account")).appendSubscriptionAndResourceGroupOption().execute(storageAccount.showCommand);





  var accountCreateCommand = storageAccount.command("create <name>").description($("Create a storage account"));
  if (isResourceMode) {
    accountCreateCommand.option("--sku-name <skuName>", $("the SKU name (LRS/ZRS/GRS/RAGRS/PLRS)")).option("--kind <kind>", $("the account kind (Storage/BlobStorage)")).option("--access-tier <accessTier>", $("the access tier for Blob storage accounts (Hot/Cool)")).option("--enable-encryption-service <enableEncryptionService>", $("specifies the service which needs to enable encryption settings")).option("--custom-domain <customDomain>", $("the custom domain")).option("--subdomain", $("whether uses the 'asverify' subdomain to preregister the custom domain")).option("--tags <tags>", $("the account tags. Tags are key=value pairs and separated with semicolon(;)")); }






   else {
    accountCreateCommand.option("--type <type>", $("the account type(LRS/ZRS/GRS/RAGRS/PLRS)")).option("-e, --label <label>", $("the storage account label")).option("-d, --description <description>", $("the storage account description")).option("-a, --affinity-group <affinityGroup>", $("the affinity group")); } ;




  accountCreateCommand.option("-l, --location <location>", $("the location")).appendSubscriptionAndResourceGroupOption().execute(storageAccount.createCommand);




  var accountSetCommand;
  if (isResourceMode) {
    accountSetCommand = storageAccount.command("set <name>").description($("Update a storage account")).option("--sku-name <skuName>", $("the SKU name (LRS/GRS/RAGRS)")).option("--access-tier <accessTier>", $("the access tier for Blob storage accounts (Hot/Cool)")).option("--enable-encryption-service <enableEncryptionService>", $("specifies the service which needs to enable encryption settings")).option("--disable-encryption-service <disableEncryptionService>", $("specifies the service which needs to disable encryption settings")).option("--custom-domain <customDomain>", $("the custom domain")).option("--subdomain", $("whether uses the 'asverify' subdomain to preregister the custom domain")).option("--tags <tags>", $("the account tags. Tags are key=value pairs and separated with semicolon(;)")); }







   else {
    accountSetCommand = storageAccount.command("set <name>").description($("Update a storage account")).option("--type <type>", $("the account type(LRS/GRS/RAGRS)")).option("-e, --label <label>", $("the storage account label")).option("-d, --description <description>", $("the storage account description")); } ;




  accountSetCommand.appendSubscriptionAndResourceGroupOption().execute(storageAccount.updateCommand);



  storageAccount.command("delete <name>").description($("Delete a storage account")).appendSubscriptionAndResourceGroupOption().option("-q, --quiet", $("quiet mode, do not ask for delete confirmation")).execute(storageAccount.deleteCommand);





  storageAccount.command("check <name>").description($("Check whether the account name is valid and is not in use.")).execute(storageAccount.checkCommand);



  if (isResourceMode) {
    usage.command("show [subscription]").description($("Show the current count and the limit of the storage accounts under the subscription.")).option("-s, --subscription <id>", $("the subscription id")).execute(usage.usageCommand); } ;





  accountSas.command("create [services] [resourceTypes] [permissions] [expiry]").description($("Generate shared access signature of storage account")).option("--services <services>", $("the storage services accessible with the account SAS combining symbols of b(Blob)/f(File)/q(Queue)/t(Table)")).option("--resource-types <resourceTypes>", $("the storage resource types accessible with the account SAS combining symbols of s(Service)/c(Container/o(Object)")).option("--permissions <permissions>", $("the operation permissions combining symbols of r(Read)/w(Write)/d(Delete)/l(List)/a(Add)/c(Create)/u(Update)/p(Process)")).option("--protocol <protocol>", $("the protocol permitted for a request made with the SAS. Possible values are HttpsOnly and HttpsOrHttp")).option("--ip-range <ipRange>", $("an IP address or a range of IP addresses from which to accept requests. When specifying a range of IP addresses, note that the range is inclusive. For example, specifying 168.1.5.65 or 168.1.5.60-168.1.5.70 on the SAS restricts the request to those IP addresses.")).option("--start <start>", $("the UTC time at which the SAS becomes valid")).option("--expiry <expiry>", $("the UTC time at which the SAS expires")).option("-a, --account-name <accountName>", $("the storage account name")).option("-k, --account-key <accountKey>", $("the storage account key")).option("-c, --connection-string <connectionString>", $("the storage connection string")).execute(accountSas.createCommand);














  keys.command("list <name>").description($("List the keys for a storage account")).appendSubscriptionAndResourceGroupOption().execute(keys.listCommand);





  keys.command("renew <name>").description($("Renew a key for a storage account from your account")).option("--primary", $("Update the primary key")).option("--secondary", $("Update the secondary key")).appendSubscriptionAndResourceGroupOption().execute(keys.renewCommand);







  connectionString.command("show <name>").description($("Show the connection string for your account")).appendSubscriptionAndResourceGroupOption().option("--use-http", $("Use http as default endpoints protocol")).option("--blob-endpoint <blobEndpoint>", $("the blob endpoint")).option("--queue-endpoint <queueEndpoint>", $("the queue endpoint")).option("--table-endpoint <tableEndpoint>", $("the table endpoint")).option("--file-endpoint <fileEndpoint>", $("the file endpoint")).execute(connectionString.showCommand);};
