diff --git a/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs b/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs index 9507862..230a641 100644 --- a/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs +++ b/LetsEncrypt-SiteExtension/Models/AuthenticationModel.cs @@ -101,7 +101,8 @@ public static explicit operator AuthenticationModel(AppSettingsAuthConfig config AuthenticationEndpoint = config.AuthenticationEndpoint, AzureWebSitesDefaultDomainName = config.AzureWebSitesDefaultDomainName, ManagementEndpoint = config.ManagementEndpoint, - TokenAudience = config.TokenAudience + TokenAudience = config.TokenAudience, + SiteSlotName = config.SiteSlotName }; } } diff --git a/LetsEncrypt.SiteExtension.Core/ArmHelper.cs b/LetsEncrypt.SiteExtension.Core/ArmHelper.cs index 9ee6480..5776ae0 100644 --- a/LetsEncrypt.SiteExtension.Core/ArmHelper.cs +++ b/LetsEncrypt.SiteExtension.Core/ArmHelper.cs @@ -1,5 +1,4 @@ using LetsEncrypt.SiteExtension.Models; -using Microsoft.Azure.Management.Resources; using Microsoft.Azure.Management.WebSites; using Microsoft.IdentityModel.Clients.ActiveDirectory; using Microsoft.Rest; diff --git a/LetsEncrypt.SiteExtension.Core/KuduHelper.cs b/LetsEncrypt.SiteExtension.Core/KuduHelper.cs index d120e3d..9fbc0dd 100644 --- a/LetsEncrypt.SiteExtension.Core/KuduHelper.cs +++ b/LetsEncrypt.SiteExtension.Core/KuduHelper.cs @@ -14,7 +14,7 @@ public static KuduRestClient GetKuduClient(this WebSiteManagementClient client, { var user = client.WebApps.GetPublsihingCredentialSiteOrSlot(settings.ResourceGroupName, settings.WebAppName, settings.SiteSlotName); - return new KuduRestClient(settings, settings.WebAppName, user.PublishingUserName, user.PublishingPassword); + return new KuduRestClient(settings, user.PublishingUserName, user.PublishingPassword); } } } diff --git a/LetsEncrypt.SiteExtension.Core/KuduRestClient.cs b/LetsEncrypt.SiteExtension.Core/KuduRestClient.cs index 3288c5c..cd79fd3 100644 --- a/LetsEncrypt.SiteExtension.Core/KuduRestClient.cs +++ b/LetsEncrypt.SiteExtension.Core/KuduRestClient.cs @@ -16,9 +16,9 @@ public class KuduRestClient private string publishingUserName; private string webAppName; - public KuduRestClient(IAzureEnvironment azureEnvironment, string webAppName, string publishingUserName, string publishingPassword) + public KuduRestClient(IAzureEnvironment azureEnvironment, string publishingUserName, string publishingPassword) { - this.webAppName = webAppName; + this.webAppName = string.IsNullOrEmpty(azureEnvironment.SiteSlotName) ? azureEnvironment.WebAppName : azureEnvironment.WebAppName + "-" + azureEnvironment.SiteSlotName; this.publishingUserName = publishingUserName; this.publishingPassword = publishingPassword; this.baseUri = $"https://{this.webAppName}.scm.{azureEnvironment.AzureWebSitesDefaultDomainName}"; diff --git a/LetsEncrypt.SiteExtension.WebJob/Functions.cs b/LetsEncrypt.SiteExtension.WebJob/Functions.cs index d49bfd8..52fa45c 100644 --- a/LetsEncrypt.SiteExtension.WebJob/Functions.cs +++ b/LetsEncrypt.SiteExtension.WebJob/Functions.cs @@ -39,11 +39,13 @@ public class Functions public static void AddCertificate([TimerTrigger(typeof(MonthlySchedule), RunOnStartup = true)] TimerInfo timerInfo, [Blob("letsencrypt/firstrun.job")] string input, [Blob("letsencrypt/firstrun.job")] out string output) { Console.WriteLine("Starting add certificate"); - string websiteName = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"); + var environment = new Models.AppSettingsAuthConfig(); + string websiteName = environment.WebAppName + "-" + environment.SiteSlotName + "|"; if (string.IsNullOrEmpty(input) || !input.Contains(websiteName)) { - new CertificateManager(new Models.AppSettingsAuthConfig()).AddCertificate(); - output = string.IsNullOrEmpty(input) ? websiteName : input + '|' + websiteName; + Console.WriteLine($"First run of add certificate for {websiteName}"); + new CertificateManager(environment).AddCertificate(); + output = string.IsNullOrEmpty(input) ? websiteName : input + websiteName; } else { diff --git a/LetsEncrypt.SiteExtension.WebJob/Program.cs b/LetsEncrypt.SiteExtension.WebJob/Program.cs index 0438fb3..ee3d8c3 100644 --- a/LetsEncrypt.SiteExtension.WebJob/Program.cs +++ b/LetsEncrypt.SiteExtension.WebJob/Program.cs @@ -19,7 +19,8 @@ static void Main() config.UseTimers(); //A host ID must be between 1 and 32 characters, contain only lowercase letters, numbers, and //dashes, not start or end with a dash, and not contain consecutive dashes. - var hostId = "letsencrypt-" + Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"); + var environment = new Models.AppSettingsAuthConfig(); + var hostId = "le-" + environment.WebAppName + environment.SiteSlotName; config.HostId = hostId.Substring(0,hostId.Length > 32 ? 32 : hostId.Length).TrimEnd(new[] { '-' }).ToLower(); var host = new JobHost(config); diff --git a/LetsEncrypt.nuspec b/LetsEncrypt.nuspec index 5ce0db4..cb896fb 100644 --- a/LetsEncrypt.nuspec +++ b/LetsEncrypt.nuspec @@ -3,7 +3,7 @@ letsencrypt Azure Let's Encrypt (x86) - 0.6.14 + 0.6.16 SJKP http://opensource.org/licenses/Apache-2.0 https://github.com/sjkp/letsencrypt-siteextension diff --git a/LetsEncrypt64.nuspec b/LetsEncrypt64.nuspec index 24c55e8..7cbad6c 100644 --- a/LetsEncrypt64.nuspec +++ b/LetsEncrypt64.nuspec @@ -3,7 +3,7 @@ letsencrypt64 Azure Let's Encrypt (x64) - 0.6.14 + 0.6.16 SJKP http://opensource.org/licenses/Apache-2.0 https://github.com/sjkp/letsencrypt-siteextension