-
Notifications
You must be signed in to change notification settings - Fork 644
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
Changes from 14 commits
ce47984
13ac167
1f1a79f
5f7b39e
7023029
8eefef1
e42e3d1
efca902
9fa781b
74b7956
3adaa0f
60faaef
aaed55f
c4d23ea
2b6d013
ec6a5df
2fe8a08
9179140
d8c2737
1349c14
b6e7a38
3bfd79e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.1" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Waiting for 8.2.0 to have tracing support. (Hopefully, it will be released next week) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would the current preview version have the tracing feature? If so then you could complete the PR and just switch the version when it's no more preview. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the current preview version doesn't support tracing. |
||
<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" /> | ||
|
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> | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<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" /> | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" /> | ||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" /> | ||
sebastienros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</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.Azure.AppConfiguration; | ||
using Azure.Identity; | ||
using Microsoft.Extensions.Configuration.AzureAppConfiguration; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Aspire.Azure.Common; | ||
|
||
namespace Microsoft.Extensions.Hosting; | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <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:Azure:AppConfiguration"; | ||
|
||
/// <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:Azure:AppConfiguration" 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.Azure.AppConfiguration; | ||
|
||
[assembly: ConfigurationSchema("Aspire:Azure:AppConfiguration", 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.Azure.AppConfiguration; | ||
|
||
/// <summary> | ||
/// Provides the client configuration settings for connecting to Azure App Configuration. | ||
/// </summary> | ||
public sealed class AzureAppConfigurationSettings : IConnectionStringSettings | ||
zhiyuanliang-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
/// <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,39 @@ | ||
{ | ||
"definitions": { | ||
"logLevel": { | ||
"properties": { | ||
"Microsoft.Extensions.Configuration.AzureAppConfiguration.Refresh": { | ||
"$ref": "#/definitions/logLevelThreshold" | ||
} | ||
} | ||
} | ||
}, | ||
"type": "object", | ||
"properties": { | ||
"Aspire": { | ||
"type": "object", | ||
"properties": { | ||
"Azure": { | ||
"type": "object", | ||
"properties": { | ||
"AppConfiguration": { | ||
"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." | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.