Skip to content

Commit

Permalink
update azure app config access
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed May 5, 2024
1 parent e0e132c commit 3c9ebdf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
50 changes: 28 additions & 22 deletions src/container_apps/Jordnaer.Chat/AzureAppConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@ namespace Jordnaer.Chat;

public static class AzureAppConfigurationExtensions
{
public static WebApplicationBuilder AddAzureAppConfiguration(this WebApplicationBuilder builder)
{
string? connectionString = builder.Configuration.GetConnectionString("AppConfig") ?? builder.Configuration["appconfig"];
if (connectionString is null)
{
throw new InvalidOperationException("Failed to find connection string to Azure App Configuration. Keys checked: 'ConnectionStrings:AppConfig' and 'appconfig'");
}
public static WebApplicationBuilder AddAzureAppConfiguration(this WebApplicationBuilder builder)
{
builder.Services.AddFeatureManagement();

Check failure on line 7 in src/container_apps/Jordnaer.Chat/AzureAppConfigurationExtensions.cs

View workflow job for this annotation

GitHub Actions / test

'IServiceCollection' does not contain a definition for 'AddFeatureManagement' and no accessible extension method 'AddFeatureManagement' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

builder.Services.AddAzureAppConfiguration();
builder.Configuration.AddAzureAppConfiguration(options =>
options.Connect(connectionString)
// Load all keys that have no label
.Select("*")
// Configure to reload builder if the registered sentinel key is modified
.ConfigureRefresh(refreshOptions =>
{
refreshOptions.Register("Sentinel", refreshAll: true);
refreshOptions.SetCacheExpiration(TimeSpan.FromMinutes(5));
})
.UseFeatureFlags(flagOptions => flagOptions.CacheExpirationInterval = TimeSpan.FromMinutes(3)));
if (builder.Environment.IsDevelopment())
{
return builder;
}

return builder;
}
}
builder.Services.AddAzureAppConfiguration();

// This is set by Azure Service Connector
var connectionString = builder.Configuration["AZURE_APPCONFIGURATION_ENDPOINT"];
if (connectionString is null)
{
throw new InvalidOperationException("Failed to find connection string to Azure App Configuration. Keys checked: 'AZURE_APPCONFIGURATION_ENDPOINT'");
}

builder.Configuration.AddAzureAppConfiguration(options =>
options.Connect(connectionString)
// Load all keys that have no label
.Select("*")
.ConfigureRefresh(refreshOptions =>
// Only reload configs if the 'Sentinel' key is modified
refreshOptions.Register("Sentinel", refreshAll: true))
.UseFeatureFlags());

return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public static WebApplicationBuilder AddAzureAppConfiguration(this WebApplication

builder.Services.AddAzureAppConfiguration();

var connectionString = builder.Configuration.GetConnectionString("AppConfig");
// This is set by Azure Service Connector
var connectionString = builder.Configuration["AZURE_APPCONFIGURATION_ENDPOINT"];
if (connectionString is null)
{
throw new InvalidOperationException("Failed to find connection string to Azure App Configuration. Keys checked: 'ConnectionStrings:AppConfig'");
throw new InvalidOperationException("Failed to find connection string to Azure App Configuration. Keys checked: 'AZURE_APPCONFIGURATION_ENDPOINT'");
}

builder.Configuration.AddAzureAppConfiguration(options =>
Expand Down

0 comments on commit 3c9ebdf

Please sign in to comment.