From ff33263df308efce402bf731b48aa584f5295321 Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Sat, 25 Apr 2026 03:05:40 +0300 Subject: [PATCH] feat: Add configurable limits for bytes and amount validation via environment variables - Add MAX_BYTES_LIMIT environment variable to configure bytes validation limit (defaults to 1TB) - Add MAX_AMOUNT_LIMIT environment variable to configure amount validation limit (defaults to 10,000) - Replace hardcoded 1_000_000_000_000 bytes limit with configurable max_bytes value - Replace hardcoded 10_000.0 amount limit with configurable max_amount value --- apps/charging-engine/src/errors/helpers.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/charging-engine/src/errors/helpers.rs b/apps/charging-engine/src/errors/helpers.rs index 4134fd1..868ce8d 100644 --- a/apps/charging-engine/src/errors/helpers.rs +++ b/apps/charging-engine/src/errors/helpers.rs @@ -61,7 +61,13 @@ pub fn validate_bytes(bytes: u64) -> ChargingResult<()> { return Err(ChargingError::InvalidInput("Bytes cannot be zero".to_string())); } - if bytes > 1_000_000_000_000 { // 1TB limit + // Configurable via MAX_BYTES_LIMIT, defaults to 1TB + let max_bytes: u64 = std::env::var("MAX_BYTES_LIMIT") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(1_000_000_000_000); + + if bytes > max_bytes { return Err(ChargingError::InvalidInput("Bytes exceed maximum limit".to_string())); } @@ -85,7 +91,13 @@ pub fn validate_amount(amount: f64) -> ChargingResult<()> { return Err(ChargingError::InvalidInput("Amount must be positive".to_string())); } - if amount > 10_000.0 { + // Configurable via MAX_AMOUNT_LIMIT, defaults to 10,000 + let max_amount: f64 = std::env::var("MAX_AMOUNT_LIMIT") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(10_000.0); + + if amount > max_amount { return Err(ChargingError::InvalidInput("Amount exceeds maximum limit".to_string())); }