Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Failing after 10m14s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Has been skipped
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
Security Vulnerability Scan / Check for Dependency Changes (push) Failing after 11m25s
Security Vulnerability Scan / Composer Security Audit (push) Has been cancelled
- Remove middleware reference from Gitea Traefik labels (caused routing issues) - Optimize Gitea connection pool settings (MAX_IDLE_CONNS=30, authentication_timeout=180s) - Add explicit service reference in Traefik labels - Fix intermittent 504 timeouts by improving PostgreSQL connection handling Fixes Gitea unreachability via git.michaelschiemer.de
110 lines
3.2 KiB
PHP
110 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\ExceptionHandling\RateLimit;
|
|
|
|
use App\Framework\Core\ValueObjects\Duration;
|
|
|
|
/**
|
|
* Exception Rate Limit Configuration
|
|
*
|
|
* Immutable configuration for exception rate limiting.
|
|
*/
|
|
final readonly class ExceptionRateLimitConfig
|
|
{
|
|
/**
|
|
* @param int $maxExceptions Maximum number of exceptions allowed per time window
|
|
* @param Duration $timeWindow Time window for rate limiting
|
|
* @param bool $enabled Whether rate limiting is enabled
|
|
* @param bool $skipLoggingOnLimit Whether to skip logging when rate limit is reached
|
|
* @param bool $skipAuditOnLimit Whether to skip audit logging when rate limit is reached
|
|
* @param bool $trackMetricsOnLimit Whether to track metrics even when rate limit is reached
|
|
*/
|
|
public function __construct(
|
|
public int $maxExceptions = 10,
|
|
public Duration $timeWindow = new Duration(60), // 1 minute default
|
|
public bool $enabled = true,
|
|
public bool $skipLoggingOnLimit = true,
|
|
public bool $skipAuditOnLimit = true,
|
|
public bool $trackMetricsOnLimit = true
|
|
) {
|
|
if ($this->maxExceptions < 1) {
|
|
throw new \InvalidArgumentException('maxExceptions must be at least 1');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create default configuration
|
|
*/
|
|
public static function default(): self
|
|
{
|
|
return new self();
|
|
}
|
|
|
|
/**
|
|
* Create configuration with custom limits
|
|
*/
|
|
public static function withLimits(int $maxExceptions, Duration $timeWindow): self
|
|
{
|
|
return new self(
|
|
maxExceptions: $maxExceptions,
|
|
timeWindow: $timeWindow
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create disabled configuration
|
|
*/
|
|
public static function disabled(): self
|
|
{
|
|
return new self(enabled: false);
|
|
}
|
|
|
|
/**
|
|
* Create new instance with different max exceptions
|
|
*/
|
|
public function withMaxExceptions(int $maxExceptions): self
|
|
{
|
|
return new self(
|
|
maxExceptions: $maxExceptions,
|
|
timeWindow: $this->timeWindow,
|
|
enabled: $this->enabled,
|
|
skipLoggingOnLimit: $this->skipLoggingOnLimit,
|
|
skipAuditOnLimit: $this->skipAuditOnLimit,
|
|
trackMetricsOnLimit: $this->trackMetricsOnLimit
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create new instance with different time window
|
|
*/
|
|
public function withTimeWindow(Duration $timeWindow): self
|
|
{
|
|
return new self(
|
|
maxExceptions: $this->maxExceptions,
|
|
timeWindow: $timeWindow,
|
|
enabled: $this->enabled,
|
|
skipLoggingOnLimit: $this->skipLoggingOnLimit,
|
|
skipAuditOnLimit: $this->skipAuditOnLimit,
|
|
trackMetricsOnLimit: $this->trackMetricsOnLimit
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create new instance with enabled/disabled state
|
|
*/
|
|
public function withEnabled(bool $enabled): self
|
|
{
|
|
return new self(
|
|
maxExceptions: $this->maxExceptions,
|
|
timeWindow: $this->timeWindow,
|
|
enabled: $enabled,
|
|
skipLoggingOnLimit: $this->skipLoggingOnLimit,
|
|
skipAuditOnLimit: $this->skipAuditOnLimit,
|
|
trackMetricsOnLimit: $this->trackMetricsOnLimit
|
|
);
|
|
}
|
|
}
|
|
|