(value: &str)
| 2683 | |
| 2684 | #[allow(clippy::cast_possible_truncation)] |
| 2685 | fn parse_cpu_limit(value: &str) -> Result<Option<i64>, Status> { |
| 2686 | let value = value.trim(); |
| 2687 | if value.is_empty() { |
| 2688 | return Ok(None); |
| 2689 | } |
| 2690 | if let Some(millicores) = value.strip_suffix('m') { |
| 2691 | let millicores = millicores.parse::<i64>().map_err(|_| { |
| 2692 | Status::failed_precondition(format!( |
| 2693 | "invalid docker cpu_limit '{value}'; expected an integer or millicore quantity", |
| 2694 | )) |
| 2695 | })?; |
| 2696 | if millicores <= 0 { |
| 2697 | return Err(Status::failed_precondition( |
| 2698 | "docker cpu_limit must be greater than zero", |
| 2699 | )); |
| 2700 | } |
| 2701 | return Ok(Some(millicores.saturating_mul(1_000_000))); |
| 2702 | } |
| 2703 | |
| 2704 | let cores = value.parse::<f64>().map_err(|_| { |
| 2705 | Status::failed_precondition(format!( |
| 2706 | "invalid docker cpu_limit '{value}'; expected an integer or millicore quantity", |
| 2707 | )) |
| 2708 | })?; |
| 2709 | if !cores.is_finite() || cores <= 0.0 { |
| 2710 | return Err(Status::failed_precondition( |
| 2711 | "docker cpu_limit must be greater than zero", |
| 2712 | )); |
| 2713 | } |
| 2714 | |
| 2715 | Ok(Some((cores * 1_000_000_000.0).round() as i64)) |
| 2716 | } |
| 2717 | |
| 2718 | #[allow(clippy::cast_possible_truncation)] |
| 2719 | fn parse_memory_limit(value: &str) -> Result<Option<i64>, Status> { |
no test coverage detected