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
This commit is contained in:
nutcas3
2026-04-25 03:05:40 +03:00
parent c4746970a2
commit ff33263df3
+14 -2
View File
@@ -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()));
}