diff --git a/LetsEncrypt-SiteExtension/Controllers/HomeController.cs b/LetsEncrypt-SiteExtension/Controllers/HomeController.cs index 70097e8..597494b 100644 --- a/LetsEncrypt-SiteExtension/Controllers/HomeController.cs +++ b/LetsEncrypt-SiteExtension/Controllers/HomeController.cs @@ -62,6 +62,7 @@ public async Task Index(AuthenticationModel model) return View(model); } var webappsettings = client.WebApps.ListSiteOrSlotAppSettings(model.ResourceGroupName, model.WebAppName, model.SiteSlotName); + var connectionStrings = client.WebApps.ListConnectionStrings(model.ResourceGroupName, model.WebAppName); if (model.UpdateAppSettings) { var newAppSettingsValues = new Dictionary{ @@ -74,6 +75,13 @@ public async Task Index(AuthenticationModel model) { AppSettingsAuthConfig.servicePlanResourceGroupNameKey, model.ServicePlanResourceGroupName }, { AppSettingsAuthConfig.useIPBasedSSL, model.UseIPBasedSSL.ToString().ToLowerInvariant() } }; + + var newConnectionStrings = new Dictionary + { + { AppSettingsAuthConfig.webjobDashboard, model.DashboardConnectionString }, + { AppSettingsAuthConfig.webjobStorage, model.StorageConnectionString } + }; + foreach (var appsetting in newAppSettingsValues) { if (!webappsettings.Properties.ContainsKey(appsetting.Key)) @@ -86,8 +94,22 @@ public async Task Index(AuthenticationModel model) } } + foreach (var connString in newConnectionStrings) + { + if (!connectionStrings.Properties.ContainsKey(connString.Key)) + { + connectionStrings.Properties.Add(connString.Key, new ConnStringValueTypePair(connString.Value, ConnectionStringType.Custom)); + } + else + { + connectionStrings.Properties[connString.Key] = new ConnStringValueTypePair(connString.Value, ConnectionStringType.Custom); + } + } + client.WebApps.UpdateSiteOrSlotAppSettings(model.ResourceGroupName, model.WebAppName, model.SiteSlotName, webappsettings); + client.WebApps.UpdateConnectionStrings(model.ResourceGroupName, model.WebAppName, connectionStrings); ConfigurationManager.RefreshSection("appSettings"); + ConfigurationManager.RefreshSection("connectionStrings"); await path.ChallengeDirectory(true); } diff --git a/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs b/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs index 3ace706..47aa2f2 100644 --- a/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs +++ b/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs @@ -46,6 +46,18 @@ public bool UseIPBasedSSL get; set; } + [Required] + public string DashboardConnectionString + { + get; set; + } + + [Required] + public string StorageConnectionString + { + get; set; + } + [Display(Name = "Update Application Settings and Virtual Directory (if needed)")] public bool UpdateAppSettings { @@ -113,6 +125,8 @@ public static explicit operator AuthenticationModel(AppSettingsAuthConfig config SiteSlotName = config.SiteSlotName, WebRootPath = config.WebRootPath, RunFromPackage = config.RunFromPackage, + DashboardConnectionString = config.DashboardConnectionString, + StorageConnectionString = config.StorageConnectionString, }; } } diff --git a/LetsEncrypt-SiteExtension/Views/Home/Index.cshtml b/LetsEncrypt-SiteExtension/Views/Home/Index.cshtml index f80193c..22c8ca4 100644 --- a/LetsEncrypt-SiteExtension/Views/Home/Index.cshtml +++ b/LetsEncrypt-SiteExtension/Views/Home/Index.cshtml @@ -113,21 +113,21 @@ @if (Model.RunFromPackage && string.IsNullOrEmpty(Environment.GetEnvironmentVariable(LetsEncrypt.Azure.Core.Models.AppSettingsAuthConfig.webRootPath))) { - } @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @{ - var authModel = (Model as LetsEncrypt.SiteExtension.Models.AuthenticationModel); + var authModel = (Model as LetsEncrypt.SiteExtension.Models.AuthenticationModel); } @if (authModel != null && authModel.Error) { - + }
@Html.LabelFor(model => model.Tenant, htmlAttributes: new { @class = "control-label col-md-2" }) @@ -198,6 +198,20 @@ @Html.ValidationMessageFor(model => model.SiteSlotName, "", new { @class = "text-danger" })
+
+ @Html.LabelFor(model => model.DashboardConnectionString, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.DashboardConnectionString, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.DashboardConnectionString, "", new { @class = "text-danger" }) +
+
+
+ @Html.LabelFor(model => model.StorageConnectionString, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.StorageConnectionString, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.StorageConnectionString, "", new { @class = "text-danger" }) +
+
@Html.LabelFor(model => model.UpdateAppSettings, htmlAttributes: new { @class = "control-label col-md-2" })
diff --git a/LetsEncrypt.SiteExtension.Core/AppSettingsAuthConfig.cs b/LetsEncrypt.SiteExtension.Core/AppSettingsAuthConfig.cs index d07d0ac..e47121d 100644 --- a/LetsEncrypt.SiteExtension.Core/AppSettingsAuthConfig.cs +++ b/LetsEncrypt.SiteExtension.Core/AppSettingsAuthConfig.cs @@ -35,6 +35,8 @@ public class AppSettingsAuthConfig : IAzureWebAppEnvironment, IAcmeConfig public const string authorizationChallengeBlobStorageAccount = "letsencrypt:AuthorizationChallengeBlobStorageAccount"; public const string authorizationChallengeBlobStorageContainer = "letsencrypt:AuthorizationChallengeBlobStorageContainer"; public const string disableVirtualApplication = "letsencrypt:DisableVirtualApplication"; + public const string webjobDashboard = "AzureWebJobsDashboard"; + public const string webjobStorage = "AzureWebJobsStorage"; public AppSettingsAuthConfig() { @@ -109,6 +111,24 @@ public string WebAppName } } + [Required(ErrorMessage = webjobDashboard + " connectionString is required")] + public string DashboardConnectionString + { + get + { + return ConfigurationManager.ConnectionStrings[webjobDashboard].ConnectionString; + } + } + + [Required(ErrorMessage = webjobStorage + " connectionString is required")] + public string StorageConnectionString + { + get + { + return ConfigurationManager.ConnectionStrings[webjobStorage].ConnectionString; + } + } + public string WebRootPath { get