private Hashtable GetAppSettingsToUpdate() { Hashtable appSettings = new Hashtable(); if (ContainerRegistryUrl != null) { appSettings[CmdletHelpers.DocerRegistryServerUrl] = ContainerRegistryUrl; } if (ContainerRegistryUser != null) { appSettings[CmdletHelpers.DocerRegistryServerUserName] = ContainerRegistryUser; } if (ContainerRegistryPassword != null) { appSettings[CmdletHelpers.DocerRegistryServerPassword] = ContainerRegistryPassword.ConvertToString(); } if (EnableContainerContinuousDeployment.IsPresent) { appSettings[CmdletHelpers.DockerEnableCI] = "true"; } return(appSettings); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); SiteConfig siteConfig = null; Site site = null; string location = null; IDictionary <string, string> tags = null; switch (ParameterSetName) { case ParameterSet1Name: WebApp = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, null)); location = WebApp.Location; tags = WebApp.Tags; var parameters = new HashSet <string>(MyInvocation.BoundParameters.Keys, StringComparer.OrdinalIgnoreCase); if (parameters.Any(p => CmdletHelpers.SiteConfigParameters.Contains(p))) { siteConfig = new SiteConfig { DefaultDocuments = parameters.Contains("DefaultDocuments") ? DefaultDocuments : null, NetFrameworkVersion = parameters.Contains("NetFrameworkVersion") ? NetFrameworkVersion : null, PhpVersion = parameters.Contains("PhpVersion") ? PhpVersion.ToLower() == "off" ? "" : PhpVersion : null, RequestTracingEnabled = parameters.Contains("RequestTracingEnabled") ? (bool?)RequestTracingEnabled : null, HttpLoggingEnabled = parameters.Contains("HttpLoggingEnabled") ? (bool?)HttpLoggingEnabled : null, DetailedErrorLoggingEnabled = parameters.Contains("DetailedErrorLoggingEnabled") ? (bool?)DetailedErrorLoggingEnabled : null, HandlerMappings = parameters.Contains("HandlerMappings") ? HandlerMappings : null, ManagedPipelineMode = parameters.Contains("ManagedPipelineMode") ? (ManagedPipelineMode?)Enum.Parse(typeof(ManagedPipelineMode), ManagedPipelineMode) : null, WebSocketsEnabled = parameters.Contains("WebSocketsEnabled") ? (bool?)WebSocketsEnabled : null, Use32BitWorkerProcess = parameters.Contains("Use32BitWorkerProcess") ? (bool?)Use32BitWorkerProcess : null, AutoSwapSlotName = parameters.Contains("AutoSwapSlotName") ? AutoSwapSlotName : null, NumberOfWorkers = parameters.Contains("NumberOfWorkers") ? NumberOfWorkers : WebApp.SiteConfig.NumberOfWorkers }; } Hashtable appSettings = AppSettings ?? new Hashtable(); if (siteConfig == null) { siteConfig = WebApp.SiteConfig; } //According to current implementation if AppSettings parameter is provided we are overriding existing AppSettings if (WebApp.SiteConfig.AppSettings != null && AppSettings == null) { foreach (var setting in WebApp.SiteConfig.AppSettings) { appSettings[setting.Name] = setting.Value; } } if (ContainerImageName != null) { string dockerImage = CmdletHelpers.DockerImagePrefix + ContainerImageName; if (WebApp.IsXenon.GetValueOrDefault()) { siteConfig.WindowsFxVersion = dockerImage; } else if (WebApp.Reserved.GetValueOrDefault()) { siteConfig.LinuxFxVersion = dockerImage; } } if (ContainerRegistryUrl != null) { appSettings[CmdletHelpers.DocerRegistryServerUrl] = ContainerRegistryUrl; } if (ContainerRegistryUser != null) { appSettings[CmdletHelpers.DocerRegistryServerUserName] = ContainerRegistryUser; } if (ContainerRegistryPassword != null) { appSettings[CmdletHelpers.DocerRegistryServerPassword] = ContainerRegistryPassword.ConvertToString(); } if (parameters.Contains("EnableContainerContinuousDeployment")) { if (EnableContainerContinuousDeployment) { appSettings[CmdletHelpers.DockerEnableCI] = "true"; } else { appSettings.Remove(CmdletHelpers.DockerEnableCI); } } // Update web app configuration WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, siteConfig, appSettings.ConvertToStringDictionary(), ConnectionStrings.ConvertToConnectionStringDictionary(), AzureStoragePath.ConvertToAzureStorageAccountPathPropertyDictionary()); //Update WebApp object after configuration update WebApp = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, null)); if (parameters.Any(p => CmdletHelpers.SiteParameters.Contains(p))) { site = new Site { Location = location, Tags = tags, ServerFarmId = WebApp.ServerFarmId, Identity = parameters.Contains("AssignIdentity") ? AssignIdentity ? new ManagedServiceIdentity("SystemAssigned", null, null) : new ManagedServiceIdentity("None", null, null) : WebApp.Identity, HttpsOnly = parameters.Contains("HttpsOnly") ? HttpsOnly : WebApp.HttpsOnly }; WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, WebApp.ServerFarmId, new PSSite(site)); } if (parameters.Contains("AppServicePlan")) { // AzureStorage path is not a part of the back end siteObject, but if the PSSite Object is given as an input, so simply set this to null WebApp.AzureStoragePath = null; WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, AppServicePlan, WebApp); } if (parameters.Contains("HostNames")) { WebsitesClient.AddCustomHostNames(ResourceGroupName, location, Name, HostNames); } break; case ParameterSet2Name: // Web app is direct or pipeline input string servicePlanName; string rg; location = WebApp.Location; siteConfig = WebApp.SiteConfig; // Update web app configuration WebsitesClient.UpdateWebAppConfiguration( ResourceGroupName, location, Name, null, siteConfig, WebApp.SiteConfig == null ? null : WebApp.SiteConfig .AppSettings .ToDictionary( nvp => nvp.Name, nvp => nvp.Value, StringComparer.OrdinalIgnoreCase), WebApp.SiteConfig?.ConnectionStrings .ToDictionary( nvp => nvp.Name, nvp => new ConnStringValueTypePair { Type = nvp.Type.Value, Value = nvp.ConnectionString }, StringComparer.OrdinalIgnoreCase)); CmdletHelpers.TryParseAppServicePlanMetadataFromResourceId(WebApp.ServerFarmId, out rg, out servicePlanName); // AzureStorage path is not a part of the back end siteObject, but if the PSSite Object is given as an input, we will some value for this WebApp.AzureStoragePath = null; WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, servicePlanName, WebApp); WebsitesClient.AddCustomHostNames(ResourceGroupName, location, Name, WebApp.HostNames.ToArray()); break; } WriteObject(new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, null))); }