Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkp committed Jan 7, 2019
2 parents d405970 + bb314ba commit 3e4a814
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
8 changes: 7 additions & 1 deletion LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public Uri AuthenticationEndpoint
get;set;
}

public string WebRootPath
{
get; set;
}

public static explicit operator AuthenticationModel(AppSettingsAuthConfig config)
{
return new AuthenticationModel()
Expand All @@ -103,7 +108,8 @@ public static explicit operator AuthenticationModel(AppSettingsAuthConfig config
AzureWebSitesDefaultDomainName = config.AzureWebSitesDefaultDomainName,
ManagementEndpoint = config.ManagementEndpoint,
TokenAudience = config.TokenAudience,
SiteSlotName = config.SiteSlotName
SiteSlotName = config.SiteSlotName,
WebRootPath = config.WebRootPath
};
}
}
Expand Down
9 changes: 9 additions & 0 deletions LetsEncrypt.SiteExtension.Core/AppSettingsAuthConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class AppSettingsAuthConfig : IAzureWebAppEnvironment, IAcmeConfig
public const string acmeBaseUriKey = "letsencrypt:AcmeBaseUri";
public const string siteSlotNameKey = "letsencrypt:SiteSlot";
public const string webAppNameKey = "WEBSITE_SITE_NAME";
public const string webRootPath = "letsencrypt:WebRootPath";
public const string servicePlanResourceGroupNameKey = "letsencrypt:ServicePlanResourceGroupName";
public const string rsaKeyLengthKey = "letsencrypt:RSAKeyLength";
private readonly WebAppEnviromentVariables environemntVariables;
Expand Down Expand Up @@ -107,6 +108,14 @@ public string WebAppName
}
}

public string WebRootPath
{
get
{
return ConfigurationManager.AppSettings[webRootPath];
}
}

public string SiteSlotName
{
get
Expand Down
13 changes: 11 additions & 2 deletions LetsEncrypt.SiteExtension.Core/IAzureEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IAzureWebAppEnvironment : IAzureEnvironment

string AzureWebSitesDefaultDomainName { get; }


string WebRootPath { get; }
}

public interface IAzureDnsEnvironment : IAzureEnvironment
Expand Down Expand Up @@ -142,10 +142,11 @@ public AzureDnsEnvironment(string tenant, Guid subscription, Guid clientId, stri
/// </summary>
public class AzureWebAppEnvironment : AzureEnvironment, IAzureWebAppEnvironment
{
public AzureWebAppEnvironment(string tenant, Guid subscription, Guid clientId, string clientSecret, string resourceGroup, string webAppName, string servicePlanResourceGroupName = null, string siteSlotName = null)
public AzureWebAppEnvironment(string tenant, Guid subscription, Guid clientId, string clientSecret, string resourceGroup, string webAppName, string servicePlanResourceGroupName = null, string siteSlotName = null, string webrootPath = null)
: base(tenant, subscription, clientId, clientSecret, resourceGroup)
{
this.WebAppName = webAppName;
this.WebRootPath = webrootPath;
this.ServicePlanResourceGroupName = string.IsNullOrEmpty(servicePlanResourceGroupName) ? resourceGroup : servicePlanResourceGroupName;
this.SiteSlotName = siteSlotName;
}
Expand Down Expand Up @@ -193,5 +194,13 @@ public string WebAppName
{
get; set;
}

/// <summary>
/// The path to the web root.
/// </summary>
public string WebRootPath
{
get; set;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ public class KuduFileSystemAuthorizationChallengeProvider : BaseHttpAuthorizatio
{
private readonly KuduRestClient kuduClient;
private readonly IAuthorizationChallengeProviderConfig config;
private readonly IAzureWebAppEnvironment azureEnvironment;

public KuduFileSystemAuthorizationChallengeProvider(IAzureWebAppEnvironment azureEnvironment, IAuthorizationChallengeProviderConfig config)
{
this.config = config;
var website = ArmHelper.GetWebSiteManagementClient(azureEnvironment);
this.kuduClient = KuduHelper.GetKuduClient(website, azureEnvironment);
this.azureEnvironment = azureEnvironment;
}

public override Task CleanupChallengeFile(HttpChallenge challenge)
{
return Task.CompletedTask;
Expand Down Expand Up @@ -55,7 +58,7 @@ private async Task WriteFile(string answerPath, string content)
}
}

private static string GetAnswerPath(HttpChallenge httpChallenge)
private string GetAnswerPath(HttpChallenge httpChallenge)
{
// We need to strip off any leading '/' in the path
var filePath = httpChallenge.FilePath;
Expand All @@ -65,14 +68,13 @@ private static string GetAnswerPath(HttpChallenge httpChallenge)
return answerPath;
}

private static string WebRootPath()
private string WebRootPath()
{

var webrootPath = ConfigurationManager.AppSettings["letsencrypt:WebRootPath"];
if (string.IsNullOrEmpty(webrootPath))
if (string.IsNullOrEmpty(azureEnvironment.WebRootPath))
return "site/wwwroot";
//Ensure this is a backwards compatible with the LocalFileSystemProvider that was the only option before
return webrootPath.Replace(Environment.ExpandEnvironmentVariables("%HOME%"), "").Replace('\\', '/');
return azureEnvironment.WebRootPath.Replace(Environment.ExpandEnvironmentVariables("%HOME%"), "").Replace('\\', '/');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public LocalFileSystemAuthorizationChallengeProvider(IAzureWebAppEnvironment azu



private static string WebRootPath()
private string WebRootPath()
{
return ConfigurationManager.AppSettings["letsencrypt:WebRootPath"] ?? Path.Combine(Environment.ExpandEnvironmentVariables("%HOME%"), "site", "wwwroot");
return azureEnvironment.WebRootPath ?? Path.Combine(Environment.ExpandEnvironmentVariables("%HOME%"), "site", "wwwroot");
}

private string ChallengeDirectory
Expand Down Expand Up @@ -84,7 +84,7 @@ public override Task PersistsChallengeFile(HttpChallenge httpChallenge)
return Task.CompletedTask;
}

private static string GetAnswerPath(HttpChallenge httpChallenge)
private string GetAnswerPath(HttpChallenge httpChallenge)
{
// We need to strip off any leading '/' in the path
var filePath = httpChallenge.FilePath;
Expand Down

0 comments on commit 3e4a814

Please sign in to comment.