using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using ScadaLink.Commons.Entities.InboundApi; namespace ScadaLink.ConfigurationDatabase.Configurations; public class ApiKeyConfiguration : IEntityTypeConfiguration { /// Configures the EF Core mapping for the entity. /// Entity type builder used to apply the configuration. public void Configure(EntityTypeBuilder builder) { builder.HasKey(k => k.Id); builder.Property(k => k.Name) .IsRequired() .HasMaxLength(200); // ConfigurationDatabase-012: the bearer credential is persisted only as a // deterministic HMAC-SHA256 hash, never as plaintext. Base64 of a 32-byte // HMAC-SHA256 digest is 44 characters; 256 leaves generous headroom. builder.Property(k => k.KeyHash) .IsRequired() .HasMaxLength(256); builder.HasIndex(k => k.Name).IsUnique(); builder.HasIndex(k => k.KeyHash).IsUnique(); } } public class ApiMethodConfiguration : IEntityTypeConfiguration { /// Configures the EF Core mapping for the entity. /// Entity type builder used to apply the configuration. public void Configure(EntityTypeBuilder builder) { builder.HasKey(m => m.Id); builder.Property(m => m.Name) .IsRequired() .HasMaxLength(200); builder.Property(m => m.Script) .IsRequired(); builder.Property(m => m.ApprovedApiKeyIds) .HasMaxLength(4000); builder.Property(m => m.ParameterDefinitions) .HasMaxLength(4000); builder.Property(m => m.ReturnDefinition) .HasMaxLength(4000); builder.HasIndex(m => m.Name).IsUnique(); } }