Skip to content

Commit

Permalink
Merge pull request #36 from ohadschn/multiple-deployment-slots
Browse files Browse the repository at this point in the history
Support multiple deployment slots (BREAKING CHANGE)
  • Loading branch information
ohadschn authored Dec 30, 2017
2 parents 97dc9c4 + e2418ac commit 3b952f6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class RenewalTestBase
Subscription1,
Tenant1,
ResourceGroup1,
WebApp1,
WebApp1Name,
Hosts1,
Email1,
ClientId1,
Expand All @@ -79,7 +80,7 @@ public class RenewalTestBase
Subscription1,
Tenant1,
ResourceGroup1,
WebApp1,
WebApp1Name,
Hosts1,
Email1,
ClientId1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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() },
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 3b952f6

Please sign in to comment.