-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New update mechanism for Azure certs (#78)
* Fixes problem with trying to update certs which are in use * Transparently treats slots the same way as normal apps * Fixes problem with base app settings being changed rather than slot settings * Refactors very large PersistAsync method into parts
- Loading branch information
Showing
3 changed files
with
369 additions
and
190 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
src/FluffySpoon.AspNet.LetsEncrypt.Azure/AzureAppInstance.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Management.AppService.Fluent; | ||
using Microsoft.Azure.Management.AppService.Fluent.Models; | ||
using Microsoft.Azure.Management.Fluent; | ||
|
||
namespace FluffySpoon.AspNet.LetsEncrypt.Azure | ||
{ | ||
/// <summary> | ||
/// A reference to an Azure app, which might be either a simple app, or a deployment slot | ||
/// </summary> | ||
public class AzureAppInstance | ||
{ | ||
readonly IWebApp _app; | ||
readonly IDeploymentSlot _slot; | ||
|
||
public AzureAppInstance(IWebApp app) | ||
{ | ||
_app = app; | ||
} | ||
|
||
public AzureAppInstance(IWebApp app, IDeploymentSlot slot) | ||
{ | ||
_app = app; | ||
_slot = slot; | ||
} | ||
|
||
/// <summary> | ||
/// A general purpose name for this instance | ||
/// </summary> | ||
public string DisplayName => IsSlot ? $"{_app.Name}/{_slot.Name}" : _app.Name; | ||
|
||
/// <summary> | ||
/// Get the host names associated with this instance | ||
/// </summary> | ||
public ISet<string> HostNames => IsSlot ? _slot.HostNames : _app.HostNames; | ||
|
||
private bool IsSlot => _slot != null; | ||
|
||
public Task<HostNameBindingInner> GetHostNameBindingAsync(IAzure client, string resourceGroupName, string domain) | ||
{ | ||
if (IsSlot) | ||
{ | ||
return client.WebApps.Inner.GetHostNameBindingSlotAsync(resourceGroupName, | ||
_app.Name, | ||
_slot.Name, | ||
domain); | ||
} | ||
else | ||
{ | ||
return client.WebApps.Inner.GetHostNameBindingAsync(resourceGroupName, | ||
_app.Name, | ||
domain); | ||
} | ||
} | ||
|
||
public Task SetHostNameBindingAsync(IAzure client, string resourceGroupName, string domain, HostNameBindingInner binding) | ||
{ | ||
if (IsSlot) | ||
{ | ||
return client.WebApps.Inner.CreateOrUpdateHostNameBindingSlotWithHttpMessagesAsync( | ||
resourceGroupName, | ||
_app.Name, | ||
domain, | ||
binding, | ||
_slot.Name); | ||
} | ||
else | ||
{ | ||
return client.WebApps.Inner.CreateOrUpdateHostNameBindingWithHttpMessagesAsync( | ||
resourceGroupName, | ||
_app.Name, | ||
domain, | ||
binding | ||
); | ||
} | ||
} | ||
|
||
public Task<IReadOnlyDictionary<string, IAppSetting>> GetAppSettings() | ||
{ | ||
if (IsSlot) | ||
{ | ||
return _slot.GetAppSettingsAsync(); | ||
} | ||
else | ||
{ | ||
return _app.GetAppSettingsAsync(); | ||
} | ||
} | ||
|
||
public Task UpdateAppSettingAsync(string key, string value) | ||
{ | ||
if (IsSlot) | ||
{ | ||
return _slot.Update() | ||
.WithAppSetting(key, value) | ||
.ApplyAsync(); | ||
} | ||
else | ||
{ | ||
return _app.Update() | ||
.WithAppSetting(key, value) | ||
.ApplyAsync(); | ||
} | ||
} | ||
|
||
public string RegionName => IsSlot ? _slot.RegionName : _app.RegionName; | ||
} | ||
} |
Oops, something went wrong.