Skip to content

Commit

Permalink
Merge pull request #100 from influxdata/serde_json_path
Browse files Browse the repository at this point in the history
chore: Use serde_json_path library
  • Loading branch information
Marko Mikulicic authored Nov 8, 2023
2 parents b3bc1a2 + a3e949c commit 49e536e
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 9 deletions.
88 changes: 87 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ futures = "0.3"
kube = { version = "0.85.0", features = ["runtime", "derive"] }
kube-derive = "0.84.0"
k8s-openapi = { version = "0.19.0", features = ["v1_26"] }
kubert = { version = "0.19.0", features = ["clap", "runtime", "server", "rustls-tls"] }
kubert = { version = "0.19.0", features = [
"clap",
"runtime",
"server",
"rustls-tls",
] }
tokio = { version = "1.26", features = ["full"] }
anyhow = { version = "1", features = ["backtrace"] }
tracing = "0.1"
schemars = "0.8.15"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_yaml = "0.9.25"
jsonpath_lib = "0.3.0"
thiserror = "1"
serde_json_path = "0.6.3"

[dev-dependencies]
rstest = "0.17.0"
11 changes: 6 additions & 5 deletions src/controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use futures::StreamExt;
use serde_json_path::JsonPath;
use std::{collections::BTreeMap, sync::Arc, time::Duration};

use k8s_openapi::api::core::v1::Secret;
Expand Down Expand Up @@ -356,11 +357,11 @@ where
} else {
"$".to_string()
};
match jsonpath_lib::select(&resource_json, &from_field_path)?.as_slice() {
[] => Ok(json!(null)),
[subtree] => Ok((*subtree).clone()),
_ => Err(Error::JsonPathExactlyOneValue(from_field_path.to_owned())),
}
let subtree = JsonPath::parse(&from_field_path)?
.query(&resource_json)
.at_most_one()
.map_err(|_| Error::JsonPathExactlyOneValue(from_field_path.to_owned()))?;
Ok(subtree.cloned().unwrap_or(json!(null)))
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum Error {
SerializationError(#[from] serde_json::Error),

#[error("JsonPathError: {0}")]
JsonPathError(#[from] jsonpath_lib::JsonPathError),
JsonPathError(#[from] serde_json_path::ParseError),

#[error("Namespace is required")]
NamespaceRequired,
Expand Down

0 comments on commit 49e536e

Please sign in to comment.