Skip to content

Commit 1dad682

Browse files
StephenMolloyHongGit
authored andcommitted
Azure app config preview (#48)
* Add Azconfig builder. * Update package build. * Update name for Azure App Configuration. * Fix bug installing user secrets in 'Website' projects. * Update AppConfig packages to strong-named previews. * Incorrect handling of name change affecting version adjustment for Azconfig.
1 parent 0db7b6a commit 1dad682

15 files changed

Lines changed: 586 additions & 3 deletions

MicrosoftConfigurationBuilders.msbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<AssemblyProject Include="src\UserSecrets\UserSecrets.csproj" />
77
<AssemblyProject Include="src\Azure\Azure.csproj" />
88
<AssemblyProject Include="src\Json\Json.csproj" />
9+
<AssemblyProject Include="src\AzureAppConfig\AzureAppConfig.csproj" />
910
</ItemGroup>
1011

1112
<ItemGroup>

MicrosoftConfigurationBuilders.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyPerFile", "src\KeyPerFil
5858
EndProject
5959
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApp", "samples\SampleWebApp\SampleWebApp.csproj", "{590892DD-F842-4E7C-9400-4C6451C16B1A}"
6060
EndProject
61+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureAppConfig", "src\AzureAppConfig\AzureAppConfig.csproj", "{3F1BB24A-355F-49E7-B396-6AA2EB5DDA0E}"
62+
EndProject
6163
Global
6264
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6365
Debug|Any CPU = Debug|Any CPU
@@ -100,6 +102,10 @@ Global
100102
{590892DD-F842-4E7C-9400-4C6451C16B1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
101103
{590892DD-F842-4E7C-9400-4C6451C16B1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
102104
{590892DD-F842-4E7C-9400-4C6451C16B1A}.Release|Any CPU.Build.0 = Release|Any CPU
105+
{3F1BB24A-355F-49E7-B396-6AA2EB5DDA0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
106+
{3F1BB24A-355F-49E7-B396-6AA2EB5DDA0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
107+
{3F1BB24A-355F-49E7-B396-6AA2EB5DDA0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
108+
{3F1BB24A-355F-49E7-B396-6AA2EB5DDA0E}.Release|Any CPU.Build.0 = Release|Any CPU
103109
EndGlobalSection
104110
GlobalSection(SolutionProperties) = preSolution
105111
HideSolutionNode = FALSE

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ are also intended to address some of the basic needs of applications as they mov
66

77
### V2 Update:
88
Version 2 is here with some new features:
9+
* Azure App Configuration Support - There is a [new builder](#azureappconfigurationbuilder) for drawing values from the new Azure App Configuration service.
910
* ConfigBuilder Parameters from AppSettings - This has been one of the most asked for features of these config builders. With V2, it is now possible to
1011
read initialization parameters for config builders from `appSettings`. Read more about it [here](#appsettings-parameters).
1112
* Lazy Initialization - As part of the work to enable pulling config parameters from `appSettings`, these key/value configuration builders now support a
@@ -164,6 +165,49 @@ and currently exposes the format of the file which, as mentioned above, should b
164165
</root>
165166
```
166167

168+
### AzureAppConfigurationBuilder
169+
```xml
170+
<add name="AzureAppConfig"
171+
[mode|@prefix|@stripPrefix|tokenPattern|@optional=false]
172+
(@vaultName="MyVaultName" | @uri="https://MyVaultName.vault.azure.net")
173+
[@connectionString="connection string"]
174+
[@version="secrets version"]
175+
[@preloadSecretNames="true"]
176+
type="Microsoft.Configuration.ConfigurationBuilders.AzureKeyVaultConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Azure" />
177+
```
178+
[ParameterDescription]@{ Name="endpoint"; IsRequired=$false; DefaultValue="[Config_Store_Endpoint_Url]" },
179+
[ParameterDescription]@{ Name="connectionString"; IsRequired=$false },
180+
[ParameterDescription]@{ Name="keyFilter"; IsRequired=$false });
181+
[ParameterDescription]@{ Name="labelFilter"; IsRequired=$false });
182+
[ParameterDescription]@{ Name="preferredDateTime"; IsRequired=$false },
183+
If your secrets are kept in Azure Key Vault, then this config builder is for you. There are three additional attributes for this config builder. The `vaultName` is
184+
required. The other attributes allow you some manual control about which vault to connect to, but are only necessary if the application is not running in an
185+
environment that works magically with `Microsoft.Azure.Services.AppAuthentication`. The Azure Services Authentication library is used to automatically pick
186+
up connection information from the execution environment if possible, but you can override that feature by providing a connection string instead.
187+
* `vaultName` - This is a required attribute. It specifies the name of the vault in your Azure subscription from which to read key/value pairs.
188+
* `connectionString` - A connection string usable by [AzureServiceTokenProvider](https://docs.microsoft.com/en-us/azure/key-vault/service-to-service-authentication#connection-string-support)
189+
* `uri` - Connect to other Key Vault providers with this attribute. If not specified, Azure is the assumed Vault provider. If the uri _is_specified, then `vaultName` is no longer a required parameter.
190+
* `version` - Azure Key Vault provides a versioning feature for secrets. If this is specified, the builder will only retrieve secrets matching this version.
191+
* `preloadSecretNames` - By default, this builder will query __all__ the key names in the key vault when it is initialized. If this is a concern, set
192+
this attribute to 'false', and secrets will be retrieved one at a time. This could also be useful if the vault allows "Get" access but not
193+
"List" access. (NOTE: Disabling preload is incompatible with Greedy mode.)
194+
Tip: Azure Key Vault uses random per-secret Guid assignments for versioning, which makes specifying a secret `version` tag on this builder rather
195+
limiting, as it will only ever update one config value. To make version handling more useful, V2 of this builder takes advantage of the new key-updating
196+
feature to allow users to specify version tags in key names rather than on the config builder declaration. That way, the same builder can handle multiple
197+
keys with specific versions instead of needing to redefine multiple builders.
198+
When requesting a specific version for a particular key, the key name in the original config file should look like __`keyName/versionId`__. The
199+
AzureKeyVaultConfigBuilder will only substitue values for 'keyName' if the specified 'versionId' exists in the vault. When that happens, the
200+
AzureKeyVaultConfigBuilder will remove the `/versionId` from the original key, and the resulting config section will only contain `keyName`.
201+
For example:
202+
```xml
203+
<appSettings configBuilders="AzureKeyVault">
204+
<add key="item1" value="Replaced with latest value from the key vault." />
205+
<add key="item2/0123456789abcdefdeadbeefbadf00d" value="Replaced with specific version only." />
206+
</appSettings>
207+
```
208+
Assuming both of these items exist in the vault, and the version tag for `item2` is valid, this would result in an collection of appSettings with two
209+
entries: `item1` and `item2`.
210+
167211
### AzureKeyVaultConfigBuilder
168212
```xml
169213
<add name="AzureKeyVault"
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),MicrosoftConfigurationBuilders.sln))\tools\MicrosoftConfigurationBuilders.settings.targets" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{3F1BB24A-355F-49E7-B396-6AA2EB5DDA0E}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Microsoft.Configuration.ConfigurationBuilders</RootNamespace>
12+
<AssemblyName>Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration</AssemblyName>
13+
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
14+
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
15+
<FileAlignment>512</FileAlignment>
16+
<TargetFrameworkProfile />
17+
<SignAssembly>true</SignAssembly>
18+
<DelaySign>true</DelaySign>
19+
<AssemblyOriginatorKeyFile>..\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
20+
<NuGetPackageImportStamp>
21+
</NuGetPackageImportStamp>
22+
</PropertyGroup>
23+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
24+
<DebugSymbols>true</DebugSymbols>
25+
<DebugType>full</DebugType>
26+
<Optimize>false</Optimize>
27+
<DefineConstants>DEBUG;TRACE</DefineConstants>
28+
<ErrorReport>prompt</ErrorReport>
29+
<WarningLevel>4</WarningLevel>
30+
<BaseIntermediateOutputPath>..\obj\</BaseIntermediateOutputPath>
31+
</PropertyGroup>
32+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
33+
<DebugType>pdbonly</DebugType>
34+
<Optimize>true</Optimize>
35+
<DefineConstants>TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
<BaseIntermediateOutputPath>..\obj\</BaseIntermediateOutputPath>
39+
</PropertyGroup>
40+
<ItemGroup>
41+
<Reference Include="Microsoft.AspNetCore.Http.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
42+
<HintPath>..\..\packages\Microsoft.AspNetCore.Http.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Microsoft.AspNetCore.Http.Extensions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
45+
<HintPath>..\..\packages\Microsoft.AspNetCore.Http.Extensions.2.1.1\lib\netstandard2.0\Microsoft.AspNetCore.Http.Extensions.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Microsoft.AspNetCore.Http.Features, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
48+
<HintPath>..\..\packages\Microsoft.AspNetCore.Http.Features.2.1.1\lib\netstandard2.0\Microsoft.AspNetCore.Http.Features.dll</HintPath>
49+
</Reference>
50+
<Reference Include="Microsoft.Azure.AppConfiguration.AzconfigClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69dad7634abb75e4, processorArchitecture=MSIL">
51+
<HintPath>..\..\packages\Microsoft.Azure.AppConfiguration.AzconfigClient.1.0.0-preview-007830001\lib\netstandard2.0\Microsoft.Azure.AppConfiguration.AzconfigClient.dll</HintPath>
52+
</Reference>
53+
<Reference Include="Microsoft.Azure.AppConfiguration.ManagedIdentityConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69dad7634abb75e4, processorArchitecture=MSIL">
54+
<HintPath>..\..\packages\Microsoft.Azure.AppConfiguration.ManagedIdentityConnector.1.0.0-preview-007830001-1266\lib\netstandard2.0\Microsoft.Azure.AppConfiguration.ManagedIdentityConnector.dll</HintPath>
55+
</Reference>
56+
<Reference Include="Microsoft.Azure.Management.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57+
<HintPath>..\..\packages\Microsoft.Azure.Management.ResourceManager.2.0.0-preview\lib\net452\Microsoft.Azure.Management.ResourceManager.dll</HintPath>
58+
</Reference>
59+
<Reference Include="Microsoft.Azure.Services.AppAuthentication, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
60+
<HintPath>..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.3\lib\net452\Microsoft.Azure.Services.AppAuthentication.dll</HintPath>
61+
</Reference>
62+
<Reference Include="Microsoft.Extensions.FileProviders.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
63+
<HintPath>..\..\packages\Microsoft.Extensions.FileProviders.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Abstractions.dll</HintPath>
64+
</Reference>
65+
<Reference Include="Microsoft.Extensions.Primitives, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
66+
<HintPath>..\..\packages\Microsoft.Extensions.Primitives.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll</HintPath>
67+
</Reference>
68+
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
69+
<HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.14.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
70+
</Reference>
71+
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
72+
<HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.14.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll</HintPath>
73+
</Reference>
74+
<Reference Include="Microsoft.Net.Http.Headers, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
75+
<HintPath>..\..\packages\Microsoft.Net.Http.Headers.2.1.1\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll</HintPath>
76+
</Reference>
77+
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
78+
<HintPath>..\..\packages\Microsoft.Rest.ClientRuntime.2.3.13\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
79+
</Reference>
80+
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
81+
<HintPath>..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.15\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
82+
</Reference>
83+
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
84+
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
85+
</Reference>
86+
<Reference Include="System" />
87+
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
88+
<HintPath>..\..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
89+
</Reference>
90+
<Reference Include="System.Configuration" />
91+
<Reference Include="System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
92+
<HintPath>..\..\packages\System.Interactive.Async.3.1.1\lib\net46\System.Interactive.Async.dll</HintPath>
93+
</Reference>
94+
<Reference Include="System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
95+
<HintPath>..\..\packages\System.Memory.4.5.1\lib\netstandard2.0\System.Memory.dll</HintPath>
96+
</Reference>
97+
<Reference Include="System.Net" />
98+
<Reference Include="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
99+
<Reference Include="System.Net.Http.WebRequest" />
100+
<Reference Include="System.Numerics" />
101+
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
102+
<HintPath>..\..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
103+
</Reference>
104+
<Reference Include="System.Reactive, Version=4.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
105+
<HintPath>..\..\packages\System.Reactive.4.0.0\lib\net46\System.Reactive.dll</HintPath>
106+
</Reference>
107+
<Reference Include="System.Reactive.Linq, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
108+
<HintPath>..\..\packages\System.Reactive.Linq.4.0.0\lib\net46\System.Reactive.Linq.dll</HintPath>
109+
</Reference>
110+
<Reference Include="System.Runtime" />
111+
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
112+
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
113+
</Reference>
114+
<Reference Include="System.Runtime.Serialization" />
115+
<Reference Include="System.Text.Encodings.Web, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
116+
<HintPath>..\..\packages\System.Text.Encodings.Web.4.5.0\lib\netstandard2.0\System.Text.Encodings.Web.dll</HintPath>
117+
</Reference>
118+
<Reference Include="System.Windows" />
119+
<Reference Include="System.Windows.Forms" />
120+
<Reference Include="WindowsBase" />
121+
</ItemGroup>
122+
<ItemGroup>
123+
<Compile Include="AzureAppConfigurationBuilder.cs" />
124+
<Compile Include="Properties\AssemblyInfo.cs" />
125+
</ItemGroup>
126+
<ItemGroup>
127+
<ProjectReference Include="..\Base\Base.csproj">
128+
<Project>{f382fbf8-146d-4968-a199-90d37f9ef9a7}</Project>
129+
<Name>Base</Name>
130+
</ProjectReference>
131+
</ItemGroup>
132+
<ItemGroup>
133+
<None Include="app.config" />
134+
<None Include="packages.config" />
135+
</ItemGroup>
136+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
137+
<Import Project="..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.3\build\Microsoft.Azure.Services.AppAuthentication.targets" Condition="Exists('..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.3\build\Microsoft.Azure.Services.AppAuthentication.targets')" />
138+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
139+
<PropertyGroup>
140+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
141+
</PropertyGroup>
142+
<Error Condition="!Exists('..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.3\build\Microsoft.Azure.Services.AppAuthentication.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.3\build\Microsoft.Azure.Services.AppAuthentication.targets'))" />
143+
</Target>
144+
</Project>

0 commit comments

Comments
 (0)