feat(rate-limiting): Implement core rate limiting functionality with configuration, decision-making, metrics, middleware, and service registration
- Add RateLimitConfig for configuration management with YAML binding support. - Introduce RateLimitDecision to encapsulate the result of rate limit checks. - Implement RateLimitMetrics for OpenTelemetry metrics tracking. - Create RateLimitMiddleware for enforcing rate limits on incoming requests. - Develop RateLimitService to orchestrate instance and environment rate limit checks. - Add RateLimitServiceCollectionExtensions for dependency injection registration.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using StellaOps.Signer.KeyManagement.Entities;
|
||||
|
||||
namespace StellaOps.Signer.KeyManagement;
|
||||
|
||||
/// <summary>
|
||||
/// DbContext for key management entities.
|
||||
/// </summary>
|
||||
public class KeyManagementDbContext : DbContext
|
||||
{
|
||||
public KeyManagementDbContext(DbContextOptions<KeyManagementDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Key history entries.
|
||||
/// </summary>
|
||||
public DbSet<KeyHistoryEntity> KeyHistory => Set<KeyHistoryEntity>();
|
||||
|
||||
/// <summary>
|
||||
/// Key audit log entries.
|
||||
/// </summary>
|
||||
public DbSet<KeyAuditLogEntity> KeyAuditLog => Set<KeyAuditLogEntity>();
|
||||
|
||||
/// <summary>
|
||||
/// Trust anchors.
|
||||
/// </summary>
|
||||
public DbSet<TrustAnchorEntity> TrustAnchors => Set<TrustAnchorEntity>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.HasDefaultSchema("signer");
|
||||
|
||||
modelBuilder.Entity<KeyHistoryEntity>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.HistoryId);
|
||||
entity.HasIndex(e => new { e.AnchorId, e.KeyId }).IsUnique();
|
||||
entity.HasIndex(e => e.AnchorId);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<KeyAuditLogEntity>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.LogId);
|
||||
entity.HasIndex(e => e.AnchorId);
|
||||
entity.HasIndex(e => e.CreatedAt).IsDescending();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<TrustAnchorEntity>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.AnchorId);
|
||||
entity.HasIndex(e => e.PurlPattern);
|
||||
entity.HasIndex(e => e.IsActive);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user