Skip to content

Commit

Permalink
Added DataProtectionKey migration and updated the DB (#192)
Browse files Browse the repository at this point in the history
* Added DataProtectionKey migration and updated the DB

* Update 20240701174941_DataProtection.cs

* dotnet format

---------

Co-authored-by: Ryan Maffit <[email protected]>
  • Loading branch information
amahdysancsoft and rmaffitsancsoft authored Jul 2, 2024
1 parent db76ead commit d84b7e1
Show file tree
Hide file tree
Showing 6 changed files with 1,380 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/dotnet/HQ.Server/Commands/APICommand.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
using System.Security.Claims;

using Duende.AccessTokenManagement.OpenIdConnect;

using HQ.Server.API;
using HQ.Server.API;
using HQ.Server.Authorization;
using HQ.Server.Data;
using HQ.Server.Services;

using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;

using Npgsql;

using Spectre.Console.Cli;

using Swashbuckle.AspNetCore.Filters;
Expand All @@ -39,6 +34,8 @@ public override async Task<int> ExecuteAsync(CommandContext context)
builder.Services.AddHealthChecks();
builder.Services.AddHQServices(builder.Configuration);
builder.Services.AddHQDbContext(builder.Configuration);
builder.Services.AddDataProtection()
.PersistKeysToDbContext<HQDbContext>();

builder.Services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
builder.Services.AddSwaggerGen(c =>
Expand Down
4 changes: 3 additions & 1 deletion src/dotnet/HQ.Server/Data/HQDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

using HQ.Server.Data.Models;

using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace HQ.Server.Data
{
public class HQDbContext : DbContext
public class HQDbContext : DbContext, IDataProtectionKeyContext
{
public DbSet<Book> Books { get; set; } = null!;
public DbSet<ChargeCode> ChargeCodes { get; set; } = null!;
public DbSet<DataProtectionKey> DataProtectionKeys { get; set; } = null!;
public DbSet<Client> Clients { get; set; } = null!;
public DbSet<Expense> Expenses { get; set; } = null!;
public DbSet<Holiday> Holidays { get; set; } = null!;
Expand Down
Loading

0 comments on commit d84b7e1

Please sign in to comment.