diff --git a/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/CLI/CliTests.cs b/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/CLI/CliTests.cs index 0ae6778..8f1d764 100644 --- a/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/CLI/CliTests.cs +++ b/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/CLI/CliTests.cs @@ -17,7 +17,7 @@ public class CliTests : RenewalTestBase { ("-s", "--subscriptionId"), Subscription1.ToString() }, { ("-t", "--tenantId"), Tenant1 }, { ("-r", "--resourceGroup"), ResourceGroup1 }, - { ("-w", "--webApp"), WebApp1 }, + { ("-w", "--webApp"), WebApp1Name }, { ("-o", "--hosts"), String.Join(";", Hosts1) }, { ("-e", "--email"), Email1 }, { ("-c", "--clientId"), ClientId1.ToString() }, diff --git a/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/RenewalTestBase.cs b/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/RenewalTestBase.cs index c35f7d2..be6b672 100644 --- a/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/RenewalTestBase.cs +++ b/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/RenewalTestBase.cs @@ -17,7 +17,9 @@ public class RenewalTestBase protected const string ResourceGroup1 = "foo-resource-group"; protected const string ResourceGroup2 = "bar-resource-group"; protected const string ResourceGroupShared = "shared-resource-group"; - protected const string WebApp1 = "fooApp"; + protected const string SiteSlotName1 = "foo-slot"; + protected const string WebApp1Name = "fooApp"; + protected const string WebApp1 = WebApp1Name + "{" + SiteSlotName1 + "}"; protected const string WebApp2 = "barApp"; protected const string WebApp3 = "bazApp"; protected const string Email1 = "foo@gmail.com"; @@ -28,7 +30,6 @@ public class RenewalTestBase protected const string ClientSecretShared = "shared-secret4real"; protected const string ServicePlanResourceGroup1 = "foo-service-plan-resource-group"; protected const string ServicePlanResourceGroupShared = "shared-service-plan-resource-group"; - protected const string SiteSlotName1 = "foo-slot"; protected const bool UseIpBasedSsl1 = true; protected const bool UseIpBasedSslShared = true; protected const int RsaKeyLength1 = 1024; @@ -59,7 +60,7 @@ public class RenewalTestBase Subscription1, Tenant1, ResourceGroup1, - WebApp1, + WebApp1Name, Hosts1, Email1, ClientId1, @@ -79,7 +80,7 @@ public class RenewalTestBase Subscription1, Tenant1, ResourceGroup1, - WebApp1, + WebApp1Name, Hosts1, Email1, ClientId1, diff --git a/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/WebJob/AppSettingsTests.cs b/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/WebJob/AppSettingsTests.cs index 5977614..67dec79 100644 --- a/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/WebJob/AppSettingsTests.cs +++ b/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob.Tests/WebJob/AppSettingsTests.cs @@ -25,7 +25,6 @@ public class AppSettingsTests : RenewalTestBase private const string ClientIdKeySuffix = "clientId"; private const string ClientSecretKeySuffix = "clientSecret"; private const string ServicePlanResourceGroupKeySuffix = "servicePlanResourceGroup"; - private const string SiteSlotNameSuffix = "siteSlotName"; private const string UseIpBasedSslKeySuffix = "useIpBasedSsl"; private const string RsaKeyLengthKeySuffix = "rsaKeyLength"; private const string AcmeBaseUriKeySuffix = "acmeBaseUri"; @@ -52,7 +51,6 @@ public class AppSettingsTests : RenewalTestBase { BuildConfigKey(HostsKeySuffix, WebApp1), String.Join(";", Hosts1) }, { BuildConfigKey(EmailKeySuffix, WebApp1), Email1 }, { BuildConfigKey(ClientIdKeySuffix, WebApp1), ClientId1.ToString() }, // override shared - { BuildConfigKey(SiteSlotNameSuffix, WebApp1), SiteSlotName1 }, { BuildConfigKey(UseIpBasedSslKeySuffix, WebApp1), UseIpBasedSsl1.ToString() }, { BuildConfigKey(RsaKeyLengthKeySuffix, WebApp1), RsaKeyLength1.ToString(CultureInfo.InvariantCulture) }, { BuildConfigKey(AcmeBaseUriKeySuffix, WebApp1), AcmeBaseUri1.ToString() }, @@ -147,7 +145,16 @@ public void TestInvalidServicePlanResourceGroup() [TestMethod] public void TestInvalidSiteSlotName() { - AssertInvalidConfig(SiteSlotNameSuffix, WebApp2, " ", "siteSlotName", testMissing: false, testShared: false); + const string webApp = "foo{ }"; + + m_appSettings[BuildConfigKey(WebAppsKey)] = webApp; + m_appSettings[BuildConfigKey(SubscriptionIdKeySuffix, webApp)] = Subscription1.ToString(); + m_appSettings[BuildConfigKey(TenantIdKeySuffix, webApp)] = Tenant1; + m_appSettings[BuildConfigKey(ResourceGroupKeySuffix, webApp)] = ResourceGroup1; + m_appSettings[BuildConfigKey(HostsKeySuffix, webApp)] = String.Join(";", Hosts1); + m_appSettings[BuildConfigKey(EmailKeySuffix, webApp)] = Email1; + + AssertInvalidConfigCore("siteSlotName"); } [TestMethod] diff --git a/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob/AppSettings/AppSettingsRenewalParamsReader.cs b/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob/AppSettings/AppSettingsRenewalParamsReader.cs index 53c4098..4bb7271 100644 --- a/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob/AppSettings/AppSettingsRenewalParamsReader.cs +++ b/OhadSoft.AzureLetsEncrypt.Renewal/OhadSoft.AzureLetsEncrypt.Renewal.WebJob/AppSettings/AppSettingsRenewalParamsReader.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using OhadSoft.AzureLetsEncrypt.Renewal.Management; namespace OhadSoft.AzureLetsEncrypt.Renewal.WebJob.AppSettings @@ -61,19 +62,29 @@ private RenewalParameters GetWebAppRenewalInfo(string webApp, SharedRenewalParam { Trace.TraceInformation("Parsing SSL renewal parameters for web app '{0}'...", webApp); + string webAppName = webApp; + string siteSlotName = null; + + var match = Regex.Match(webApp, "^(.*){(.*)}$"); + if (match.Success) + { + webAppName = match.Groups[1].Value; + siteSlotName = match.Groups[2].Value; + } + try { return new RenewalParameters( ResolveGuidSetting(Constants.SubscriptionIdKey, webApp, sharedRenewalParams.SubscriptionId), ResolveSetting(Constants.TenantIdKey, webApp, sharedRenewalParams.TenantId), ResolveSetting(Constants.ResourceGroupKey, webApp, sharedRenewalParams.ResourceGroup), - webApp, + webAppName, m_appSettings.GetDelimitedList(BuildConfigKey(Constants.HostsKey, webApp)), ResolveSetting(Constants.EmailKey, webApp, sharedRenewalParams.Email), ResolveGuidSetting(Constants.ClientIdKey, webApp, sharedRenewalParams.ClientId), ResolveConnectionString(Constants.ClientSecretKey, webApp, sharedRenewalParams.ClientSecret), ResolveOptionalSetting(Constants.ServicePlanResourceGroupKey, webApp, sharedRenewalParams.ServicePlanResourceGroup), - ResolveOptionalSetting(Constants.SiteSlotNameKey, webApp), + siteSlotName, ResolveOptionalBooleanSetting(Constants.UseIpBasedSslKey, webApp, sharedRenewalParams.UseIpBasedSsl, false), ResolveOptionalInt32Setting(Constants.RsaKeyLengthKey, webApp, sharedRenewalParams.RsaKeyLength, 2048), ResolveOptionalUriSetting(Constants.AcmeBaseUriKey, webApp, sharedRenewalParams.AcmeBaseUri),