From 3419532a9bf093a818356df3f470f8e5612766ec Mon Sep 17 00:00:00 2001 From: Jeroen Vantroyen Date: Wed, 28 Jul 2021 15:52:33 +0200 Subject: [PATCH] Add extra setting (TipSlotName) which holds the name of the slot that is currently serving when using Testing-in-Production --- .../Controllers/HomeController.cs | 2 ++ .../Models/AuthenticationModel.cs | 5 +++++ LetsEncrypt-SiteExtension/Views/Home/Index.cshtml | 11 +++++++++++ .../AppSettingsAuthConfig.cs | 9 +++++++++ LetsEncrypt.SiteExtension.Core/IAzureEnvironment.cs | 12 +++++++++++- LetsEncrypt.SiteExtension.Core/KuduHelper.cs | 4 ++-- 6 files changed, 40 insertions(+), 3 deletions(-) diff --git a/LetsEncrypt-SiteExtension/Controllers/HomeController.cs b/LetsEncrypt-SiteExtension/Controllers/HomeController.cs index 597494b..fa44dd0 100644 --- a/LetsEncrypt-SiteExtension/Controllers/HomeController.cs +++ b/LetsEncrypt-SiteExtension/Controllers/HomeController.cs @@ -71,6 +71,7 @@ public async Task Index(AuthenticationModel model) { AppSettingsAuthConfig.subscriptionIdKey, model.SubscriptionId.ToString() }, { AppSettingsAuthConfig.tenantKey, model.Tenant }, { AppSettingsAuthConfig.resourceGroupNameKey, model.ResourceGroupName }, + { AppSettingsAuthConfig.tipSlotNameKey, model.TipSlotName}, { AppSettingsAuthConfig.siteSlotNameKey, model.SiteSlotName}, { AppSettingsAuthConfig.servicePlanResourceGroupNameKey, model.ServicePlanResourceGroupName }, { AppSettingsAuthConfig.useIPBasedSSL, model.UseIPBasedSSL.ToString().ToLowerInvariant() } @@ -121,6 +122,7 @@ public async Task Index(AuthenticationModel model) !ValidateModelVsAppSettings("ResourceGroupName", appSetting.ResourceGroupName, model.ResourceGroupName) || !ValidateModelVsAppSettings("SubScriptionId", appSetting.SubscriptionId.ToString(), model.SubscriptionId.ToString()) || !ValidateModelVsAppSettings("Tenant", appSetting.Tenant, model.Tenant) || + !ValidateModelVsAppSettings("TipSlotName", appSetting.TipSlotName, model.TipSlotName) || !ValidateModelVsAppSettings("SiteSlotName", appSetting.SiteSlotName, model.SiteSlotName) || !ValidateModelVsAppSettings("ServicePlanResourceGroupName", appSetting.ServicePlanResourceGroupName, model.ServicePlanResourceGroupName) || !ValidateModelVsAppSettings("UseIPBasedSSL", appSetting.UseIPBasedSSL.ToString().ToLowerInvariant(), model.UseIPBasedSSL.ToString().ToLowerInvariant())) diff --git a/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs b/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs index 47aa2f2..3a586f4 100644 --- a/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs +++ b/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs @@ -35,6 +35,10 @@ public string WebAppName { get; set; } + public string TipSlotName + { + get; set; + } public string SiteSlotName { get; set; @@ -122,6 +126,7 @@ public static explicit operator AuthenticationModel(AppSettingsAuthConfig config AzureWebSitesDefaultDomainName = config.AzureWebSitesDefaultDomainName, ManagementEndpoint = config.ManagementEndpoint, TokenAudience = config.TokenAudience, + TipSlotName = config.TipSlotName, SiteSlotName = config.SiteSlotName, WebRootPath = config.WebRootPath, RunFromPackage = config.RunFromPackage, diff --git a/LetsEncrypt-SiteExtension/Views/Home/Index.cshtml b/LetsEncrypt-SiteExtension/Views/Home/Index.cshtml index 22c8ca4..cfdab50 100644 --- a/LetsEncrypt-SiteExtension/Views/Home/Index.cshtml +++ b/LetsEncrypt-SiteExtension/Views/Home/Index.cshtml @@ -48,6 +48,10 @@ @LetsEncrypt.Azure.Core.Models.AppSettingsAuthConfig.useIPBasedSSL Check this if you want the certificate to be bound to the WebApps' IP address instead of using SNI. With IP based SSL additional costs might be charged. + + @LetsEncrypt.Azure.Core.Models.AppSettingsAuthConfig.tipSlotNameKey + (Optional) Use this setting if you are using Testing-In-Production and you are currently serving from a deployment slot. The value should be the name of the slot (and the extension should be installed in PRODUCTION kudu portal) + @LetsEncrypt.Azure.Core.Models.AppSettingsAuthConfig.siteSlotNameKey (Optional) Use this setting if you want to use the extension to setup SSL certificate for deployment slots, the value should be the name of the slot (and the extension should be installed in that slots kudu portal) @@ -191,6 +195,13 @@ @Html.ValidationMessageFor(model => model.WebAppName, "", new { @class = "text-danger" }) +
+ @Html.LabelFor(model => model.TipSlotName, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.TipSlotName, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.TipSlotName, "", new { @class = "text-danger" }) +
+
@Html.LabelFor(model => model.SiteSlotName, htmlAttributes: new { @class = "control-label col-md-2" })
diff --git a/LetsEncrypt.SiteExtension.Core/AppSettingsAuthConfig.cs b/LetsEncrypt.SiteExtension.Core/AppSettingsAuthConfig.cs index b3cfa65..7688630 100644 --- a/LetsEncrypt.SiteExtension.Core/AppSettingsAuthConfig.cs +++ b/LetsEncrypt.SiteExtension.Core/AppSettingsAuthConfig.cs @@ -19,6 +19,7 @@ public class AppSettingsAuthConfig : IAzureWebAppEnvironment, IAcmeConfig public const string useIPBasedSSL = "letsencrypt:UseIPBasedSSL"; public const string emailKey = "letsencrypt:Email"; public const string acmeBaseUriKey = "letsencrypt:AcmeBaseUri"; + public const string tipSlotNameKey = "letsencrypt:TipSlot"; public const string siteSlotNameKey = "letsencrypt:SiteSlot"; public const string webAppNameKey = "WEBSITE_SITE_NAME"; public const string webRootPath = "letsencrypt:WebRootPath"; @@ -137,6 +138,14 @@ public string WebRootPath } } + public string TipSlotName + { + get + { + return ConfigurationManager.AppSettings[tipSlotNameKey]; + } + } + public string SiteSlotName { get diff --git a/LetsEncrypt.SiteExtension.Core/IAzureEnvironment.cs b/LetsEncrypt.SiteExtension.Core/IAzureEnvironment.cs index de6f064..8060a6a 100644 --- a/LetsEncrypt.SiteExtension.Core/IAzureEnvironment.cs +++ b/LetsEncrypt.SiteExtension.Core/IAzureEnvironment.cs @@ -27,6 +27,8 @@ public interface IAzureWebAppEnvironment : IAzureEnvironment string ServicePlanResourceGroupName { get; } + string TipSlotName { get; } + string SiteSlotName { get; } string AzureWebSitesDefaultDomainName { get; } @@ -179,7 +181,15 @@ public string ServicePlanResourceGroupName _servicePlanResourceGroupName = value; } } - + + /// + /// The site slot where the challenge file is installed. Only required if multiple slots are used with testing-in-Production. + /// + public string TipSlotName + { + get; set; + } + /// /// The site slot to install the certificate on. Only required if multiple slots is used. /// diff --git a/LetsEncrypt.SiteExtension.Core/KuduHelper.cs b/LetsEncrypt.SiteExtension.Core/KuduHelper.cs index 70a60dd..1ed61f7 100644 --- a/LetsEncrypt.SiteExtension.Core/KuduHelper.cs +++ b/LetsEncrypt.SiteExtension.Core/KuduHelper.cs @@ -8,8 +8,8 @@ public static class KuduHelper { public static KuduRestClient GetKuduClient(this WebSiteManagementClient client, IAzureWebAppEnvironment settings) { - var user = client.WebApps.GetPublsihingCredentialSiteOrSlot(settings.ResourceGroupName, settings.WebAppName, settings.SiteSlotName); - var site = client.WebApps.GetSiteOrSlot(settings.ResourceGroupName, settings.WebAppName, settings.SiteSlotName); + var user = client.WebApps.GetPublsihingCredentialSiteOrSlot(settings.ResourceGroupName, settings.WebAppName, settings.TipSlotName); + var site = client.WebApps.GetSiteOrSlot(settings.ResourceGroupName, settings.WebAppName, settings.TipSlotName); var defaultHostName = site.DefaultHostName; return new KuduRestClient(MakeScmUri(defaultHostName,settings), user.PublishingUserName, user.PublishingPassword);