diff options
Diffstat (limited to 'src/marlin.web/Data/ApplicationDbContext.cs')
| -rw-r--r-- | src/marlin.web/Data/ApplicationDbContext.cs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/marlin.web/Data/ApplicationDbContext.cs b/src/marlin.web/Data/ApplicationDbContext.cs index 41ec4bc..2e05835 100644 --- a/src/marlin.web/Data/ApplicationDbContext.cs +++ b/src/marlin.web/Data/ApplicationDbContext.cs @@ -1,15 +1,31 @@ namespace marlin.web.Data; using System.Linq.Expressions; +using System.Text.Json; using core; using core.models; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Models; + +// user-based session grant +// agent id/token grant +// agent job claim session grant +// service grant +public interface IActiveGrant +{ + bool CanAccessSource(Guid sourceId); +} public class ApplicationDbContext : DbContext { public DbSet<VersionControlSource> Sources => this.Set<VersionControlSource>(); + public DbSet<VersionControlledBranch> SourceBranches => this.Set<VersionControlledBranch>(); + public DbSet<VersionControlledCommit> SourceCommits => this.Set<VersionControlledCommit>(); + public DbSet<VersionControlledBlob> SourceBlobs => this.Set<VersionControlledBlob>(); + public DbSet<VersionControlSecret> Secrets => this.Set<VersionControlSecret>(); public DbSet<Job> Jobs => this.Set<Job>(); + public DbSet<Agent> Agents => this.Set<Agent>(); public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } @@ -18,7 +34,21 @@ public class ApplicationDbContext : DbContext { modelBuilder .Entity<Agent>() - .OwnsOne(p => p.Capabilities, b => b.ToJson()); + .Property(p => p.Capabilities) + .HasConversion( + v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null), + v => JsonSerializer.Deserialize<CapabilitySet>(v, (JsonSerializerOptions?)null)!); + + modelBuilder + .Entity<VersionControlledCommit>() + .HasAlternateKey(x => new { x.SourceId, x.Hash }); + + modelBuilder + .Entity<VersionControlSecret>() + .Property(p => p.Content) + .HasConversion( + v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null), + v => JsonSerializer.Deserialize<Dictionary<string, string>>(v, (JsonSerializerOptions?)null)!); base.OnModelCreating(modelBuilder); } |
