mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-22 20:08:48 +00:00
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:
@@ -61,7 +61,13 @@ pub fn validate_bytes(bytes: u64) -> ChargingResult<()> {
|
|||||||
return Err(ChargingError::InvalidInput("Bytes cannot be zero".to_string()));
|
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()));
|
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()));
|
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()));
|
return Err(ChargingError::InvalidInput("Amount exceeds maximum limit".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user