Skip to content

Azure App Configuration client integration #8945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Aspire.sln
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Azure.Npgsql.EntityF
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Components.Common.Tests", "tests\Aspire.Components.Common.Tests\Aspire.Components.Common.Tests.csproj", "{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration", "src\Components\Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration\Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration.csproj", "{C33CE874-27B7-4194-A2E7-D0CD950997CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration.Tests", "tests\Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration.Tests\Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration.Tests.csproj", "{FE972BF3-F448-4CF0-8544-0056B26BF006}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Azure.ContainerRegistry", "src\Aspire.Hosting.Azure.ContainerRegistry\Aspire.Hosting.Azure.ContainerRegistry.csproj", "{6CBA29C8-FF78-4ABC-BEFA-2A53CB4DB2A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspire.Hosting.Azure.AppService", "src\Aspire.Hosting.Azure.AppService\Aspire.Hosting.Azure.AppService.csproj", "{5DDF8E89-FBBD-4A6F-BF32-7D2140724941}"
Expand Down Expand Up @@ -3892,6 +3896,30 @@ Global
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}.Release|x64.Build.0 = Release|Any CPU
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}.Release|x86.ActiveCfg = Release|Any CPU
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7}.Release|x86.Build.0 = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|x64.ActiveCfg = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|x64.Build.0 = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|x86.ActiveCfg = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Debug|x86.Build.0 = Debug|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|Any CPU.Build.0 = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|x64.ActiveCfg = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|x64.Build.0 = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|x86.ActiveCfg = Release|Any CPU
{C33CE874-27B7-4194-A2E7-D0CD950997CC}.Release|x86.Build.0 = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|x64.ActiveCfg = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|x64.Build.0 = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|x86.ActiveCfg = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Debug|x86.Build.0 = Debug|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|Any CPU.Build.0 = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|x64.ActiveCfg = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|x64.Build.0 = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|x86.ActiveCfg = Release|Any CPU
{FE972BF3-F448-4CF0-8544-0056B26BF006}.Release|x86.Build.0 = Release|Any CPU
{6CBA29C8-FF78-4ABC-BEFA-2A53CB4DB2A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CBA29C8-FF78-4ABC-BEFA-2A53CB4DB2A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CBA29C8-FF78-4ABC-BEFA-2A53CB4DB2A3}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -4293,6 +4321,8 @@ Global
{192747A2-9338-DECF-5C8C-28EB8E13829B} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{8FCA0CFA-7823-6A2F-342A-107A994915B0} = {C424395C-1235-41A4-BF55-07880A04368C}
{30950CEB-2232-F9FC-04FF-ADDCB8AC30A7} = {C424395C-1235-41A4-BF55-07880A04368C}
{C33CE874-27B7-4194-A2E7-D0CD950997CC} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
{FE972BF3-F448-4CF0-8544-0056B26BF006} = {C424395C-1235-41A4-BF55-07880A04368C}
{6CBA29C8-FF78-4ABC-BEFA-2A53CB4DB2A3} = {77CFE74A-32EE-400C-8930-5025E8555256}
{5DDF8E89-FBBD-4A6F-BF32-7D2140724941} = {77CFE74A-32EE-400C-8930-5025E8555256}
{2D9974C2-3AB2-FBFD-5156-080508BB7449} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PackageVersion Include="Azure.Security.KeyVault.Keys" Version="4.7.0" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.24.0" />
<PackageVersion Include="Azure.Storage.Queues" Version="12.22.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.1.2" />
<PackageVersion Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="8.1.2" />
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.49.0" />
<PackageVersion Include="Microsoft.Azure.SignalR" Version="1.30.3" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
<IsPackable>true</IsPackable>
<PackageTags>$(ComponentAzurePackageTags) configuration appconfiguration</PackageTags>
<Description>A client for Azure App Configuration that integrates with Aspire.</Description>
<PackageIconFullPath>$(SharedDir)AzureAppConfig_256x.png</PackageIconFullPath>
<NoWarn>$(NoWarn);SYSLIB1100;SYSLIB1101</NoWarn>
<!-- Disable package validation as this package hasn't shipped stable yet. -->
<EnablePackageValidation>false</EnablePackageValidation>
<!-- In preview until the full experience is implemented. -->
<SuppressFinalPackageVersion>true</SuppressFinalPackageVersion>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Common\AzureComponent.cs" Link="AzureComponent.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
<Compile Include="..\Common\HealthChecksExtensions.cs" Link="HealthChecksExtensions.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Azure" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration;
using Azure.Identity;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Aspire.Azure.Common;

namespace Microsoft.Extensions.Hosting;

/// <summary>
/// Provides extension methods for registering and configuring Azure App Configuration in a .NET Aspire application.
/// </summary>
public static class AspireAppConfigurationExtensions
{
internal const string DefaultConfigSectionName = "Aspire:Microsoft:Extensions:Configuration:AzureAppConfiguration";

/// <summary>
/// Adds the Azure App Configuration to be configuration in the <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IHostApplicationBuilder" /> to read config from and add services to.</param>
/// <param name="connectionName">A name used to retrieve the connection string from the ConnectionStrings configuration section.</param>
/// <param name="configureSettings">An optional method that can be used for customizing the <see cref="AzureAppConfigurationSettings"/>. It's invoked after the settings are read from the configuration.</param>
/// <param name="configureOptions">An optional method that can be used for customizing the <see cref="AzureAppConfigurationOptions"/>.</param>
/// <remarks>Reads the settings from "Aspire:Microsoft:Extensions:Configuration:AzureAppConfiguration" section.</remarks>
/// <exception cref="InvalidOperationException">Thrown when mandatory <see cref="AzureAppConfigurationSettings.Endpoint"/> is not provided.</exception>
public static void AddAzureAppConfiguration(
this IHostApplicationBuilder builder,
string connectionName,
Action<AzureAppConfigurationSettings>? configureSettings = null,
Action<AzureAppConfigurationOptions>? configureOptions = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(connectionName);

IConfigurationSection configSection = builder.Configuration.GetSection(DefaultConfigSectionName);

var settings = new AzureAppConfigurationSettings();
configSection.Bind(settings);

if (builder.Configuration.GetConnectionString(connectionName) is string connectionString)
{
((IConnectionStringSettings)settings).ParseConnectionString(connectionString);
}

configureSettings?.Invoke(settings);

if (settings.Endpoint is null)
{
throw new InvalidOperationException($"Endpoint is missing. It should be provided in 'ConnectionStrings:{connectionName}' or under the 'Endpoint' key in the '{DefaultConfigSectionName}' configuration section.");
}

builder.Configuration.AddAzureAppConfiguration(
options =>
{
options.Connect(settings.Endpoint, settings.Credential ?? new DefaultAzureCredential());
configureOptions?.Invoke(options);
},
settings.Optional);

builder.Services.AddAzureAppConfiguration(); // register IConfigurationRefresherProvider service
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire;
using Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration;

[assembly: ConfigurationSchema("Aspire:Microsoft:Extensions:Configuration:AzureAppConfiguration", typeof(AzureAppConfigurationSettings))]

[assembly: LoggingCategories(
"Microsoft.Extensions.Configuration.AzureAppConfiguration.Refresh")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Azure.Common;
using Azure.Core;

namespace Aspire.Microsoft.Extensions.Configuration.AzureAppConfiguration;

/// <summary>
/// Provides the client configuration settings for connecting to Azure App Configuration.
/// </summary>
public sealed class AzureAppConfigurationSettings : IConnectionStringSettings
{
/// <summary>
/// A <see cref="Uri"/> to the App Configuration store on which the client operates. Appears as "Endpoint" in the Azure portal.
/// This is likely to be similar to "https://{store_name}.azconfig.io".
/// </summary>
public Uri? Endpoint { get; set; }

/// <summary>
/// Gets or sets the credential used to authenticate to the Azure App Configuration.
/// </summary>
public TokenCredential? Credential { get; set; }

/// <summary>
/// Determines the behavior of the App Configuration provider when an exception occurs while loading data from server.
/// If false, the exception is thrown. If true, the exception is suppressed and no configuration values are populated from Azure App Configuration.
/// </summary>
public bool Optional { get; set; }

void IConnectionStringSettings.ParseConnectionString(string? connectionString)
{
if (!string.IsNullOrEmpty(connectionString) &&
Uri.TryCreate(connectionString, UriKind.Absolute, out var uri))
{
Endpoint = uri;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"definitions": {
"logLevel": {
"properties": {
"Microsoft.Extensions.Configuration.AzureAppConfiguration.Refresh": {
"$ref": "#/definitions/logLevelThreshold"
}
}
}
},
"type": "object",
"properties": {
"Aspire": {
"type": "object",
"properties": {
"Microsoft": {
"type": "object",
"properties": {
"Extensions": {
"type": "object",
"properties": {
"Configuration": {
"type": "object",
"properties": {
"AzureAppConfiguration": {
"type": "object",
"properties": {
"Endpoint": {
"type": "string",
"format": "uri",
"description": "A 'System.Uri' to the App Configuration store on which the client operates. Appears as \"Endpoint\" in the Azure portal. This is likely to be similar to \"https://{store_name}.azconfig.io\"."
},
"Optional": {
"type": "boolean",
"description": "Determines the behavior of the App Configuration provider when an exception occurs while loading data from server. If false, the exception is thrown. If true, the exception is suppressed and no configuration values are populated from Azure App Configuration."
}
},
"description": "Provides the client configuration settings for connecting to Azure App Configuration."
}
}
}
}
}
}
}
}
}
}
}
Loading