Added redis

This commit is contained in:
Mia Rose Winter 2024-01-21 21:03:06 +01:00
parent d7cd8f4e41
commit 3dc6bffe63
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
3 changed files with 40 additions and 0 deletions

View file

@ -1,8 +1,13 @@
using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Server; using Microsoft.AspNetCore.Components.Server;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Diagnostics.Metrics;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using StackExchange.Redis;
using Tomlyn.Extensions.Configuration; using Tomlyn.Extensions.Configuration;
using Wave.Components; using Wave.Components;
using Wave.Components.Account; using Wave.Components.Account;
@ -21,6 +26,27 @@
builder.Services.AddRazorComponents().AddInteractiveServerComponents(); builder.Services.AddRazorComponents().AddInteractiveServerComponents();
builder.Services.AddControllers(); builder.Services.AddControllers();
#region Data Protection & Redis
if (builder.Configuration.GetConnectionString("Redis") is { } redisUri) {
var redis = ConnectionMultiplexer.Connect(redisUri);
builder.Services.AddDataProtection()
.PersistKeysToStackExchangeRedis(redis)
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration() {
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
} else {
builder.Services.AddDataProtection()
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration() {
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
Console.WriteLine("No Redis connection string found.");
}
#endregion
#region Authentication & Authorization #region Authentication & Authorization
builder.Services.AddCascadingAuthenticationState(); builder.Services.AddCascadingAuthenticationState();
@ -80,6 +106,7 @@
builder.Services.AddScoped<IEmailSender<ApplicationUser>, SmtpEmailSender>(); builder.Services.AddScoped<IEmailSender<ApplicationUser>, SmtpEmailSender>();
} else { } else {
builder.Services.AddSingleton<IEmailSender<ApplicationUser>, IdentityNoOpEmailSender>(); builder.Services.AddSingleton<IEmailSender<ApplicationUser>, IdentityNoOpEmailSender>();
Console.WriteLine("No Email provider configured.");
} }
#endregion #endregion

View file

@ -16,6 +16,7 @@
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="13.5.0" /> <PackageReference Include="Magick.NET-Q8-AnyCPU" Version="13.5.0" />
<PackageReference Include="MailKit" Version="4.3.0" /> <PackageReference Include="MailKit" Version="4.3.0" />
<PackageReference Include="Markdig" Version="0.34.0" /> <PackageReference Include="Markdig" Version="0.34.0" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />

View file

@ -14,11 +14,14 @@ services:
- database:db - database:db
environment: environment:
- "WAVE_ConnectionStrings__DefaultConnection=Host=db; Username=wave; Password=development" - "WAVE_ConnectionStrings__DefaultConnection=Host=db; Username=wave; Password=development"
- "WAVE_ConnectionStrings__Redis=redis,password=development"
volumes: volumes:
- wave-files:/app/files - wave-files:/app/files
- wave-config:/configuration - wave-config:/configuration
networks: networks:
- wave - wave
depends_on:
- database
database: database:
image: postgres:16.1-alpine image: postgres:16.1-alpine
restart: unless-stopped restart: unless-stopped
@ -28,6 +31,14 @@ services:
- "POSTGRES_PASSWORD=development" - "POSTGRES_PASSWORD=development"
volumes: volumes:
- wave-db:/var/lib/postgresql/data - wave-db:/var/lib/postgresql/data
networks:
- wave
redis:
image: redis:7-alpine
restart: unless-stopped
command: redis-server --requirepass development --save 60 1 --loglevel warning
volumes:
- wave-redis:/data
networks: networks:
- wave - wave
@ -35,5 +46,6 @@ volumes:
wave-files: wave-files:
wave-config: wave-config:
wave-db: wave-db:
wave-redis:
networks: networks:
wave: wave: