-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new module for OrchardCore.KeyVault.Azure
- Loading branch information
JoshL
committed
Jun 14, 2020
1 parent
f7f4805
commit 1a92632
Showing
6 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
40 changes: 40 additions & 0 deletions
40
...OrchardCore/OrchardCore.KeyVault.Azure/Extensions/AzureKeyVaultWebHostBuilderExtension.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,40 @@ | ||
using System; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using OrchardCore.Azure.KeyVault.Services; | ||
|
||
namespace OrchardCore.Azure.KeyVault.Extensions | ||
{ | ||
public static class AzureKeyVaultWebHostBuilderExtension | ||
{ | ||
/// <summary> | ||
/// Adds Azure Key Vault as a Configuration Source. | ||
/// </summary> | ||
/// <param name="builder">The web host builder to configure.</param> | ||
/// <returns>The web host builder.</returns> | ||
public static IHostBuilder UseOrchardCoreAzureKeyVault(this IHostBuilder builder) | ||
{ | ||
if (builder == null) throw new ArgumentNullException(nameof(builder)); | ||
|
||
builder.ConfigureAppConfiguration((context, configuration) => | ||
{ | ||
var builtConfig = configuration.Build(); | ||
var keyVaultName = builtConfig["OrchardCore:OrchardCore_Azure_KeyVault:KeyVaultName"]; | ||
var clientId = builtConfig["OrchardCore:OrchardCore_Azure_KeyVault:AzureADApplicationId"]; | ||
var clientSecret = builtConfig["OrchardCore:OrchardCore_Azure_KeyVault:AzureADApplicationSecret"]; | ||
|
||
var keyVaultEndpoint = "https://" + keyVaultName + ".vault.azure.net"; | ||
configuration.AddAzureKeyVault( | ||
keyVaultEndpoint, | ||
clientId, | ||
clientSecret, | ||
new CustomKeyVaultSecretManager() | ||
); | ||
}); | ||
|
||
return builder; | ||
} | ||
|
||
|
||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/OrchardCore/OrchardCore.KeyVault.Azure/OrchardCore.KeyVault.Azure.csproj
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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(AspNetCoreTargetFramework)</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\OrchardCore.Abstractions\OrchardCore.Abstractions.csproj" /> | ||
</ItemGroup> | ||
|
||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" /> | ||
</ItemGroup> | ||
|
||
</Project> |
23 changes: 23 additions & 0 deletions
23
src/OrchardCore/OrchardCore.KeyVault.Azure/Services/CustomKeyVaultSecretManager.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,23 @@ | ||
using Microsoft.Azure.KeyVault.Models; | ||
using Microsoft.Extensions.Configuration.AzureKeyVault; | ||
|
||
namespace OrchardCore.Azure.KeyVault.Services | ||
{ | ||
/// <summary> | ||
/// A custom override of the DefaultKeyVaultManger class that retrieves secrets from azure keyvault and translates --- | ||
/// to the OC format using single underscore (illegal character in Azure KeyVault) and -- to : to define a section | ||
/// Examples: | ||
/// Key Vault Input: "OrchardCore--OrchardCore---Shells---Database--ConnectionString". | ||
/// Output: "OrchardCore:OrchardCore_Shells_Database:ConnectionString". | ||
/// See https://github.com/OrchardCMS/OrchardCore/issues/6359. | ||
/// </summary> | ||
public class CustomKeyVaultSecretManager : DefaultKeyVaultSecretManager | ||
{ | ||
public override string GetKey(SecretBundle secret) | ||
{ | ||
var key = secret.SecretIdentifier.Name.Replace("---", "_").Replace("--", ":"); | ||
return key; | ||
} | ||
|
||
} | ||
} |