public NewAzureDeploymentCmdletInfo(string serviceName, string packagePath, string configName, string slot, string label, string name, bool doNotStart, bool warning, ExtensionConfigurationInput config)
        {
            cmdletName = Utilities.NewAzureDeploymentCmdletName;

            cmdletParams.Add(new CmdletParam("ServiceName", serviceName));
            cmdletParams.Add(new CmdletParam("Package", packagePath));
            cmdletParams.Add(new CmdletParam("Configuration", configName));
            cmdletParams.Add(new CmdletParam("Slot", slot));

            if (label != null)
            {
                cmdletParams.Add(new CmdletParam("Label", label));
            }
            if (name != null)
            {
                cmdletParams.Add(new CmdletParam("Name", name));
            }
            if (doNotStart)
            {
                cmdletParams.Add(new CmdletParam("DoNotStart"));
            }
            if (warning)
            {
                cmdletParams.Add(new CmdletParam("TreatWarningsAsError"));
            }
            if (config != null)
            {
                cmdletParams.Add(new CmdletParam("ExtensionConfiguration", config));
            }
        }
 public ExtensionConfigurationBuilder Add(ExtensionConfigurationInput context, string extensionId)
 {
     if (context != null && context.Roles != null)
     {
         context.Roles.ForEach(r => Add(r, extensionId));
     }
     return(this);
 }
        public void ExecuteCommand()
        {
            ValidateParameters();
            ExtensionConfigurationInput context = new ExtensionConfigurationInput
            {
                ProviderNameSpace = ExtensionNameSpace,
                Type = ExtensionType,
                CertificateThumbprint = CertificateThumbprint,
                ThumbprintAlgorithm   = ThumbprintAlgorithm,
                X509Certificate       = X509Certificate,
                PublicConfiguration   = string.Format(PublicConfigurationXmlTemplate.ToString(), ConnectionQualifiers, DefaultEndpointsProtocol, StorageAccountName, DiagnosticsConfiguration != null ? DiagnosticsConfiguration.InnerXml : ""),
                PrivateConfiguration  = string.Format(PrivateConfigurationXmlTemplate.ToString(), StorageKey),
                Roles = Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)).ToList() : new ExtensionRole[] { new ExtensionRole() }.ToList()
            };
            var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);

            ChangeDeployment(extConfig);
        }
示例#4
0
        public void ExecuteCommand()
        {
            ValidateParameters();
            ExtensionConfigurationInput context = new ExtensionConfigurationInput
            {
                ProviderNameSpace = ExtensionNameSpace,
                Type = ExtensionType,
                CertificateThumbprint = CertificateThumbprint,
                ThumbprintAlgorithm   = ThumbprintAlgorithm,
                X509Certificate       = X509Certificate,
                PublicConfiguration   = PublicConfiguration,
                PrivateConfiguration  = PrivateConfiguration,
                Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
            };
            var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);

            ChangeDeployment(extConfig);
        }
        public void ExecuteCommand()
        {
            ValidateParameters();
            ExtensionConfigurationInput context = new ExtensionConfigurationInput
            {
                ProviderNameSpace = ExtensionNameSpace,
                Type = ExtensionType,
                CertificateThumbprint = CertificateThumbprint,
                ThumbprintAlgorithm   = ThumbprintAlgorithm,
                X509Certificate       = X509Certificate,
                PublicConfiguration   = string.Format(PublicConfigurationXmlTemplate.ToString(), Credential.UserName, Expiration.ToString("yyyy-MM-dd")),
                PrivateConfiguration  = string.Format(PrivateConfigurationXmlTemplate.ToString(), Credential.Password.ConvertToUnsecureString()),
                Roles = Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)).ToList() : new ExtensionRole[] { new ExtensionRole() }.ToList()
            };
            var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);

            ChangeDeployment(extConfig);
        }
 public ExtensionConfigurationBuilder Add(ExtensionConfigurationInput context, string extensionId)
 {
     if (context != null && context.Roles != null)
     {
         context.Roles.ForEach(r => Add(r, extensionId));
     }
     return this;
 }
示例#7
0
        private bool VerifyExtensionConfigRDP(ExtensionConfigurationInput resultConfig, string user, string pass, List<string> roles, DateTime exp, string thumbprint = null, string algorithm = null, X509Certificate2 cert = null)
        {
            try
            {
                string resultUserName = GetInnerText(resultConfig.PublicConfiguration, "UserName");
                string resultPassword = GetInnerText(resultConfig.PrivateConfiguration, "Password");
                string resultExpDate = GetInnerText(resultConfig.PublicConfiguration, "Expiration");

                Console.WriteLine("Type: {0}, UserName:{1}, Password: {2}, ExpirationDate: {3}, CertificateThumbprint: {4}, ThumbprintAlgorithm: {5}, X509Certificate: {6}",
                    resultConfig.Type, resultUserName, resultPassword, resultExpDate, resultConfig.CertificateThumbprint, resultConfig.ThumbprintAlgorithm, resultConfig.X509Certificate);

                Assert.AreEqual(resultConfig.Type, "RDP", "Type is not equal!");
                Assert.AreEqual(resultUserName, user);
                Assert.AreEqual(resultPassword, pass);
                Assert.IsTrue(Utilities.CompareDateTime(exp, resultExpDate));

                if (string.IsNullOrWhiteSpace(thumbprint))
                {
                    Assert.IsTrue(string.IsNullOrWhiteSpace(resultConfig.CertificateThumbprint));
                }
                else
                {
                    Assert.AreEqual(resultConfig.CertificateThumbprint, thumbprint, "Certificate thumbprint is not equal!");
                }

                if (string.IsNullOrWhiteSpace(algorithm))
                {
                    Assert.IsTrue(string.IsNullOrWhiteSpace(resultConfig.ThumbprintAlgorithm));
                }
                else
                {
                    Assert.AreEqual(resultConfig.ThumbprintAlgorithm, algorithm, "Thumbprint algorithm is not equal!");
                }
                Assert.AreEqual(resultConfig.X509Certificate, cert, "X509Certificate is not equal!");
                if (resultConfig.Roles.Count == 1 && string.IsNullOrEmpty(resultConfig.Roles[0].RoleName))
                {
                    Assert.IsTrue(roles.Contains(resultConfig.Roles[0].RoleType.ToString()));
                }
                else
                {
                    foreach (ExtensionRole role in resultConfig.Roles)
                    {
                        Assert.IsTrue(roles.Contains(role.RoleName));
                    }
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
示例#8
0
        private bool VerifyExtensionConfigDiag(ExtensionConfigurationInput resultConfig, string storage, List<string> roles, XmlDocument wadconfig = null, string thumbprint = null, string algorithm = null, X509Certificate2 cert = null)
        {
            try
            {
                string resultStorageAccount = GetInnerText(resultConfig.PublicConfiguration, "Name");
                string resultWadCfg = Utilities.GetInnerXml(resultConfig.PublicConfiguration, "WadCfg");
                if (string.IsNullOrWhiteSpace(resultWadCfg))
                {
                    resultWadCfg = null;
                }
                string resultStorageKey = GetInnerText(resultConfig.PrivateConfiguration, "StorageKey");

                Console.WriteLine("Type: {0}, StorageAccountName:{1}, StorageKey: {2}, WadCfg: {3}, CertificateThumbprint: {4}, ThumbprintAlgorithm: {5}, X509Certificate: {6}",
                    resultConfig.Type, resultStorageAccount, resultStorageKey, resultWadCfg, resultConfig.CertificateThumbprint, resultConfig.ThumbprintAlgorithm, resultConfig.X509Certificate);

                Assert.AreEqual(resultConfig.Type, "Diagnostics", "Type is not equal!");
                Assert.AreEqual(resultStorageAccount, storage);
                Assert.IsTrue(Utilities.CompareWadCfg(resultWadCfg, wadconfig));

                if (string.IsNullOrWhiteSpace(thumbprint))
                {
                    Assert.IsTrue(string.IsNullOrWhiteSpace(resultConfig.CertificateThumbprint));
                }
                else
                {
                    Assert.AreEqual(resultConfig.CertificateThumbprint, thumbprint, "Certificate thumbprint is not equal!");
                }
                if (string.IsNullOrWhiteSpace(algorithm))
                {
                    Assert.IsTrue(string.IsNullOrWhiteSpace(resultConfig.ThumbprintAlgorithm));
                }
                else
                {
                    Assert.AreEqual(resultConfig.ThumbprintAlgorithm, algorithm, "Thumbprint algorithm is not equal!");
                }
                Assert.AreEqual(resultConfig.X509Certificate, cert, "X509Certificate is not equal!");
                if (resultConfig.Roles.Count == 1 && string.IsNullOrEmpty(resultConfig.Roles[0].RoleName))
                {
                    Assert.IsTrue(roles.Contains(resultConfig.Roles[0].RoleType.ToString()));
                }
                else
                {
                    foreach (ExtensionRole role in resultConfig.Roles)
                    {
                        Assert.IsTrue(roles.Contains(role.RoleName));
                    }
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
        public ExtensionConfiguration InstallExtension(ExtensionConfigurationInput context, string slot, ExtensionConfiguration extConfig)
        {
            ExtensionConfigurationBuilder builder = GetBuilder(extConfig);
            foreach (ExtensionRole r in context.Roles)
            {
                string roleName = r.RoleType == ExtensionRoleType.AllRoles ? DefaultAllRolesNameStr : r.RoleName;

                var extensionIds = (from index in Enumerable.Range(0, ExtensionIdLiveCycleCount)
                                    select GetExtensionId(roleName, context.Type, slot, index)).ToList();

                string availableId = (from extensionId in extensionIds
                                      where !builder.ExistAny(extensionId)
                                      select extensionId).FirstOrDefault();

                var extensionList = (from id in extensionIds
                                     let e = GetExtension(id)
                                     where e != null
                                     select e).ToList();

                string thumbprint = context.CertificateThumbprint;
                string thumbprintAlgorithm = context.ThumbprintAlgorithm;

                if (context.X509Certificate != null)
                {
                    thumbprint = context.X509Certificate.Thumbprint;
                }
                else
                {
                    GetExtensionThumbprintAndAlgorithm(extensionList, availableId, ref thumbprint, ref thumbprintAlgorithm);
                }

                context.CertificateThumbprint = string.IsNullOrWhiteSpace(context.CertificateThumbprint) ? thumbprint : context.CertificateThumbprint;
                context.ThumbprintAlgorithm = string.IsNullOrWhiteSpace(context.ThumbprintAlgorithm) ? thumbprintAlgorithm : context.ThumbprintAlgorithm;

                if (!string.IsNullOrWhiteSpace(context.CertificateThumbprint) && string.IsNullOrWhiteSpace(context.ThumbprintAlgorithm))
                {
                    context.ThumbprintAlgorithm = ThumbprintAlgorithmStr;
                }

                var existingExtension = extensionList.Find(e => e.Id == availableId);
                if (existingExtension != null)
                {
                    DeleteExtension(availableId);
                }

                AddExtension(new HostedServiceExtensionInput
                {
                    Id = availableId,
                    Thumbprint = context.CertificateThumbprint,
                    ThumbprintAlgorithm = context.ThumbprintAlgorithm,
                    ProviderNameSpace = context.ProviderNameSpace,
                    Type = context.Type,
                    PublicConfiguration = context.PublicConfiguration,
                    PrivateConfiguration = context.PrivateConfiguration
                });

                if (r.RoleType == ExtensionRoleType.NamedRoles)
                {
                    builder.Remove(roleName, context.ProviderNameSpace, context.Type);
                    builder.Add(roleName, availableId);
                }
                else
                {
                    builder.RemoveDefault(context.ProviderNameSpace, context.Type);
                    builder.AddDefault(availableId);
                }
            }

            return builder.ToConfiguration();
        }
 public void ExecuteCommand()
 {
     ValidateParameters();
     ExtensionConfigurationInput context = new ExtensionConfigurationInput
     {
         ProviderNameSpace = ExtensionNameSpace,
         Type = ExtensionType,
         CertificateThumbprint = CertificateThumbprint,
         ThumbprintAlgorithm = ThumbprintAlgorithm,
         X509Certificate = X509Certificate,
         PublicConfiguration = PublicConfiguration,
         PrivateConfiguration = PrivateConfiguration,
         Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
     };
     var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);
     ChangeDeployment(extConfig);
 }
示例#11
0
        public ExtensionConfiguration InstallExtension(ExtensionConfigurationInput context, string slot, ExtensionConfiguration extConfig)
        {
            ExtensionConfigurationBuilder builder = GetBuilder(extConfig);

            foreach (ExtensionRole r in context.Roles)
            {
                var extensionIds = (from index in Enumerable.Range(0, ExtensionIdLiveCycleCount)
                                    select GetExtensionId(r.PrefixName, context.Type, slot, index)).ToList();

                string availableId = (from extensionId in extensionIds
                                      where !builder.ExistAny(extensionId)
                                      select extensionId).FirstOrDefault();

                var extensionList = (from id in extensionIds
                                     let e = GetExtension(id)
                                             where e != null
                                             select e).ToList();

                string thumbprint          = context.CertificateThumbprint;
                string thumbprintAlgorithm = context.ThumbprintAlgorithm;

                if (context.X509Certificate != null)
                {
                    thumbprint = context.X509Certificate.Thumbprint;
                }
                else
                {
                    GetThumbprintAndAlgorithm(extensionList, availableId, ref thumbprint, ref thumbprintAlgorithm);
                }

                context.CertificateThumbprint = string.IsNullOrWhiteSpace(context.CertificateThumbprint) ? thumbprint : context.CertificateThumbprint;
                context.ThumbprintAlgorithm   = string.IsNullOrWhiteSpace(context.ThumbprintAlgorithm) ? thumbprintAlgorithm : context.ThumbprintAlgorithm;

                if (!string.IsNullOrWhiteSpace(context.CertificateThumbprint) && string.IsNullOrWhiteSpace(context.ThumbprintAlgorithm))
                {
                    context.ThumbprintAlgorithm = ThumbprintAlgorithmStr;
                }
                else if (string.IsNullOrWhiteSpace(context.CertificateThumbprint) && !string.IsNullOrWhiteSpace(context.ThumbprintAlgorithm))
                {
                    context.ThumbprintAlgorithm = string.Empty;
                }

                var existingExtension = extensionList.Find(e => e.Id == availableId);
                if (existingExtension != null)
                {
                    DeleteExtension(availableId);
                }

                if (r.Default)
                {
                    Cmdlet.WriteVerbose(string.Format(Resources.ServiceExtensionSettingForDefaultRole, context.Type));
                }
                else
                {
                    Cmdlet.WriteVerbose(string.Format(Resources.ServiceExtensionSettingForSpecificRole, context.Type, r.RoleName));
                }

                AddExtension(new HostedServiceExtensionInput
                {
                    Id                   = availableId,
                    Thumbprint           = context.CertificateThumbprint,
                    ThumbprintAlgorithm  = context.ThumbprintAlgorithm,
                    ProviderNameSpace    = context.ProviderNameSpace,
                    Type                 = context.Type,
                    PublicConfiguration  = context.PublicConfiguration,
                    PrivateConfiguration = context.PrivateConfiguration
                });

                if (r.Default)
                {
                    builder.RemoveDefault(context.ProviderNameSpace, context.Type);
                    builder.AddDefault(availableId);
                }
                else
                {
                    builder.Remove(r.RoleName, context.ProviderNameSpace, context.Type);
                    builder.Add(r.RoleName, availableId);
                }
            }

            return(builder.ToConfiguration());
        }
 public void ExecuteCommand()
 {
     ValidateParameters();
     ExtensionConfigurationInput context = new ExtensionConfigurationInput
     {
         ProviderNameSpace = ExtensionNameSpace,
         Type = ExtensionType,
         CertificateThumbprint = CertificateThumbprint,
         ThumbprintAlgorithm = ThumbprintAlgorithm,
         X509Certificate = X509Certificate,
         PublicConfiguration = string.Format(PublicConfigurationXmlTemplate.ToString(), ConnectionQualifiers, DefaultEndpointsProtocol, StorageAccountName, DiagnosticsConfiguration != null ? DiagnosticsConfiguration.InnerXml : ""),
         PrivateConfiguration = string.Format(PrivateConfigurationXmlTemplate.ToString(), StorageKey),
         Roles = Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)).ToList() : new ExtensionRole[] { new ExtensionRole() }.ToList()
     };
     var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);
     ChangeDeployment(extConfig);
 }
 public void ExecuteCommand()
 {
     ValidateParameters();
     ExtensionConfigurationInput context = new ExtensionConfigurationInput
     {
         ProviderNameSpace = ExtensionNameSpace,
         Type = ExtensionType,
         CertificateThumbprint = CertificateThumbprint,
         ThumbprintAlgorithm = ThumbprintAlgorithm,
         X509Certificate = X509Certificate,
         PublicConfiguration = string.Format(PublicConfigurationXmlTemplate.ToString(), Credential.UserName, Expiration.ToString("yyyy-MM-dd")),
         PrivateConfiguration = string.Format(PrivateConfigurationXmlTemplate.ToString(), Credential.Password.ConvertToUnsecureString()),
         Roles = Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)).ToList() : new ExtensionRole[] { new ExtensionRole() }.ToList()
     };
     var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);
     ChangeDeployment(extConfig);
 }