Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade jsonpath-rust to 0.5.0 #1429

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ assert-json-diff = "2.0.1"
garde = { version = "0.18.0", default-features = false, features = ["derive"] }
anyhow = "1.0.44"
futures = "0.3.17"
jsonpath-rust = "0.4.0"
jsonpath-rust = "0.5.0"
kube = { path = "../kube", version = "^0.88.1", default-features = false, features = ["admission"] }
kube-derive = { path = "../kube-derive", version = "^0.88.1", default-features = false } # only needed to opt out of schema
k8s-openapi = { version = "0.21.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion examples/dynamic_jsonpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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) {
for res in jsonpath.find_slice(&list_json, Default::default()) {
info!("\t\t {}", *res);
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion kube-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ rustls-pemfile = { version = "1.0.0", optional = true }
bytes = { version = "1.1.0", optional = true }
tokio = { version = "1.14.0", features = ["time", "signal", "sync"], optional = true }
kube-core = { path = "../kube-core", version = "=0.88.1" }
jsonpath-rust = { version = "0.4.0", optional = true }
jsonpath-rust = { version = "0.5.0", optional = true }
tokio-util = { version = "0.7.0", optional = true, features = ["io", "codec"] }
hyper = { version = "0.14.13", optional = true, features = ["client", "http1", "stream", "tcp"] }
hyper-rustls = { version = "0.24.0", optional = true }
Expand Down
5 changes: 3 additions & 2 deletions kube-client/src/client/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
header::{InvalidHeaderValue, AUTHORIZATION},
HeaderValue, Request,
};
use jsonpath_rust::JsonPathInst;
use jsonpath_rust::{path::config::JsonPathConfig, JsonPathInst};
use secrecy::{ExposeSecret, SecretString};
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -130,12 +130,12 @@
path: path.as_ref().to_owned(),
token: SecretString::from(token),
// Try to reload at least once a minute
expires_at: Utc::now() + Duration::seconds(60),

Check warning on line 133 in kube-client/src/client/auth/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead

warning: use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead --> kube-client/src/client/auth/mod.rs:133:48 | 133 | expires_at: Utc::now() + Duration::seconds(60), | ^^^^^^^

Check warning on line 133 in kube-client/src/client/auth/mod.rs

View workflow job for this annotation

GitHub Actions / msrv

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead
})
}

fn is_expiring(&self) -> bool {
Utc::now() + Duration::seconds(10) > self.expires_at

Check warning on line 138 in kube-client/src/client/auth/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead

warning: use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead --> kube-client/src/client/auth/mod.rs:138:32 | 138 | Utc::now() + Duration::seconds(10) > self.expires_at | ^^^^^^^

Check warning on line 138 in kube-client/src/client/auth/mod.rs

View workflow job for this annotation

GitHub Actions / msrv

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead
}

/// Get the cached token. Returns `None` if it's expiring.
Expand All @@ -153,7 +153,7 @@
if let Ok(token) = std::fs::read_to_string(&self.path) {
self.token = SecretString::from(token);
}
self.expires_at = Utc::now() + Duration::seconds(60);

Check warning on line 156 in kube-client/src/client/auth/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead

warning: use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead --> kube-client/src/client/auth/mod.rs:156:54 | 156 | self.expires_at = Utc::now() + Duration::seconds(60); | ^^^^^^^

Check warning on line 156 in kube-client/src/client/auth/mod.rs

View workflow job for this annotation

GitHub Actions / msrv

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead
}
self.token.expose_secret()
}
Expand Down Expand Up @@ -205,7 +205,7 @@
let mut locked_data = data.lock().await;
// Add some wiggle room onto the current timestamp so we don't get any race
// conditions where the token expires while we are refreshing
if Utc::now() + Duration::seconds(60) >= locked_data.1 {

Check warning on line 208 in kube-client/src/client/auth/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead

warning: use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead --> kube-client/src/client/auth/mod.rs:208:43 | 208 | if Utc::now() + Duration::seconds(60) >= locked_data.1 { | ^^^^^^^ | = note: `#[warn(deprecated)]` on by default

Check warning on line 208 in kube-client/src/client/auth/mod.rs

View workflow job for this annotation

GitHub Actions / msrv

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead
// TODO Improve refreshing exec to avoid `Auth::try_from`
match Auth::try_from(&locked_data.2)? {
Auth::None | Auth::Basic(_, _) | Auth::Bearer(_) | Auth::Certificate(_, _) => {
Expand Down Expand Up @@ -410,7 +410,7 @@
let expiry_date = expiry
.parse::<DateTime<Utc>>()
.map_err(Error::MalformedTokenExpirationDate)?;
if Utc::now() + Duration::seconds(60) < expiry_date {

Check warning on line 413 in kube-client/src/client/auth/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead

warning: use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead --> kube-client/src/client/auth/mod.rs:413:39 | 413 | if Utc::now() + Duration::seconds(60) < expiry_date { | ^^^^^^^

Check warning on line 413 in kube-client/src/client/auth/mod.rs

View workflow job for this annotation

GitHub Actions / msrv

use of deprecated associated function `chrono::TimeDelta::seconds`: Use `TimeDelta::try_seconds` instead
return Ok(ProviderToken::GcpCommand(access_token.clone(), Some(expiry_date)));
}
}
Expand Down Expand Up @@ -479,6 +479,7 @@
}

fn extract_value(json: &serde_json::Value, context: &str, path: &str) -> Result<String, Error> {
let cfg = JsonPathConfig::default(); // no need for regex caching here
let parsed_path = path
.trim_matches(|c| c == '"' || c == '{' || c == '}')
.parse::<JsonPathInst>()
Expand All @@ -489,7 +490,7 @@
))
})?;

let res = parsed_path.find_slice(json);
let res = parsed_path.find_slice(json, cfg);

let Some(res) = res.into_iter().next() else {
return Err(Error::AuthExec(format!(
Expand Down
Loading