/*** 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 fs = require("fs");
var util = require("util");
var path = require("path");
var exec = require("child_process").exec;
var openssl = require("openssl-wrapper");
var js2xmlparser = require("js2xmlparser");
var utils = require("../../../util/utils");
var tagUtils = require("../tag/tagUtils");
var EndPointUtil = require("../../../util/endpointUtil");
var blobUtil = require("../../../util/blobUtils");
var vmConstants = require("../../../util/vmConstants");

var $ = utils.getLocaleString;

function VMExtensionProfile(cli, params, serviceClients) {
  this.cli = cli;
  this.output = cli.output;
  this.params = params;
  this.serviceClients = serviceClients;};


__.extend(VMExtensionProfile.prototype, {
  generateExtensionProfile: function() {
    var extensionProfile = this._parseExtensionProfileParams(this.params);
    return {
      profile: extensionProfile }; },



  generateDockerExtensionProfile: function generateDockerExtensionProfile__1(_) { var endPointUtil, dockerPortValidation, homePath, dockerCertPaths, __this = this; var __frame = { name: "generateDockerExtensionProfile__1", line: 46 }; return __func(_, this, arguments, generateDockerExtensionProfile__1, 0, __frame, function __$generateDockerExtensionProfile__1() {
      if ((((__this.params.dockerPort && (typeof __this.params.dockerPort === "boolean"))) || !__this.params.dockerPort)) {
        __this.params.dockerPort = vmConstants.EXTENSIONS.DOCKER_PORT; }
       else {
        endPointUtil = new EndPointUtil();
        dockerPortValidation = endPointUtil.validatePort(__this.params.dockerPort, "docker port");
        if (dockerPortValidation.error) {
          return _(new Error(dockerPortValidation.error)); } ; } ;



      if ((((__this.params.dockerCertDir && (typeof __this.params.dockerCertDir === "boolean"))) || !__this.params.dockerCertDir)) {
        homePath = process.env[(((process.platform === "win32")) ? "USERPROFILE" : "HOME")];
        __this.params.dockerCertDir = path.join(homePath, ".docker"); } ;


      if (utils.stringIsNullOrEmpty(__this.params.version)) {
        __this.params.version = vmConstants.EXTENSIONS.DOCKER_VERSION_ARM; } ;


      dockerCertPaths = {
        caKey: path.join(__this.params.dockerCertDir, "ca-key.pem"),
        ca: path.join(__this.params.dockerCertDir, "ca.pem"),
        serverKey: path.join(__this.params.dockerCertDir, (__this.params.vmName + "-server-key.pem")),
        server: path.join(__this.params.dockerCertDir, (__this.params.vmName + "-server.csr")),
        serverCert: path.join(__this.params.dockerCertDir, (__this.params.vmName + "-server-cert.pem")),
        clientKey: path.join(__this.params.dockerCertDir, "key.pem"),
        client: path.join(__this.params.dockerCertDir, "client.csr"),
        clientCert: path.join(__this.params.dockerCertDir, "cert.pem") };


      return __this._checkAndGenerateDockerCertificatesIfNeeded(dockerCertPaths, __this.params.dockerCertCn, __cb(_, __frame, 31, 9, function __$generateDockerExtensionProfile__1() {

        __this.params.extensionName = vmConstants.EXTENSIONS.DOCKER_NAME;
        __this.params.publisherName = vmConstants.EXTENSIONS.DOCKER_PUBLISHER;
        __this.params.publicConfig = __this._createDockerPublicConfiguration();
        __this.params.privateConfig = __this._createDockerPrivateConfiguration(dockerCertPaths);
        __this.params.autoUpgradeMinorVersion = true;

        return _(null, __this.generateExtensionProfile()); }, true)); }); },


  generateVMAccessExtensionProfile: function() {
    if ((this.params.osType === "Linux")) {
      return this._generateVMAccessLinuxProfile(); }
     else if ((this.params.osType === "Windows")) {
      return this._generateVMAccessWindowsProfile(); }  ;


    return null; },


  generateVMDiagExtensionProfile: function generateVMDiagExtensionProfile__2(_) { var __this = this; var __frame = { name: "generateVMDiagExtensionProfile__2", line: 98 }; return __func(_, this, arguments, generateVMDiagExtensionProfile__2, 0, __frame, function __$generateVMDiagExtensionProfile__2() { return (function __$generateVMDiagExtensionProfile__2(__then) {
        if ((__this.params.osType === "Linux")) {
          return __this._generateVMDiagLinuxProfile(__cb(_, __frame, 2, 18, _, true)); } else { return (function __$generateVMDiagExtensionProfile__2(__then) {
            if ((__this.params.osType === "Windows")) {
              return __this._generateVMDiagWindowsProfile(__cb(_, __frame, 4, 18, _, true)); } else { __then(); } ; })(__then); } ; })(function __$generateVMDiagExtensionProfile__2() {


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


  _generateVMDiagLinuxProfile: function _generateVMDiagLinuxProfile__3(_) { var __this = this; var __frame = { name: "_generateVMDiagLinuxProfile__3", line: 108 }; return __func(_, this, arguments, _generateVMDiagLinuxProfile__3, 0, __frame, function __$_generateVMDiagLinuxProfile__3() {
      if (utils.stringIsNullOrEmpty(__this.params.version)) {
        __this.params.version = vmConstants.EXTENSIONS.LINUX_DIAG_VERSION; } ;


      __this.params.extensionName = vmConstants.EXTENSIONS.LINUX_DIAG_NAME;
      __this.params.publisherName = vmConstants.EXTENSIONS.LINUX_DIAG_PUBLISHER;
      __this.params.publicConfig = __this._createDiagPublicConfiguration();
      return __this._createDiagPrivateConfiguration(__cb(_, __frame, 8, 37, function ___(__0, __1) { __this.params.privateConfig = __1;
        __this.params.autoUpgradeMinorVersion = true;

        return _(null, __this.generateExtensionProfile()); }, true)); }); },


  _generateVMDiagWindowsProfile: function _generateVMDiagWindowsProfile__4(_) { var __this = this; var __frame = { name: "_generateVMDiagWindowsProfile__4", line: 122 }; return __func(_, this, arguments, _generateVMDiagWindowsProfile__4, 0, __frame, function __$_generateVMDiagWindowsProfile__4() {
      if (utils.stringIsNullOrEmpty(__this.params.version)) {
        __this.params.version = vmConstants.EXTENSIONS.IAAS_DIAG_VERSION; } ;


      __this.params.extensionName = vmConstants.EXTENSIONS.IAAS_DIAG_NAME;
      __this.params.publisherName = vmConstants.EXTENSIONS.IAAS_DIAG_PUBLISHER;
      __this.params.publicConfig = __this._createDiagPublicConfiguration();
      return __this._createDiagPrivateConfiguration(__cb(_, __frame, 8, 38, function ___(__0, __1) { __this.params.privateConfig = __1;
        __this.params.autoUpgradeMinorVersion = true;

        return _(null, __this.generateExtensionProfile()); }, true)); }); },


  _createDiagPublicConfiguration: function() {
    var config = {
      xmlCfg: null,
      ladCfg: null,
      storageAccount: null };


    if (!utils.stringIsNullOrEmpty(this.params.configFile)) {
      var configFile = fs.readFileSync(this.params.configFile);
      config.xmlCfg = new Buffer(configFile).toString("base64"); }
     else {
      if ((this.params.osType === "Windows")) {
        this.cli.output.verbose($("--config-file is not specified, using default one."));
        config.xmlCfg = new Buffer(this._generateDefaultWindowsXmlCfg(this.params.vmID)).toString("base64"); }
       else if ((this.params.osType === "Linux")) {
        this.cli.output.verbose($("--config-file is not specified, using default one."));
        config.ladCfg = this._generateDefaultLinuxXmlCfg(this.params.vmID); }
       else {

        return null; }  ; } ;



    config.storageAccount = this._getStorageAccountName();

    return config; },


  _generateDefaultWindowsXmlCfg: function(vmID) {
    var wadCfg = {
      DiagnosticMonitorConfiguration: {
      "@": {
          overallQuotaInMB: "4096" },

        DiagnosticInfrastructureLogs: {
        "@": {
            scheduledTransferPeriod: "PT1M",
            scheduledTransferLogLevelFilter: "Warning" } },


        PerformanceCounters: {
        "@": {
            scheduledTransferPeriod: "PT1M" },

          PerformanceCounterConfiguration: [{

          "@": {
              counterSpecifier: "\\Processor(_Total)\\% Processor Time",
              sampleRate: "PT15S",
              unit: "Percent" },

            annotation: {
            "@": {
                displayName: "CPU utilization",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\Processor(_Total)\\% Privileged Time",
              sampleRate: "PT15S",
              unit: "Percent" },

            annotation: {
            "@": {
                displayName: "CPU privileged time",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\Processor(_Total)\\% User Time",
              sampleRate: "PT15S",
              unit: "Percent" },

            annotation: {
            "@": {
                displayName: "CPU user time",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: ("\\Processor" + " Information(_Total)\\Processor Frequency"),

              sampleRate: "PT15S",
              unit: "Count" },

            annotation: {
            "@": {
                displayName: "CPU frequency",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\System\\Processes",
              sampleRate: "PT15S",
              unit: "Count" },

            annotation: {
            "@": {
                displayName: "Processes",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\Process(_Total)\\Thread Count",
              sampleRate: "PT15S",
              unit: "Count" },

            annotation: {
            "@": {
                displayName: "Threads",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\Process(_Total)\\Handle Count",
              sampleRate: "PT15S",
              unit: "Count" },

            annotation: {
            "@": {
                displayName: "Handles",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\Memory\\% Committed Bytes In Use",
              sampleRate: "PT15S",
              unit: "Percent" },

            annotation: {
            "@": {
                displayName: "Memory usage",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\Memory\\Available Bytes",
              sampleRate: "PT15S",
              unit: "Bytes" },

            annotation: {
            "@": {
                displayName: "Memory available",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\Memory\\Committed Bytes",
              sampleRate: "PT15S",
              unit: "Bytes" },

            annotation: {
            "@": {
                displayName: "Memory committed",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\Memory\\Commit Limit",
              sampleRate: "PT15S",
              unit: "Bytes" },

            annotation: {
            "@": {
                displayName: "Memory commit limit",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\Memory\\Pool Paged Bytes",
              sampleRate: "PT15S",
              unit: "Bytes" },

            annotation: {
            "@": {
                displayName: "Memory paged pool",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\Memory\\Pool Nonpaged Bytes",
              sampleRate: "PT15S",
              unit: "Bytes" },

            annotation: {
            "@": {
                displayName: "Memory non-paged pool",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\PhysicalDisk(_Total)\\% Disk Time",
              sampleRate: "PT15S",
              unit: "Percent" },

            annotation: {
            "@": {
                displayName: "Disk active time",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\PhysicalDisk(_Total)\\% Disk Read Time",
              sampleRate: "PT15S",
              unit: "Percent" },

            annotation: {
            "@": {
                displayName: "Disk active read time",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\PhysicalDisk(_Total)\\% Disk Write Time",
              sampleRate: "PT15S",
              unit: "Percent" },

            annotation: {
            "@": {
                displayName: "Disk active write time",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\PhysicalDisk(_Total)\\Disk Transfers/sec",
              sampleRate: "PT15S",
              unit: "CountPerSecond" },

            annotation: {
            "@": {
                displayName: "Disk operations",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\PhysicalDisk(_Total)\\Disk Reads/sec",
              sampleRate: "PT15S",
              unit: "CountPerSecond" },

            annotation: {
            "@": {
                displayName: "Disk read operations",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\PhysicalDisk(_Total)\\Disk Writes/sec",
              sampleRate: "PT15S",
              unit: "CountPerSecond" },

            annotation: {
            "@": {
                displayName: "Disk write operations",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\PhysicalDisk(_Total)\\Disk Bytes/sec",
              sampleRate: "PT15S",
              unit: "BytesPerSecond" },

            annotation: {
            "@": {
                displayName: "Disk speed",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\PhysicalDisk(_Total)\\Disk Read Bytes/sec",
              sampleRate: "PT15S",
              unit: "BytesPerSecond" },

            annotation: {
            "@": {
                displayName: "Disk read speed",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: ("\\PhysicalDisk(_Total)\\Disk Write" + " Bytes/sec"),

              sampleRate: "PT15S",
              unit: "BytesPerSecond" },

            annotation: {
            "@": {
                displayName: "Disk write speed",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: ("\\PhysicalDisk(_Total)\\Avg. Disk Queue" + " Length"),

              sampleRate: "PT15S",
              unit: "Count" },

            annotation: {
            "@": {
                displayName: "Disk average queue length",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: ("\\PhysicalDisk(_Total)\\Avg. Disk Read" + " Queue Length"),

              sampleRate: "PT15S",
              unit: "Count" },

            annotation: {
            "@": {
                displayName: "Disk average read queue length",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: ("\\PhysicalDisk(_Total)\\Avg. Disk Write" + " Queue Length"),

              sampleRate: "PT15S",
              unit: "Count" },

            annotation: {
            "@": {
                displayName: "Disk average write queue length",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\LogicalDisk(_Total)\\% Free Space",
              sampleRate: "PT15S",
              unit: "Percent" },

            annotation: {
            "@": {
                displayName: "Disk free space (percentage)",
                locale: "en-us" } }



          },{
          "@": {
              counterSpecifier: "\\LogicalDisk(_Total)\\Free Megabytes",
              sampleRate: "PT15S",
              unit: "Count" },

            annotation: {
            "@": {
                displayName: "Disk free space (MB)",
                locale: "en-us" } } },] },





        WindowsEventLog: {
        "@": {
            scheduledTransferPeriod: "PT1M" },

          DataSource: [{

          "@": {
              name: "Application!*[System[(Level = 1 or Level = 2)]]" }


          },{
          "@": {
              name: "Security!*[System[(Level = 1 or Level = 2)]" }


          },{
          "@": {
              name: "System!*[System[(Level = 1 or Level = 2)]]" } },] },




        Metrics: {
        "@": {
            resourceId: vmID },

          MetricAggregation: [{

          "@": {
              scheduledTransferPeriod: "PT1H" }


          },{
          "@": {
              scheduledTransferPeriod: "PT1M" } },] } } };







    var options = {
      declaration: { include: false },
      prettyPrinting: { enabled: false } };


    return js2xmlparser("WadCfg", wadCfg, options); },


  _generateDefaultLinuxXmlCfg: function(vmID) {
    var ladCfg = {
      diagnosticMonitorConfiguration: {
        metrics: {
          resourceId: vmID,
          metricAggregation: [{

            scheduledTransferPeriod: "PT1H"

          },{
            scheduledTransferPeriod: "PT1M" },] },



        performanceCounters: {
          performanceCounterConfiguration: [{

            class: "Memory",
            counterSpecifier: "PercentAvailableMemory",
            table: "LinuxMemory"
          },{
            class: "Memory",
            counterSpecifier: "AvailableMemory",
            table: "LinuxMemory"
          },{
            class: "Memory",
            counterSpecifier: "UsedMemory",
            table: "LinuxMemory"
          },{
            class: "Memory",
            counterSpecifier: "PercentUsedSwap",
            table: "LinuxMemory"
          },{
            class: "Processor",
            counterSpecifier: "PercentProcessorTime",
            table: "LinuxCpu"
          },{
            class: "Processor",
            counterSpecifier: "PercentIOWaitTime",
            table: "LinuxCpu"
          },{
            class: "Processor",
            counterSpecifier: "PercentIdleTime",
            table: "LinuxCpu"
          },{
            class: "PhysicalDisk",
            counterSpecifier: "AverageWriteTime",
            table: "LinuxDisk"
          },{
            class: "PhysicalDisk",
            counterSpecifier: "AverageReadTime",
            table: "LinuxDisk"
          },{
            class: "PhysicalDisk",
            counterSpecifier: "ReadBytesPerSecond",
            table: "LinuxDisk"
          },{
            class: "PhysicalDisk",
            counterSpecifier: "WriteBytesPerSecond",
            table: "LinuxDisk" },] } } };






    return ladCfg; },


  _createDiagPrivateConfiguration: function _createDiagPrivateConfiguration__5(_) { var config, keys, __this = this; var __frame = { name: "_createDiagPrivateConfiguration__5", line: 658 }; return __func(_, this, arguments, _createDiagPrivateConfiguration__5, 0, __frame, function __$_createDiagPrivateConfiguration__5() {
      config = {
        storageAccountName: null,
        storageAccountKey: null,
        storageAccountEndPoint: "https://core.windows.net:443/" };


      config.storageAccountName = __this._getStorageAccountName();
      return __this.serviceClients.storageManagementClient.storageAccounts.listKeys(__this.params.resourceGroupName, config.storageAccountName, __cb(_, __frame, 8, 75, function ___(__0, __1) { keys = __1;
        config.storageAccountKey = keys.keys[0].value;

        return _(null, config); }, true)); }); },


  _getStorageAccountName: function() {
    if (!utils.stringIsNullOrEmpty(this.params.storageAccountName)) {
      return this.params.storageAccountName; } ;


    if (utils.stringIsNullOrEmpty(this.params.osDiskUri)) {
      throw new Error($("params.osDiskUri is required when --storage-account-name parameter is not specified")); } ;


    var osDiskUri = blobUtil.splitDestinationUri(this.params.osDiskUri);
    return osDiskUri.accountName; },


  generateVMAemProfile: function() {
    if ((this.params.osType === "Linux")) {
      return this._generateVMAemLinuxProfile(); }
     else if ((this.params.osType === "Windows")) {
      return this._generateVMAemWindowsProfile(); }  ;

    return null; },


  _generateVMAemWindowsProfile: function() {
    if (utils.stringIsNullOrEmpty(this.params.version)) {
      this.params.version = vmConstants.EXTENSIONS.IAAS_AEM_VERSION; } ;


    this.params.extensionName = vmConstants.EXTENSIONS.IAAS_AEM_NAME;
    this.params.publisherName = vmConstants.EXTENSIONS.IAAS_AEM_PUBLISHER;
    this.params.autoUpgradeMinorVersion = true;

    this._createAemConfiguration();

    return this.generateExtensionProfile(); },


  _generateVMAemLinuxProfile: function() {
    if (utils.stringIsNullOrEmpty(this.params.version)) {
      this.params.version = vmConstants.EXTENSIONS.LINUX_AEM_VERSION; } ;


    this.params.extensionName = vmConstants.EXTENSIONS.LINUX_AEM_NAME;
    this.params.publisherName = vmConstants.EXTENSIONS.LINUX_AEM_PUBLISHER;
    this.params.autoUpgradeMinorVersion = true;

    this._createAemConfiguration();

    return this.generateExtensionProfile(); },


  _createAemConfiguration: function() {
    var publicConfig = {
      vmsize: this.params.vmSize,
    "vm.role": "IaaS",
    "vm.memory.isovercommitted": 0,
    "vm.cpu.isovercommitted": ((((this.params.vmSize === "ExtralSmall")) ? 1 : 0)),
      verbose: (((this.params.verbose) ? "1" : "0")),
      href: "http://aka.ms/sapaem" };



    var vmType = this.params.vmSize.slice(0, "Standard_DS".length);
    if (((vmType === "Standard_DS") || (vmType === "Standard_GS"))) {
      vmSizeProfile = (vmConstants.PREMIUM_STORAGE_VM_SIZES[this.params.vmSize.toUpperCase()] || { });
      publicConfig["vm.sla.iops"] = vmSizeProfile.IOPS;
      publicConfig["vm.sla.throughput"] = vmSizeProfile.THROUGHPUT; } ;


    var privateConfig = { };
    var saProperties = null;
    var premiumDiskType = null;
    var storageAccountProfile = null;


    var osDiskUri = blobUtil.splitDestinationUri(this.params.osDisk.vhd.uri);
    saProperties = this.params.vmStorageAccounts[osDiskUri.accountName];
    publicConfig["osdisk.account"] = saProperties.name;

    var tmp = this.params.osDisk.vhd.uri;
    publicConfig["osdisk.name"] = tmp.substr((tmp.lastIndexOf("/") + 1));

    publicConfig["osdisk.caching"] = this.params.osDisk.caching;
    publicConfig["osdisk.type"] = saProperties.type;

    if ((saProperties.type === "Premium")) {
      premiumDiskType = "P10";
      storageAccountProfile = (vmConstants.PREMIUM_STORAGE_ACCOUNTS[premiumDiskType] || { });
      publicConfig["osdisk.sla.iops"] = storageAccountProfile.IOPS;
      publicConfig["osdisk.sla.throughput"] = storageAccountProfile.THROUGHPUT; }
     else {
      publicConfig["osdisk.connminute"] = (saProperties.name + ".minute");
      publicConfig["osdisk.connhour"] = (saProperties.name + ".hour"); } ;



    this._addStorageAccountConfig(publicConfig, privateConfig, saProperties);


    for (var i = 1; (i <= this.params.dataDisks.length); i++) {
      var dataDisk = this.params.dataDisks[(i - 1)];
      var dataDiskUri = blobUtil.splitDestinationUri(dataDisk.vhd.uri);
      saProperties = this.params.vmStorageAccounts[dataDiskUri.accountName];
      publicConfig[("disk.account." + i)] = saProperties.name;
      publicConfig[("disk.lun." + i)] = dataDisk.lun;
      publicConfig[("disk.name." + i)] = (dataDisk.name + ".vhd");
      publicConfig[("disk.caching." + i)] = dataDisk.caching;
      publicConfig[("disk.type." + i)] = saProperties.type;

      if ((saProperties.type === "Premium")) {
        premiumDiskType = "P10";
        if ((dataDisk.diskSizeGB == 1023)) {
          premiumDiskType = "P30"; }
         else if ((dataDisk.diskSizeGB == 512)) {
          premiumDiskType = "P20"; }
         else if ((dataDisk.diskSizeGB == 128)) {
          premiumDiskType = "P10"; }   ;

        storageAccountProfile = (vmConstants.PREMIUM_STORAGE_ACCOUNTS[premiumDiskType] || { });
        publicConfig[("disk.sla.iops." + i)] = storageAccountProfile.IOPS;
        publicConfig[("disk.sla.throughput." + i)] = storageAccountProfile.THROUGHPUT; }
       else {
        publicConfig[("disk.connminute." + i)] = (saProperties.name + ".minute");
        publicConfig[("disk.connhour." + i)] = (dataDisk.name + ".hour"); } ;


      this._addStorageAccountConfig(publicConfig, privateConfig, saProperties); };



    saProperties = this.params.vmStorageAccounts[this.params.wadStorageAccount];
    publicConfig["wad.isenabled"] = 1;
    publicConfig["wad.name"] = saProperties.name;
    publicConfig["wad.uri"] = saProperties.endpoints.table;
    privateConfig["wad.key"] = saProperties.key;

    publicConfig["timestamp"] = Date.now();

    this.params.publicConfig = {
      cfg: this._generateKeyValuePairConfig(publicConfig) };

    this.params.privateConfig = {
      cfg: this._generateKeyValuePairConfig(privateConfig) }; },



  _addStorageAccountConfig: function(publicConfig, privateConfig, saProperties) {
    if ((saProperties.type === "Premium")) {
      publicConfig[(saProperties.name + ".hour.ispremium")] = 1;
      publicConfig[(saProperties.name + ".minute.ispremium")] = 1;
      privateConfig[(saProperties.name + ".hour.key")] = saProperties.key; }
     else {
      publicConfig[(saProperties.name + ".hour.ispremium")] = 0;
      publicConfig[(saProperties.name + ".minute.ispremium")] = 0;
      publicConfig[(saProperties.name + ".hour.name")] = saProperties.name;
      publicConfig[(saProperties.name + ".minute.name")] = saProperties.name;
      publicConfig[(saProperties.name + ".hour.uri")] = (saProperties.endpoints.table + "$MetricsHourPrimaryTransactionsBlob");
      publicConfig[(saProperties.name + ".minute.uri")] = (saProperties.endpoints.table + "$MetricsMinutePrimaryTransactionsBlob");

      privateConfig[(saProperties.name + ".minute.key")] = saProperties.key; } ; },



  _generateKeyValuePairConfig: function(config) {
    var keyValuePairs = [];
    var self = this;
    __.map(config, function(value, key) {
      if ((typeof value === "undefined")) {
        self.output.warn(util.format($("Empty value: %s"), key));
        return; } ;

      keyValuePairs.push({
        key: key,
        value: value }); });


    return keyValuePairs; },


  _generateVMAccessLinuxProfile: function() {
    if (((utils.stringIsNullOrEmpty(this.params.userName) && utils.stringIsNullOrEmpty(this.params.removeUser)) && !this.params.resetSsh)) {


      throw new Error($("Either --user-name or --remove-user or --reset-ssh params are required.")); } ;


    if (!utils.stringIsNullOrEmpty(this.params.userName)) {
      if ((utils.stringIsNullOrEmpty(this.params.password) && utils.stringIsNullOrEmpty(this.params.sshKeyFile))) {
        throw new Error(util.format($("Either password or SSH key are required to reset access for user %s."), this.params.userName)); } ; } ;



    if (utils.stringIsNullOrEmpty(this.params.version)) {
      this.params.version = vmConstants.EXTENSIONS.LINUX_ACCESS_VERSION; } ;


    this.params.extensionName = vmConstants.EXTENSIONS.LINUX_ACCESS_NAME;
    this.params.publisherName = vmConstants.EXTENSIONS.LINUX_ACCESS_PUBLISHER;
    this.params.privateConfig = this._createVMAccessLinuxPrivateConfig();

    return this.generateExtensionProfile(); },


  _generateVMAccessWindowsProfile: function() {
    var self = this;
    if ((utils.stringIsNullOrEmpty(this.params.userName) || utils.stringIsNullOrEmpty(this.params.password))) {
      throw new Error($("Both user name and password are required.")); } ;


    if (((!utils.stringIsNullOrEmpty(this.params.removeUser) || this.params.resetSsh) || !utils.stringIsNullOrEmpty(this.params.sshKeyFile))) {


      self.output.warn($("Resetting access on Windows VM, --reset-ssh, --ssh-key-file and--remove-user parameters will be ignored.")); } ;


    if (utils.stringIsNullOrEmpty(this.params.version)) {
      this.params.version = vmConstants.EXTENSIONS.WINDOWS_ACCESS_VERSION; } ;


    this.params.extensionName = vmConstants.EXTENSIONS.WINDOWS_ACCESS_NAME;
    this.params.publisherName = vmConstants.EXTENSIONS.WINDOWS_ACCESS_PUBLISHER;
    this.params.publicConfig = { UserName: this.params.userName };
    this.params.privateConfig = { Password: this.params.password };

    return this.generateExtensionProfile(); },


  _parseExtensionProfileParams: function(params) {
    if ((params.publicConfig && params.publicConfigPath)) {
      throw new Error($("Both optional parameters --public-config and --public-config-path cannot be specified together.")); } ;


    if ((params.privateConfig && params.privateConfigPath)) {
      throw new Error($("Both optional parameters --private-config and --private-config-path cannot be specified together.")); } ;


    var extensionProfile = {
      name: params.extensionName,
      type: vmConstants.EXTENSIONS.TYPE,
      location: params.location,
      tags: null,
      publisher: params.publisherName,
      virtualMachineExtensionType: params.extensionName,
      typeHandlerVersion: params.version,
      settings: null,
      autoUpgradeMinorVersion: null,
      protectedSettings: null };


    if (params.publicConfig) {
      if ((typeof params.publicConfig === "string")) {
        extensionProfile.settings = this._parseExtensionConfig(params.publicConfig, $("Error parsing public config")); }
       else {
        extensionProfile.settings = params.publicConfig; } ; } ;



    if (params.privateConfig) {
      if ((typeof params.privateConfig === "string")) {
        extensionProfile.protectedSettings = this._parseExtensionConfig(params.privateConfig, $("Error parsing private config")); }
       else {
        extensionProfile.protectedSettings = params.privateConfig; } ; } ;



    if (params.publicConfigPath) {
      var publicConfig = fs.readFileSync(params.publicConfigPath);
      extensionProfile.settings = this._parseExtensionConfig(publicConfig.toString(), util.format($("Error parsing public config from file %s"), params.publicConfigPath)); } ;


    if (params.privateConfigPath) {
      var privateConfig = fs.readFileSync(params.privateConfigPath);
      extensionProfile.protectedSettings = this._parseExtensionConfig(privateConfig.toString(), util.format($("Error parsing private config from file %s"), params.privateConfigPath)); } ;


    if (params.tags) {
      extensionProfile.tags = { };
      extensionProfile.tags = tagUtils.buildTagsParameter(extensionProfile.tags, { tags: params.tags }); } ;


    if (params.autoUpgradeMinorVersion) {
      extensionProfile.autoUpgradeMinorVersion = true; } ;


    return extensionProfile; },


  _parseExtensionConfig: function(config, errorMessage) {
    try {
      var parsedConfig = JSON.parse(config);
      return parsedConfig;
    } catch (err) {
      throw new Error(util.format($("%s. %s"), errorMessage, err)); }; },



  _createVMAccessLinuxPrivateConfig: function() {
    var privateConfig = { };

    if (this.params.resetSsh) {
      privateConfig["reset_ssh"] = true; } ;


    if (!utils.stringIsNullOrEmpty(this.params.userName)) {
      privateConfig["username"] = this.params.userName; } ;


    if (!utils.stringIsNullOrEmpty(this.params.password)) {
      privateConfig["password"] = this.params.password; } ;


    if (!utils.stringIsNullOrEmpty(this.params.expiration)) {
      privateConfig["expiration"] = this.params.expiration; } ;


    if (!utils.stringIsNullOrEmpty(this.params.sshKeyFile)) {
      var publicKey = this._parseSSHPublicKeyFile(this.params.sshKeyFile);
      privateConfig["ssh_key"] = publicKey; } ;


    if (!utils.stringIsNullOrEmpty(this.params.removeUser)) {
      privateConfig["remove_user"] = this.params.removeUser; } ;



    privateConfig["task_id"] = utils.uuidGen();

    return privateConfig; },


  _parseSSHPublicKeyFile: function(sshKeyFile) {
    var self = this;
    self.output.info(util.format($("Parsing the public key SSH file: %s"), sshKeyFile));
    var sshPublickeyData = fs.readFileSync(sshKeyFile);
    var sshPublickeyDataStr = sshPublickeyData.toString();

    return sshPublickeyDataStr; },


  _checkAndGenerateDockerCertificatesIfNeeded: function _checkAndGenerateDockerCertificatesIfNeeded__6(dockerCertPaths, serverCN, _) { var self, dockerDirExists, progress, password, missingClientCertificates, missingServerCertificates, __this = this; var __frame = { name: "_checkAndGenerateDockerCertificatesIfNeeded__6", line: 1010 }; return __func(_, this, arguments, _checkAndGenerateDockerCertificatesIfNeeded__6, 2, __frame, function __$_checkAndGenerateDockerCertificatesIfNeeded__6() { self = __this;

      return utils.fileExists(__this.params.dockerCertDir, __cb(_, __frame, 2, 32, function ___(__0, __1) { dockerDirExists = __1;

        password = "Docker123"; return (function __$_checkAndGenerateDockerCertificatesIfNeeded__6(__then) {
          if (!dockerDirExists) {
            self.output.verbose($("Docker certificates were not found."));
            return fs.mkdir(__this.params.dockerCertDir, __cb(_, __frame, 7, 9, function __$_checkAndGenerateDockerCertificatesIfNeeded__6() {
              progress = __this.cli.interaction.progress($("Generating docker certificates.")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$_checkAndGenerateDockerCertificatesIfNeeded__6() {

                    return __this._generateDockerCertificates(dockerCertPaths, password, serverCN, __cb(_, __frame, 10, 13, function __$_checkAndGenerateDockerCertificatesIfNeeded__6() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$_checkAndGenerateDockerCertificatesIfNeeded__6() {

                      progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, __then); }); }, true)); } else {




            return __this._checkExistingDockerClientCertificates(dockerCertPaths, __cb(_, __frame, 17, 43, function ___(__0, __2) { missingClientCertificates = __2; return (function __$_checkAndGenerateDockerCertificatesIfNeeded__6(__then) {
                if ((missingClientCertificates.length === 0)) {
                  self.output.verbose($("Found docker client certificates."));
                  return __this._checkExistingDockerServerCertificates(dockerCertPaths, __cb(_, __frame, 20, 45, function ___(__0, __3) { missingServerCertificates = __3; return (function __$_checkAndGenerateDockerCertificatesIfNeeded__6(__then) {
                      if ((missingServerCertificates.length === 0)) {
                        self.output.verbose($("Found docker server certificates.")); __then(); } else {

                        return __this._generateDockerServerCertificates(dockerCertPaths, password, serverCN, __cb(_, __frame, 24, 15, __then, true)); } ; })(__then); }, true)); } else {


                  for (i = 0; (i < missingClientCertificates.length); i++) {
                    self.output.verbose(missingClientCertificates[i]); };


                  progress = __this.cli.interaction.progress($("Generating docker certificates.")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$_checkAndGenerateDockerCertificatesIfNeeded__6() {

                        return __this._generateDockerCertificates(dockerCertPaths, password, serverCN, __cb(_, __frame, 33, 15, function __$_checkAndGenerateDockerCertificatesIfNeeded__6() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$_checkAndGenerateDockerCertificatesIfNeeded__6() {

                          progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, __then); }); } ; })(__then); }, true)); } ; })(_); }, true)); }); },





  _checkExistingDockerClientCertificates: function _checkExistingDockerClientCertificates__7(dockerCertPaths, _) { var missingCertificates, __this = this; var __frame = { name: "_checkExistingDockerClientCertificates__7", line: 1051 }; return __func(_, this, arguments, _checkExistingDockerClientCertificates__7, 1, __frame, function __$_checkExistingDockerClientCertificates__7() {
      missingCertificates = [];
      return __this._checkIfDockerCertificateExist(missingCertificates, dockerCertPaths.caKey, __cb(_, __frame, 2, 9, function __$_checkExistingDockerClientCertificates__7() {
        return __this._checkIfDockerCertificateExist(missingCertificates, dockerCertPaths.ca, __cb(_, __frame, 3, 9, function __$_checkExistingDockerClientCertificates__7() {
          return __this._checkIfDockerCertificateExist(missingCertificates, dockerCertPaths.clientKey, __cb(_, __frame, 4, 9, function __$_checkExistingDockerClientCertificates__7() {
            return __this._checkIfDockerCertificateExist(missingCertificates, dockerCertPaths.clientCert, __cb(_, __frame, 5, 9, function __$_checkExistingDockerClientCertificates__7() {

              return _(null, missingCertificates); }, true)); }, true)); }, true)); }, true)); }); },


  _checkExistingDockerServerCertificates: function _checkExistingDockerServerCertificates__8(dockerCertPaths, _) { var missingCertificates, __this = this; var __frame = { name: "_checkExistingDockerServerCertificates__8", line: 1061 }; return __func(_, this, arguments, _checkExistingDockerServerCertificates__8, 1, __frame, function __$_checkExistingDockerServerCertificates__8() {
      missingCertificates = [];
      return __this._checkIfDockerCertificateExist(missingCertificates, dockerCertPaths.serverKey, __cb(_, __frame, 2, 9, function __$_checkExistingDockerServerCertificates__8() {
        return __this._checkIfDockerCertificateExist(missingCertificates, dockerCertPaths.serverCert, __cb(_, __frame, 3, 9, function __$_checkExistingDockerServerCertificates__8() {

          return _(null, missingCertificates); }, true)); }, true)); }); },


  _checkIfDockerCertificateExist: function _checkIfDockerCertificateExist__9(missingCertificates, filepath, _) { var fileExists; var __frame = { name: "_checkIfDockerCertificateExist__9", line: 1069 }; return __func(_, this, arguments, _checkIfDockerCertificateExist__9, 2, __frame, function __$_checkIfDockerCertificateExist__9() {
      return utils.fileExists(filepath, __cb(_, __frame, 1, 27, function ___(__0, __1) { fileExists = __1;
        if (!fileExists) {
          missingCertificates.push(util.format($("%s file was not found"), filepath)); } ; _(); }, true)); }); },



  _generateDockerCertificates: function _generateDockerCertificates__10(dockerCertPaths, password, serverCN, _) { var self, __this = this; var __frame = { name: "_generateDockerCertificates__10", line: 1076 }; return __func(_, this, arguments, _generateDockerCertificates__10, 3, __frame, function __$_generateDockerCertificates__10() { self = __this;


      self.output.verbose(util.format($("Password for docker certificates is \"%s\""), password)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$_generateDockerCertificates__10() {

            return exec("openssl version", __cb(_, __frame, 5, 6, __then, true)); }); })(function ___(e, __result) { __catch(function __$_generateDockerCertificates__10() { if (e) {

              return _(new Error(util.format($("Please install/configure OpenSSL client. Error: %s"), e.message))); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$_generateDockerCertificates__10() {


          return __this._executeOpensslCommand("genrsa", {
            des3: true,
            passout: ("pass:" + password),
            out: dockerCertPaths.caKey }, __cb(_, __frame, 10, 9, function __$_generateDockerCertificates__10() {



            return __this._executeOpensslCommand("req", {
              new: true,
              x509: true,
              days: 365,
              passin: ("pass:" + password),
              subj: "/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=\\*",
              key: dockerCertPaths.caKey,
              out: dockerCertPaths.ca }, __cb(_, __frame, 17, 9, function __$_generateDockerCertificates__10() {


              return __this._generateDockerServerCertificates(dockerCertPaths, password, serverCN, __cb(_, __frame, 27, 9, function __$_generateDockerCertificates__10() {
                return __this._generateDockerClientCertificates(dockerCertPaths, password, __cb(_, __frame, 28, 9, function __$_generateDockerCertificates__10() {


                  fs.chmodSync(dockerCertPaths.caKey, 384);
                  fs.chmodSync(dockerCertPaths.ca, 384); return _(null); }, true)); }, true)); }, true)); }, true)); }); }); }); },



  _generateDockerServerCertificates: function _generateDockerServerCertificates__11(dockerCertPaths, password, serverCN, _) { var __this = this; var __frame = { name: "_generateDockerServerCertificates__11", line: 1112 }; return __func(_, this, arguments, _generateDockerServerCertificates__11, 3, __frame, function __$_generateDockerServerCertificates__11() {

      return __this._executeOpensslCommand("genrsa", {
        des3: true,
        passout: ("pass:" + password),
        out: dockerCertPaths.serverKey }, __cb(_, __frame, 2, 9, function __$_generateDockerServerCertificates__11() {


        if (utils.stringIsNullOrEmpty(serverCN)) {
          serverCN = "*"; } ;

        return __this._executeOpensslCommand("req", {
          new: true,
          passin: ("pass:" + password),
          subj: ("/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=" + serverCN),
          key: dockerCertPaths.serverKey,
          out: dockerCertPaths.server }, __cb(_, __frame, 11, 9, function __$_generateDockerServerCertificates__11() {



          return __this._executeOpensslCommand("x509", {
            req: true,
            days: 365,
            in: dockerCertPaths.server,
            passin: ("pass:" + password),
            set_serial: 1,
            CA: dockerCertPaths.ca,
            CAkey: dockerCertPaths.caKey,
            out: dockerCertPaths.serverCert }, __cb(_, __frame, 20, 9, function __$_generateDockerServerCertificates__11() {


            return __this._executeOpensslCommand("rsa", {
              passin: ("pass:" + password),
              in: dockerCertPaths.serverKey,
              passout: ("pass:" + password),
              out: dockerCertPaths.serverKey }, __cb(_, __frame, 31, 9, function __$_generateDockerServerCertificates__11() {


              fs.chmodSync(dockerCertPaths.serverKey, 384);
              fs.chmodSync(dockerCertPaths.server, 384);
              fs.chmodSync(dockerCertPaths.serverCert, 384); _(); }, true)); }, true)); }, true)); }, true)); }); },


  _generateDockerClientCertificates: function _generateDockerClientCertificates__12(dockerCertPaths, password, _) { var configPath, __this = this; var __frame = { name: "_generateDockerClientCertificates__12", line: 1155 }; return __func(_, this, arguments, _generateDockerClientCertificates__12, 2, __frame, function __$_generateDockerClientCertificates__12() {

      return __this._executeOpensslCommand("genrsa", {
        des3: true,
        passout: ("pass:" + password),
        out: dockerCertPaths.clientKey }, __cb(_, __frame, 2, 9, function __$_generateDockerClientCertificates__12() {


        return __this._executeOpensslCommand("req", {
          new: true,
          passin: ("pass:" + password),
          subj: "/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=\\*",
          key: dockerCertPaths.clientKey,
          out: dockerCertPaths.client }, __cb(_, __frame, 8, 9, function __$_generateDockerClientCertificates__12() {


          configPath = path.join(__this.params.dockerCertDir, "extfile.cnf");
          return fs.writeFile(configPath, "extendedKeyUsage = clientAuth", __cb(_, __frame, 17, 7, function __$_generateDockerClientCertificates__12() {

            return __this._executeOpensslCommand("x509", {
              req: true,
              days: 365,
              in: dockerCertPaths.client,
              passin: ("pass:" + password),
              set_serial: 1,
              extfile: configPath,
              CA: dockerCertPaths.ca,
              CAkey: dockerCertPaths.caKey,
              out: dockerCertPaths.clientCert }, __cb(_, __frame, 19, 9, function __$_generateDockerClientCertificates__12() {


              return __this._executeOpensslCommand("rsa", {
                passin: ("pass:" + password),
                in: dockerCertPaths.clientKey,
                passout: ("pass:" + password),
                out: dockerCertPaths.clientKey }, __cb(_, __frame, 31, 9, function __$_generateDockerClientCertificates__12() {


                fs.chmodSync(dockerCertPaths.clientKey, 384);
                fs.chmodSync(dockerCertPaths.client, 384);
                fs.chmodSync(configPath, 384);
                fs.chmodSync(dockerCertPaths.clientCert, 384); _(); }, true)); }, true)); }, true)); }, true)); }, true)); }); },


  _executeOpensslCommand: function _executeOpensslCommand__13(command, options, _) { var self, __this = this; var __frame = { name: "_executeOpensslCommand__13", line: 1199 }; return __func(_, this, arguments, _executeOpensslCommand__13, 2, __frame, function __$_executeOpensslCommand__13() { self = __this; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$_executeOpensslCommand__13() {


            return openssl.exec(command, options, __cb(_, __frame, 3, 14, __then, true)); }); })(function ___(err, __result) { __catch(function __$_executeOpensslCommand__13() { if (err) {



              self.output.verbose(err); __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$_executeOpensslCommand__13() { _(); }); }); }); },



  _createDockerPublicConfiguration: function() {
    var publicConfig = {
      docker: {
        port: this.params.dockerPort.toString() } };



    return publicConfig; },


  _createDockerPrivateConfiguration: function(dockerCertPaths) {
    var certs = this._getDockerServerCertsInBase64(dockerCertPaths);
    var privateConfig = {
      certs: {
        ca: certs.caCert,
        cert: certs.serverCert,
        key: certs.serverKey } };



    return privateConfig; },


  _getDockerServerCertsInBase64: function(dockerCertPaths) {
    var caCert = this._convertFileToBase64(dockerCertPaths.ca);
    var serverKey = this._convertFileToBase64(dockerCertPaths.serverKey);
    var serverCert = this._convertFileToBase64(dockerCertPaths.serverCert);

    return {
      caCert: caCert,
      serverKey: serverKey,
      serverCert: serverCert }; },



  _convertFileToBase64: function(filePath) {
    var file = fs.readFileSync(filePath);
    return new Buffer(file).toString("base64"); },


  generateVMBgInfoExtensionProfile: function() {
    if (!this.params.versionFound) {
      this.params.version = vmConstants.EXTENSIONS.BGINFO_VERSION; } ;


    this.params.extensionName = vmConstants.EXTENSIONS.BGINFO_NAME;
    this.params.publisherName = vmConstants.EXTENSIONS.BGINFO_PUBLISHER;
    this.params.publicConfig = null;
    this.params.privateConfig = null;
    this.params.autoUpgradeMinorVersion = true;

    return this.generateExtensionProfile(); },


  generateAzureVMBackupExtensionProfile: function() {
    if (utils.ignoreCaseEquals(this.params.osType, "Linux")) {
      return this._generateAzureVMBackupExtensionProfile(); } ;

    return null; },


  _generateAzureVMBackupExtensionProfile: function() {
    if (utils.stringIsNullOrEmpty(this.params.version)) {
      this.params.version = vmConstants.EXTENSIONS.AZURE_VM_BACKUP_LINUX_EXTENSION_VERSION; } ;

    this.params.extensionName = vmConstants.EXTENSIONS.AZURE_VM_BACKUP_LINUX_EXTENSION_NAME;
    this.params.publisherName = vmConstants.EXTENSIONS.AZURE_VM_BACKUP_LINUX_EXTENSION_PUBLISHER;


    var vmBackupPublicConfig = {
      locale: this.params.locale,
      taskId: this.params.taskId,
      commandToExecute: this.params.command,
      commandStartTimeUTCTicks: this.params.commandStartTimeUTCTicks,
      objectStr: this.params.pubObjectStr };


    var vmBackupPrivateConfig = {
      logsBlobUri: null,
      objectStr: this.params.objectStr };


    this.params.publicConfig = vmBackupPublicConfig;
    this.params.privateConfig = vmBackupPrivateConfig;

    return this.generateExtensionProfile(); },


  generateAzureDiskEncryptionExtensionProfile: function() {
    if (utils.ignoreCaseEquals(this.params.osType, "Linux")) {
      return this._generateAzureDiskEncryptionLinuxProfile(); }
     else if (utils.ignoreCaseEquals(this.params.osType, "Windows")) {
      return this._generateAzureDiskEncryptionWindowsProfile(); }  ;


    return null; },


  _generateAzureDiskEncryptionLinuxProfile: function() {


    if ((((utils.stringIsNullOrEmpty(this.params.aadClientId)) || (utils.stringIsNullOrEmpty(this.params.diskEncryptionKeyVaultUrl))) || (utils.stringIsNullOrEmpty(this.params.diskEncryptionKeyVaultId)))) {


      throw new Error($("--aad-client-id, --disk-encryption-key-vault-url, --disk-encryption-key-vault-id are mandatory inputs")); } ;


    if (((utils.stringIsNullOrEmpty(this.params.aadClientSecret)) && (utils.stringIsNullOrEmpty(this.params.aadClientCertThumbprint)))) {

      throw new Error($("Please provide --aad-client-secret or --aad-client-cert-thumbprint correspondong to --aad-client-id")); } ;


    if ((!utils.stringIsNullOrEmpty(this.params.keyEncryptionKeyUrl) && (utils.stringIsNullOrEmpty(this.params.keyEncryptionKeyVaultId)))) {

      throw new Error($("Please provide --key-encryption-key-vault-id correspondong to --key-encryption-key-url")); } ;



    if (utils.stringIsNullOrEmpty(this.params.version)) {
      this.params.version = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_LINUX_EXTENSION_VERSION; } ;

    this.params.extensionName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_LINUX_EXTENSION_NAME;
    this.params.publisherName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_LINUX_EXTENSION_PUBLISHER;


    var adePublicConfig = {
      AADClientID: this.params.aadClientId,
      AADClientCertThumbprint: this.params.aadClientCertThumbprint,
      KeyVaultURL: this.params.diskEncryptionKeyVaultUrl,
      VolumeType: this.params.volumeType,
      EncryptionOperation: "EnableEncryption",
      KeyEncryptionKeyURL: this.params.keyEncryptionKeyUrl,
      KeyEncryptionAlgorithm: this.params.keyEncryptionAlgorithm,
      SequenceVersion: this.params.sequenceVersion,
      AutoUpgradeMinorVersion: this.params.autoUpgradeMinorVersion };


    this.params.publicConfig = adePublicConfig;
    this.params.privateConfig = { AADClientSecret: this.params.aadClientSecret };

    return this.generateExtensionProfile(); },


  _generateAzureDiskEncryptionWindowsProfile: function() {


    if ((((utils.stringIsNullOrEmpty(this.params.aadClientId)) || (utils.stringIsNullOrEmpty(this.params.diskEncryptionKeyVaultUrl))) || (utils.stringIsNullOrEmpty(this.params.diskEncryptionKeyVaultId)))) {


      throw new Error($("--aad-client-id, --disk-encryption-key-vault-url, --disk-encryption-key-vault-id are mandatory inputs")); } ;


    if (((utils.stringIsNullOrEmpty(this.params.aadClientSecret)) && (utils.stringIsNullOrEmpty(this.params.aadClientCertThumbprint)))) {

      throw new Error($("Please provide --aad-client-secret or --aad-client-cert-thumbprint correspondong to --aad-client-id")); } ;


    if ((!utils.stringIsNullOrEmpty(this.params.keyEncryptionKeyUrl) && (utils.stringIsNullOrEmpty(this.params.keyEncryptionKeyVaultId)))) {

      throw new Error($("Please provide --key-encryption-key-vault-id correspondong to --key-encryption-key-url")); } ;



    if (utils.stringIsNullOrEmpty(this.params.version)) {
      this.params.version = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_VERSION; } ;

    this.params.extensionName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_NAME;
    this.params.publisherName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_PUBLISHER;


    var adePublicConfig = {
      AADClientID: this.params.aadClientId,
      AADClientCertThumbprint: this.params.aadClientCertThumbprint,
      KeyVaultURL: this.params.diskEncryptionKeyVaultUrl,
      VolumeType: this.params.volumeType,
      EncryptionOperation: "EnableEncryption",
      KeyEncryptionKeyURL: this.params.keyEncryptionKeyUrl,
      KeyEncryptionAlgorithm: this.params.keyEncryptionAlgorithm,
      SequenceVersion: this.params.sequenceVersion,
      AutoUpgradeMinorVersion: this.params.autoUpgradeMinorVersion };


    this.params.publicConfig = adePublicConfig;
    this.params.privateConfig = { AADClientSecret: this.params.aadClientSecret };

    return this.generateExtensionProfile(); },


  generateDisableAzureDiskEncryptionExtensionProfile: function() {


    if (utils.stringIsNullOrEmpty(this.params.version)) {
      this.params.version = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_VERSION; } ;

    this.params.extensionName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_NAME;
    this.params.publisherName = vmConstants.EXTENSIONS.AZURE_DISK_ENCRYPTION_WINDOWS_EXTENSION_PUBLISHER;


    var adePublicConfig = {
      VolumeType: this.params.volumeType,
      EncryptionOperation: "DisableEncryption",
      SequenceVersion: this.params.sequenceVersion,
      AutoUpgradeMinorVersion: this.params.autoUpgradeMinorVersion };


    this.params.publicConfig = adePublicConfig;
    this.params.privateConfig = { };

    return this.generateExtensionProfile(); }});




module.exports = VMExtensionProfile;
