Skip to content

Commit f7a40ed

Browse files
committed
1 parent a99eb68 commit f7a40ed

File tree

6 files changed

+42
-6
lines changed

6 files changed

+42
-6
lines changed

LetsEncrypt-SiteExtension/Controllers/HomeController.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ public async Task<ActionResult> Index(AuthenticationModel model)
4949
ModelState.AddModelError("ServicePlanResourceGroupName", string.Format("The Service Plan Resource Group registered on the Web App in Azure in the ServerFarmId property '{0}' does not match the value you entered here {1}", azureServerFarmResourceGroup, model.ServicePlanResourceGroupName));
5050
return View(model);
5151
}
52+
var appServicePlan = client.AppServicePlans.Get(model.ServicePlanResourceGroupName, site.ServerFarmName());
53+
if (appServicePlan.Sku.Tier.Equals("Free") || appServicePlan.Sku.Tier.Equals("Shared"))
54+
{
55+
ModelState.AddModelError("ServicePlanResourceGroupName", $"The Service Plan is using the {appServicePlan.Sku.Tier} which doesn't support SSL certificates");
56+
return View(model);
57+
}
58+
var path = new PathProvider(model);
59+
if (model.RunFromPackage && !await path.IsVirtualDirectorySetup() && !model.UpdateAppSettings)
60+
{
61+
ModelState.AddModelError("UpdateAppSettings", string.Format("The site is using Run From Package. You need to to allow the site-extension to update app settings to setup the virtual directory."));
62+
return View(model);
63+
}
5264
var webappsettings = client.WebApps.ListSiteOrSlotAppSettings(model.ResourceGroupName, model.WebAppName, model.SiteSlotName);
5365
if (model.UpdateAppSettings)
5466
{
@@ -76,7 +88,7 @@ public async Task<ActionResult> Index(AuthenticationModel model)
7688

7789
client.WebApps.UpdateSiteOrSlotAppSettings(model.ResourceGroupName, model.WebAppName, model.SiteSlotName, webappsettings);
7890
ConfigurationManager.RefreshSection("appSettings");
79-
var path = new PathProvider(model);
91+
8092
await path.ChallengeDirectory(true);
8193
}
8294
else

LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public bool UseIPBasedSSL
4646
get; set;
4747
}
4848

49-
[Display(Name = "Update Application Settings and Virtual Application (if needed)")]
49+
[Display(Name = "Update Application Settings and Virtual Directory (if needed)")]
5050
public bool UpdateAppSettings
5151
{
5252
get;set;

LetsEncrypt-SiteExtension/Views/Home/Index.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
@if (Model.RunFromPackage && string.IsNullOrEmpty(Environment.GetEnvironmentVariable(LetsEncrypt.Azure.Core.Models.AppSettingsAuthConfig.webRootPath)))
115115
{
116116
<div class="alert alert-warning" role="alert">
117-
<p>Web Site was deployed using "Run From Package", the site extension will have to configure a virtual application to ensure the challenge file can be browsable at http://your-site/.well-known/acme-challenge. </p>
117+
<p>Web Site was deployed using "Run From Package", the site extension will have to configure a virtual directory to ensure the challenge file can be browsable at http://your-site/.well-known/acme-challenge. </p>
118118
119119
<p>If you already host content under /.well-known then you should not continue, instead you should follow the manual setup procedure at <a href="https://github.com/sjkp/letsencrypt-siteextension/wiki/Run-From-Package">https://github.com/sjkp/letsencrypt-siteextension/wiki/Run-From-Package</a></p>
120120
</div>

LetsEncrypt.SiteExtension.Core/Services/PathProvider.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ private async Task EnsureVirtualDirectorySetup()
6363
{
6464
var siteConfig = client.WebApps.GetSiteConfigurationOrSlot(azureEnvironment.ResourceGroupName, azureEnvironment.WebAppName, azureEnvironment.SiteSlotName);
6565

66-
if (IsVirtualDirectorySetup(siteConfig))
66+
if (!IsVirtualDirectorySetup(siteConfig))
6767
{
68-
siteConfig.VirtualApplications.First().VirtualDirectories.Add(new VirtualDirectory()
68+
var app = siteConfig.VirtualApplications.First();
69+
if (app.VirtualDirectories == null)
70+
{
71+
app.VirtualDirectories = new List<VirtualDirectory>();
72+
}
73+
app.VirtualDirectories.Add(new VirtualDirectory()
6974
{
7075
PhysicalPath = wellKnownPhysicalPath,
7176
VirtualPath = "/.well-known",
@@ -89,7 +94,7 @@ public async Task<bool> IsVirtualDirectorySetup()
8994
private bool IsVirtualDirectorySetup(SiteConfigResource siteConfig)
9095
{
9196
var isSetupAsAppliction = siteConfig.VirtualApplications.Any(s => s.PhysicalPath.StartsWith(wellKnownPhysicalPath));
92-
var isSetupAsDirectory = siteConfig.VirtualApplications.Any(s => s.VirtualDirectories.Any(d => d.PhysicalPath.StartsWith(wellKnownPhysicalPath)));
97+
var isSetupAsDirectory = siteConfig.VirtualApplications.Any(s => s.VirtualDirectories?.Any(d => d.PhysicalPath.StartsWith(wellKnownPhysicalPath)) ?? false);
9398

9499
return isSetupAsAppliction || isSetupAsDirectory;
95100
}

LetsEncrypt.SiteExtension.Core/WebSiteManagementExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,15 @@ public static string ServerResourceGroupFromServerFarmId(string serverFarmId)
2121
var m = r.Match(serverFarmId);
2222
return m.Groups[1].Value;
2323
}
24+
25+
public static string ServerFarmName(this Site site)
26+
{
27+
return ServerFarmNameFromServerFarmId(site.ServerFarmId);
28+
}
29+
30+
public static string ServerFarmNameFromServerFarmId(string serverFarmId)
31+
{
32+
return serverFarmId.Split(new[] { '/' }).Last();
33+
}
2434
}
2535
}

LetsEncrypt.SiteExtension.Test/WebSiteManagementClientExtensionsTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,14 @@ public void ServerFarmResourceGroup()
2020

2121
Assert.AreEqual("LetsEncrypt-SiteExtension", res);
2222
}
23+
24+
[TestMethod]
25+
public void ServerFarmName()
26+
{
27+
var serverFarmId = "/subscriptions/3f09c367-93e0-4b61-bbe5-dcb5c686bf8a/resourceGroups/LetsEncrypt-SiteExtension/providers/Microsoft.Web/serverfarms/sjkp.testplan";
28+
var res = WebSiteManagementClientExtensions.ServerFarmNameFromServerFarmId(serverFarmId);
29+
30+
Assert.AreEqual("sjkp.testplan", res);
31+
}
2332
}
2433
}

0 commit comments

Comments
 (0)