public IWebAppBase SetConnectionString(IWebAppBase deployTarget, string connectionStringName, string connectionString) { _logger.LogInformation("Setting connection string..."); IWebAppBase web; if (deployTarget is IWebApp webApp) { web = ExecuteWithRetry(() => webApp.Update().WithConnectionString(connectionStringName, connectionString, Microsoft.Azure.Management.AppService.Fluent.Models.ConnectionStringType.Custom).Apply()); } else if (deployTarget is IDeploymentSlot slot) { web = ExecuteWithRetry(() => slot.Update().WithConnectionString(connectionStringName, connectionString, Microsoft.Azure.Management.AppService.Fluent.Models.ConnectionStringType.Custom).Apply()); } else { web = null; } var connStrings = ExecuteWithRetry(() => web?.GetConnectionStrings()); if (connStrings == null || !connStrings.ContainsKey(connectionStringName)) { throw new Exception("Failed setting connection string. Please check for the user permission"); } return(web); }
public static void Print(IWebAppBase resource) { var builder = new StringBuilder().Append("Web app: ").Append(resource.Id) .Append("Name: ").Append(resource.Name) .Append("\n\tState: ").Append(resource.State) .Append("\n\tResource group: ").Append(resource.ResourceGroupName) .Append("\n\tRegion: ").Append(resource.Region) .Append("\n\tDefault hostname: ").Append(resource.DefaultHostName) .Append("\n\tApp service plan: ").Append(resource.AppServicePlanId) .Append("\n\tHost name bindings: "); foreach (var binding in resource.GetHostNameBindings().Values) { builder = builder.Append("\n\t\t" + binding.ToString()); } builder = builder.Append("\n\tSSL bindings: "); foreach (var binding in resource.HostNameSslStates.Values) { builder = builder.Append("\n\t\t" + binding.Name + ": " + binding.SslState); if (binding.SslState != null && binding.SslState != SslState.Disabled) { builder = builder.Append(" - " + binding.Thumbprint); } } builder = builder.Append("\n\tApp settings: "); foreach (var setting in resource.GetAppSettings().Values) { builder = builder.Append("\n\t\t" + setting.Key + ": " + setting.Value + (setting.Sticky ? " - slot setting" : "")); } builder = builder.Append("\n\tConnection strings: "); foreach (var conn in resource.GetConnectionStrings().Values) { builder = builder.Append("\n\t\t" + conn.Name + ": " + conn.Value + " - " + conn.Type + (conn.Sticky ? " - slot setting" : "")); } Utilities.Log(builder.ToString()); }
///GENMHASH:81C5A75C912A5059487CAA454304B8FC:E174ECD1F459D4BCFB76BF0692F555C9 public FluentImplT WithConfigurationFromDeploymentSlot(FluentT slot) { this.SiteConfig = ((WebAppBaseImpl <FluentT, FluentImplT, DefAfterRegionT, DefAfterGroupT, UpdateT>)(IWebAppBase) slot).SiteConfig; configurationSource = slot; return((FluentImplT)this); }
public async Task Install(ICertificateInstallModel model) { logger.LogInformation("Starting installation of certificate {Thumbprint} for {Host}", model.CertificateInfo.Certificate.Thumbprint, model.Host); var cert = model.CertificateInfo; foreach (var setting in this.settings) { logger.LogInformation("Installing certificate for web app {WebApp}", setting.WebAppName); try { IAppServiceManager appServiceManager = GetAppServiceManager(setting); var s = appServiceManager.WebApps.GetByResourceGroup(setting.ResourceGroupName, setting.WebAppName); IWebAppBase siteOrSlot = s; if (!string.IsNullOrEmpty(setting.SiteSlotName)) { var slot = s.DeploymentSlots.GetByName(setting.SiteSlotName); siteOrSlot = slot; } var existingCerts = await appServiceManager.AppServiceCertificates.ListByResourceGroupAsync(setting.ServicePlanResourceGroupName ?? setting.ResourceGroupName); if (existingCerts.Where(_ => _.RegionName == s.RegionName).All(_ => _.Thumbprint != cert.Certificate.Thumbprint)) { await appServiceManager.AppServiceCertificates.Define($"{cert.Certificate.Thumbprint}-{model.Host}-{s.RegionName}").WithRegion(s.RegionName).WithExistingResourceGroup(setting.ServicePlanResourceGroupName ?? setting.ResourceGroupName).WithPfxByteArray(model.CertificateInfo.PfxCertificate).WithPfxPassword(model.CertificateInfo.Password).CreateAsync(); } var sslStates = siteOrSlot.HostNameSslStates; var domainSslMappings = new List <KeyValuePair <string, HostNameSslState> >(sslStates.Where(_ => _.Key.Contains($"{model.Host}"))); if (domainSslMappings.Any()) { foreach (var domainMapping in domainSslMappings) { string hostName = domainMapping.Value.Name; if (domainMapping.Value.Thumbprint == cert.Certificate.Thumbprint) { continue; } logger.LogInformation("Binding certificate {Thumbprint} to {Host}", model.CertificateInfo.Certificate.Thumbprint, hostName); var binding = new HostNameBindingInner() { SslState = setting.UseIPBasedSSL ? SslState.IpBasedEnabled : SslState.SniEnabled, Thumbprint = model.CertificateInfo.Certificate.Thumbprint }; if (!string.IsNullOrEmpty(setting.SiteSlotName)) { await appServiceManager.Inner.WebApps.CreateOrUpdateHostNameBindingSlotAsync(setting.ResourceGroupName, setting.WebAppName, hostName, binding, setting.SiteSlotName); } else { await appServiceManager.Inner.WebApps.CreateOrUpdateHostNameBindingAsync(setting.ResourceGroupName, setting.WebAppName, hostName, binding); } } } } catch (Exception e) { logger.LogCritical(e, "Unable to install certificate for '{WebApp}'", setting.WebAppName); throw; } } }
/// <summary> /// Specifies the web app to verify the ownership of the domain. The web app needs to /// be bound to the hostname for the certificate. /// </summary> /// <param name="webApp">The web app bound to the hostname.</param> /// <return>The next stage of the definition.</return> AppServiceCertificateOrder.Definition.IWithKeyVault AppServiceCertificateOrder.Definition.IWithDomainVerificationFromWebApp.WithWebAppVerification(IWebAppBase webApp) { return(this.WithWebAppVerification(webApp) as AppServiceCertificateOrder.Definition.IWithKeyVault); }
public IPublishingProfile GetPublishingProfile(IWebAppBase deployTarget) { return(ExecuteWithRetry(() => deployTarget.GetPublishingProfile())); }
internal KuduClient(IWebAppBase webAppBase) { this.webAppBase = webAppBase; }
internal WebAppIdProvider(IWebAppBase webApp) { this.webApp = webApp; }
///GENMHASH:998ED679562660847C6B644CE156D46C:BD8EDAEE21E0A80A3794CA1BF6C8293A public AppServiceCertificateOrderImpl WithWebAppVerification(IWebAppBase webApp) { this.domainVerifyWebApp = webApp; return(this); }