From a40a3adaddd982bf718671ccff88802fa3660447 Mon Sep 17 00:00:00 2001 From: bill fumerola Date: Thu, 12 Jun 2025 16:41:59 -0700 Subject: [PATCH 1/2] fix(http): include tokio time feature --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9cd9655..856f600 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,7 +121,7 @@ json-builtins = ["dep:json-patch"] units-builtins = ["dep:parse-size"] rand-builtins = ["rng"] yaml-builtins = ["dep:serde_yaml"] -http-builtins = ["http", "dep:serde_yaml", "dep:duration-str"] +http-builtins = ["http", "dep:serde_yaml", "dep:duration-str", "tokio/time"] urlquery-builtins = ["dep:form_urlencoded", "dep:urlencoding"] time-builtins = ["time", "dep:chrono-tz", "dep:duration-str", "dep:chronoutil"] From e603e056cf1c0c9c1a5b57207caba1688b009c42 Mon Sep 17 00:00:00 2001 From: bill fumerola Date: Thu, 12 Jun 2025 16:52:08 -0700 Subject: [PATCH 2/2] chore(clippy): cast max_retry_attempts into u32 earlier --- src/builtins/impls/http.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/builtins/impls/http.rs b/src/builtins/impls/http.rs index 0586b3a..6ced4b3 100644 --- a/src/builtins/impls/http.rs +++ b/src/builtins/impls/http.rs @@ -107,6 +107,7 @@ async fn internal_send( let max_retry_attempts = opa_req .get("max_retry_attempts") .and_then(serde_json::Value::as_u64) + .and_then(|r| u32::try_from(r).ok()) .unwrap_or(0); let mut http_resp_res: Result> = Err(anyhow::anyhow!("unreachable")); @@ -119,8 +120,7 @@ async fn internal_send( break; } if max_retry_attempts > 0 { - #[allow(clippy::cast_possible_truncation)] - sleep(Duration::from_millis(500 * 2_u64.pow(attempt as u32))).await; + sleep(Duration::from_millis(500 * 2_u64.pow(attempt))).await; } } @@ -210,8 +210,10 @@ fn convert_http_resp_to_opa_resp( opa_resp["body"] = parsed_body; } } else if force_yaml_decode - || content_type == Some("application/yaml") - || content_type == Some("application/x-yaml") + || matches!( + content_type, + Some("application/yaml" | "application/x-yaml") + ) { if let Ok(parsed_body) = serde_yaml::from_str::(&raw_resp_body) { opa_resp["body"] = parsed_body;