Skip to content
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

Moved Data Protection configuration into it's own typed Options #1242

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Dfe.PrepareConversions.Configuration;

public class DataProtectionOptions
{
public const string ConfigurationSection = "DataProtection";
public string KeyVaultKey { get; init; }
}
5 changes: 3 additions & 2 deletions Dfe.PrepareConversions/Dfe.PrepareConversions/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ public void ConfigureServices(IServiceCollection services)
options.MaxAge = TimeSpan.FromDays(365);
});

services.AddDataProtectionService(Configuration);

services.AddScoped(sp => sp.GetService<IHttpContextAccessor>()?.HttpContext?.Session);
services.AddSession(options =>
{
Expand Down Expand Up @@ -150,6 +148,9 @@ public void ConfigureServices(IServiceCollection services)
services.Configure<ServiceLinkOptions>(GetConfigurationSectionFor<ServiceLinkOptions>());
services.Configure<AzureAdOptions>(GetConfigurationSectionFor<AzureAdOptions>());
services.Configure<ApplicationInsightsOptions>(GetConfigurationSectionFor<ApplicationInsightsOptions>());
services.Configure<DataProtectionOptions>(GetConfigurationSectionFor<DataProtectionOptions>());

services.AddDataProtectionService(GetTypedConfigurationFor<DataProtectionOptions>());

services.AddScoped<ErrorService>();
services.AddScoped<IGetEstablishment, EstablishmentService>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Config = Dfe.PrepareConversions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.DataProtection;
using System;
Expand All @@ -9,16 +9,16 @@ namespace Dfe.PrepareConversions.Utils
{
internal static class DataProtectionService
{
public static void AddDataProtectionService(this IServiceCollection services, IConfiguration configuration)
public static void AddDataProtectionService(this IServiceCollection services, Config.DataProtectionOptions options)
{
var dp = services.AddDataProtection();
var dpTargetPath = "@/srv/app/storage";
var dpTargetPath = @"/srv/app/storage";

if (Directory.Exists(dpTargetPath)) {
dp.PersistKeysToFileSystem(new DirectoryInfo(dpTargetPath));

// If a Key Vault Key URI is defined, expect to encrypt the keys.xml
string kvProtectionKeyUri = configuration.GetValue<string>("DataProtection:KeyVaultKey");
string kvProtectionKeyUri = options.KeyVaultKey;

if (!string.IsNullOrWhiteSpace(kvProtectionKeyUri))
{
Expand Down
Loading