Skip to content

Commit 6307982

Browse files
Integrated KeyVault (#58)
1 parent 8a8a37c commit 6307982

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/Functions/Rsp.RtsImport/Startup/Configuration/AzureAppConfiguration.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ public static IServiceCollection AddAzureAppConfiguration(this IServiceCollectio
2727
(
2828
options =>
2929
{
30+
var credentials = new ManagedIdentityCredential(azureAppSettings.AzureAppConfiguration.IdentityClientId);
3031
options.Connect
3132
(
3233
new Uri(azureAppSettings!.AzureAppConfiguration.Endpoint),
33-
new ManagedIdentityCredential(azureAppSettings.AzureAppConfiguration.IdentityClientId)
34+
credentials
3435
)
3536
.Select(KeyFilter.Any) // select all the settings without any label
3637
.Select(KeyFilter.Any,
@@ -61,7 +62,7 @@ public static IServiceCollection AddAzureAppConfiguration(this IServiceCollectio
6162
AppSettings.ServiceLabel) // select all flags using the service name as label
6263
.SetRefreshInterval(TimeSpan.FromSeconds(15));
6364
}
64-
);
65+
).ConfigureKeyVault(options=>options.SetCredential(credentials));
6566
}
6667
);
6768

src/Startup/Rsp.RtsService/Program.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,33 @@
3232
var services = builder.Services;
3333
var configuration = builder.Configuration;
3434

35+
var appSettingsSection = configuration.GetSection(nameof(AppSettings));
36+
var appSettings = appSettingsSection.Get<AppSettings>();
37+
3538
if (!builder.Environment.IsDevelopment())
3639
{
3740
services.AddLogging(builder => builder.AddConsole());
3841
}
3942

4043
if (!builder.Environment.IsDevelopment())
4144
{
42-
var azureAppConfigSection = configuration.GetSection(nameof(AppSettings));
43-
var azureAppConfiguration = azureAppConfigSection.Get<AppSettings>();
44-
4545
// Load configuration from Azure App Configuration
4646
builder.Configuration.AddAzureAppConfiguration(
4747
options =>
48-
{
49-
options.Connect
48+
{
49+
var credentials = new ManagedIdentityCredential(appSettings!.AzureAppConfiguration.IdentityClientID);
50+
51+
options.Connect
5052
(
51-
new Uri(azureAppConfiguration!.AzureAppConfiguration.Endpoint),
52-
new ManagedIdentityCredential(azureAppConfiguration.AzureAppConfiguration.IdentityClientID)
53+
new Uri(appSettings.AzureAppConfiguration.Endpoint),
54+
credentials
5355
)
5456
.Select(KeyFilter.Any)
5557
.Select(KeyFilter.Any, AppSettings.ServiceLabel)
58+
.ConfigureKeyVault(kv => kv.SetCredential(credentials))
5659
.ConfigureRefresh(refreshOptions =>
5760
refreshOptions
58-
.Register("AppSettings:Sentinel", AppSettings.ServiceLabel, refreshAll: true)
61+
.Register("AppSettings:Sentinel", AppSettings.ServiceLabel, refreshAll: true)
5962
.SetRefreshInterval(new TimeSpan(0, 0, 15))
6063
);
6164
}
@@ -81,8 +84,6 @@
8184
// uncomment the following line
8285
// builder.AddServiceDefaults()
8386

84-
var appSettingsSection = configuration.GetSection(nameof(AppSettings));
85-
var appSettings = appSettingsSection.Get<AppSettings>();
8687

8788
// adds sql server database context
8889
services.AddDatabase(configuration);

0 commit comments

Comments
 (0)