fengling-risk-control/Fengling.RiskControl.Client/Configuration/RiskControlClientOptions.cs
Sam 293209b1dc feat: add Fengling.RiskControl.Client SDK
- Implement RedisCounterService for rate limiting
- Implement RuleLoader with timer refresh
- Implement RiskEvaluator for local rule evaluation
- Implement SamplingService for CAP events
- Implement CapEventPublisher for async event publishing
- Implement FailoverStrategy for Redis failure handling
- Add configuration classes and DI extensions
- Add unit tests (9 tests)
- Add NuGet publishing script
2026-02-06 00:16:53 +08:00

62 lines
1.9 KiB
C#

namespace Fengling.RiskControl.Configuration;
public class RiskControlClientOptions
{
public RedisOptions Redis { get; set; } = new();
public EvaluationOptions Evaluation { get; set; } = new();
public CapOptions Cap { get; set; } = new();
public SamplingOptions Sampling { get; set; } = new();
public FailoverOptions RedisFailover { get; set; } = new();
public ReconciliationOptions Reconciliation { get; set; } = new();
}
public class RedisOptions
{
public string ConnectionString { get; set; } = "localhost:6379";
public string KeyPrefix { get; set; } = "fengling:risk:";
public int DefaultTtlSeconds { get; set; } = 7200;
}
public class EvaluationOptions
{
public int RuleRefreshIntervalSeconds { get; set; } = 30;
public int HighRiskThreshold { get; set; } = 70;
public int MediumRiskThreshold { get; set; } = 30;
}
public class CapOptions
{
public bool PublisherEnabled { get; set; } = true;
public string ConnectionName { get; set; } = "Fengling.RiskControl";
}
public class SamplingOptions
{
public bool Enabled { get; set; } = true;
public double DefaultRate { get; set; } = 0.01;
public List<SamplingRule> Rules { get; set; } = new();
}
public class SamplingRule
{
public string Condition { get; set; } = string.Empty;
public double Rate { get; set; } = 0.01;
}
public class FailoverOptions
{
public bool Enabled { get; set; } = true;
public int QuickFailThresholdSeconds { get; set; } = 5;
public int DenyNewUsersThresholdSeconds { get; set; } = 30;
public string Strategy { get; set; } = "DenyNewUsers";
public bool FallbackToRulesOnly { get; set; } = false;
}
public class ReconciliationOptions
{
public bool Enabled { get; set; } = true;
public string Schedule { get; set; } = "0 4 * * *";
public int Threshold { get; set; } = 5;
public int BatchSize { get; set; } = 1000;
}