From 5ac05e8c82d52230e505c1187d03ba01546978a7 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Wed, 6 Nov 2024 20:26:14 -0600 Subject: [PATCH 1/4] chore: Update jsonpath-rust to remove `lazy_static` and `once_cell` dependencies, slight performance improvement Signed-off-by: Bryant Biggs --- Cargo.toml | 8 ++++---- kube-client/src/api/entry.rs | 2 +- kube-client/src/client/auth/mod.rs | 11 +++++------ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 62b4d41be..1aa434508 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ async-broadcast = "0.7.0" async-stream = "0.3.5" async-trait = "0.1.64" backoff = "0.4.0" -base64 = "0.22.0" +base64 = "0.22.1" bytes = "1.1.0" chrono = { version = "0.4.34", default-features = false } darling = "0.20.3" @@ -49,7 +49,7 @@ futures = { version = "0.3.17", default-features = false } hashbrown = "0.15.0" home = "0.5.4" http = "1.1.0" -http-body = "1.0.0" +http-body = "1.0.1" http-body-util = "0.1.2" hyper = "1.2.0" hyper-util = "0.1.9" @@ -59,7 +59,7 @@ hyper-socks2 = { version = "0.9.0", default-features = false } hyper-timeout = "0.5.1" json-patch = "3" jsonptr = "0.6" -jsonpath-rust = "0.5.0" +jsonpath-rust = "0.7.3" k8s-openapi = { version = "0.23.0", default-features = false } openssl = "0.10.36" parking_lot = "0.12.0" @@ -68,7 +68,7 @@ pin-project = "1.0.4" proc-macro2 = "1.0.29" quote = "1.0.10" rand = "0.8.3" -rustls = { version = "0.23.0", default-features = false } +rustls = { version = "0.23.16", default-features = false } rustls-pemfile = "2.0.0" schemars = "0.8.6" secrecy = "0.10.2" diff --git a/kube-client/src/api/entry.rs b/kube-client/src/api/entry.rs index 70d7d61cd..14e408fbd 100644 --- a/kube-client/src/api/entry.rs +++ b/kube-client/src/api/entry.rs @@ -134,7 +134,7 @@ enum Dirtiness { New, } -impl<'a, K> OccupiedEntry<'a, K> { +impl OccupiedEntry<'_, K> { /// Borrow the object pub fn get(&self) -> &K { &self.object diff --git a/kube-client/src/client/auth/mod.rs b/kube-client/src/client/auth/mod.rs index 406ca26ca..f112a459e 100644 --- a/kube-client/src/client/auth/mod.rs +++ b/kube-client/src/client/auth/mod.rs @@ -10,7 +10,7 @@ use http::{ header::{InvalidHeaderValue, AUTHORIZATION}, HeaderValue, Request, }; -use jsonpath_rust::{path::config::JsonPathConfig, JsonPathInst}; +use jsonpath_rust::JsonPath; use secrecy::{ExposeSecret, SecretString}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -498,10 +498,9 @@ fn token_from_gcp_provider(provider: &AuthProviderConfig) -> Result Result { - let cfg = JsonPathConfig::default(); // no need for regex caching here let parsed_path = path .trim_matches(|c| c == '"' || c == '{' || c == '}') - .parse::() + .parse::() .map_err(|err| { Error::AuthExec(format!( "Failed to parse {context:?} as a JsonPath: {path}\n @@ -509,7 +508,7 @@ fn extract_value(json: &serde_json::Value, context: &str, path: &str) -> Result< )) })?; - let res = parsed_path.find_slice(json, cfg); + let res = parsed_path.find_slice(json); let Some(res) = res.into_iter().next() else { return Err(Error::AuthExec(format!( @@ -517,12 +516,12 @@ fn extract_value(json: &serde_json::Value, context: &str, path: &str) -> Result< ))); }; - if let Some(val) = res.as_str() { + if let Some(val) = res.clone().to_path() { Ok(val.to_owned()) } else { Err(Error::AuthExec(format!( "Target {:?} value {:?} is not a string: {:?}", - context, path, *res + context, path, res ))) } } From 55c0eb69cb2d1f240a41beeb0fb4fbfa85daf60a Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Thu, 7 Nov 2024 10:31:52 -0600 Subject: [PATCH 2/4] chore: Update example for jsoanpath changes Signed-off-by: Bryant Biggs --- examples/dynamic_jsonpath.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/dynamic_jsonpath.rs b/examples/dynamic_jsonpath.rs index 3fb670b84..04a5827b1 100644 --- a/examples/dynamic_jsonpath.rs +++ b/examples/dynamic_jsonpath.rs @@ -1,5 +1,5 @@ use anyhow::{Context, Error}; -use jsonpath_rust::JsonPathInst; +use jsonpath_rust::JsonPath; use k8s_openapi::api::core::v1::Pod; use kube::{ api::{Api, ListParams}, @@ -18,7 +18,7 @@ async fn main() -> anyhow::Result<()> { let jsonpath = { let path = std::env::var("JSONPATH").unwrap_or_else(|_| ".items[*].spec.containers[*].image".into()); format!("${path}") - .parse::() + .parse::() .map_err(Error::msg) .with_context(|| { format!( @@ -34,8 +34,10 @@ async fn main() -> anyhow::Result<()> { // Use the given JSONPATH to filter the ObjectList let list_json = serde_json::to_value(&list)?; - for res in jsonpath.find_slice(&list_json, Default::default()) { - info!("\t\t {}", *res); + for res in jsonpath.find_slice(&list_json) { + if let Some(path) = res.to_path() { + info!("\t\t: {path}"); + } } Ok(()) } From 563c4f1389f0991912c3637939abbbaaee4e0b84 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Thu, 7 Nov 2024 10:40:26 -0600 Subject: [PATCH 3/4] fix: Extract value, not the json path Signed-off-by: Bryant Biggs --- examples/dynamic_jsonpath.rs | 4 +--- kube-client/src/client/auth/mod.rs | 9 +-------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/examples/dynamic_jsonpath.rs b/examples/dynamic_jsonpath.rs index 04a5827b1..bc4b02d48 100644 --- a/examples/dynamic_jsonpath.rs +++ b/examples/dynamic_jsonpath.rs @@ -35,9 +35,7 @@ async fn main() -> anyhow::Result<()> { // Use the given JSONPATH to filter the ObjectList let list_json = serde_json::to_value(&list)?; for res in jsonpath.find_slice(&list_json) { - if let Some(path) = res.to_path() { - info!("\t\t: {path}"); - } + info!("\t\t {}", res.to_data()); } Ok(()) } diff --git a/kube-client/src/client/auth/mod.rs b/kube-client/src/client/auth/mod.rs index f112a459e..beb94b291 100644 --- a/kube-client/src/client/auth/mod.rs +++ b/kube-client/src/client/auth/mod.rs @@ -516,14 +516,7 @@ fn extract_value(json: &serde_json::Value, context: &str, path: &str) -> Result< ))); }; - if let Some(val) = res.clone().to_path() { - Ok(val.to_owned()) - } else { - Err(Error::AuthExec(format!( - "Target {:?} value {:?} is not a string: {:?}", - context, path, res - ))) - } + Ok(res.to_data().to_string()) } /// ExecCredentials is used by exec-based plugins to communicate credentials to From cbdda8df3853b2777ec893be29257a9a4813ae80 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Sun, 10 Nov 2024 19:49:35 -0600 Subject: [PATCH 4/4] fix: Return string value, not string encoded json value Signed-off-by: Bryant Biggs --- kube-client/src/client/auth/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kube-client/src/client/auth/mod.rs b/kube-client/src/client/auth/mod.rs index beb94b291..f051bba45 100644 --- a/kube-client/src/client/auth/mod.rs +++ b/kube-client/src/client/auth/mod.rs @@ -516,7 +516,12 @@ fn extract_value(json: &serde_json::Value, context: &str, path: &str) -> Result< ))); }; - Ok(res.to_data().to_string()) + let jval = res.to_data(); + let val = jval.as_str().ok_or(Error::AuthExec(format!( + "Target {context:?} value {path:?} is not a string" + )))?; + + Ok(val.to_string()) } /// ExecCredentials is used by exec-based plugins to communicate credentials to