Added data protection database based support
continuous-integration/drone/pr Build is passing

This commit is contained in:
Khwezi Mngoma
2026-06-14 09:57:24 +02:00
parent 9099610185
commit 4e9e428ab5
8 changed files with 196 additions and 15 deletions
+4 -13
View File
@@ -2,6 +2,7 @@
using LiteCharms.Features.Api;
using LiteCharms.Features.Api.Configuration;
using LiteCharms.Features.Api.Sdk;
using LiteCharms.Features.Postgres;
using Microsoft.AspNetCore.Hosting;
using System.Runtime.InteropServices;
@@ -53,20 +54,10 @@ public static class Api
return services;
}
public static IServiceCollection AddLiteCharmsWebSecurity(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment environment)
public static IServiceCollection AddLiteCharmsWebSecurity(this IServiceCollection services, IConfiguration configuration)
{
string keysFolderPath;
if (OperatingSystem.IsLinux())
keysFolderPath = "/app/shared-keys";
else
keysFolderPath = Path.Combine(environment.ContentRootPath, "obj", "DeveloperDataProtectionKeys");
if (!Directory.Exists(keysFolderPath)) Directory.CreateDirectory(keysFolderPath);
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(keysFolderPath))
.SetApplicationName("MidrandBookshop");
services.AddDataProtection().PersistKeysToDbContext<DataProtectionDbContext>()
.SetApplicationName("LiteCharmsApp");
var configSection = configuration.GetSection(nameof(LiteCharmsSettings));
+23 -2
View File
@@ -1,6 +1,27 @@
namespace LiteCharms.Features.Extensions;
using LiteCharms.Features.Postgres;
namespace LiteCharms.Features.Extensions;
public static class Postgres
{
public const string SchedulerDbConfigName = "PostgresScheduler";
public const string SchedulerDbConfigName = "PostgresScheduler";
public const string DataProtectionDbConfigName = "PostgresDataProtection";
public static IServiceCollection AddDataProtectionDatabase(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString(DataProtectionDbConfigName);
var dataSourceBuilder = new NpgsqlDataSourceBuilder(connectionString);
dataSourceBuilder.ConfigureTypeLoading(options => { options.EnableTypeLoading(false); });
var dataSource = dataSourceBuilder.Build();
services.AddSingleton(dataSource);
services.AddPooledDbContextFactory<DataProtectionDbContext>(options =>
options.UseNpgsql(dataSource));
return services;
}
}