refactor: replace unmaintained chrono with time (RUSTSEC-2026-0543)
Adds a timeutil module (unix_now, is_valid_unix, RFC 3339 format/parse) and moves ClickHouse event timestamps to time::serde::rfc3339. cargo deny is green again.
This commit is contained in:
parent
f25dc3558a
commit
e2adf8601c
19 changed files with 74 additions and 128 deletions
|
|
@ -34,7 +34,7 @@ async fn backfill(state: &AppState) -> ApiResult<usize> {
|
|||
.get_multiplexed_async_connection()
|
||||
.await
|
||||
.map_err(redis_unavailable)?;
|
||||
let now = chrono::Utc::now().timestamp();
|
||||
let now = crate::timeutil::unix_now();
|
||||
let mut cursor = 0_u64;
|
||||
let mut filled = 0_usize;
|
||||
loop {
|
||||
|
|
|
|||
|
|
@ -46,9 +46,7 @@ pub(super) fn legacy_metadata(now: i64) -> BlacklistMetadata {
|
|||
}
|
||||
|
||||
pub(super) fn format_timestamp(timestamp: i64) -> String {
|
||||
chrono::DateTime::from_timestamp(timestamp, 0)
|
||||
.map(|value| value.to_rfc3339())
|
||||
.unwrap_or_else(|| chrono::Utc::now().to_rfc3339())
|
||||
crate::timeutil::format_rfc3339(timestamp).unwrap_or_else(crate::timeutil::now_rfc3339)
|
||||
}
|
||||
|
||||
pub(super) fn event_payload(
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ pub async fn list_blacklist(
|
|||
.take(usize::try_from(limit).unwrap_or(usize::MAX))
|
||||
.collect();
|
||||
let metadata = load_metadata(&mut conn, &page).await?;
|
||||
let now = chrono::Utc::now().timestamp();
|
||||
let now = crate::timeutil::unix_now();
|
||||
let items = page
|
||||
.iter()
|
||||
.filter_map(|target| entry(target, metadata.get(target), now))
|
||||
|
|
@ -116,8 +116,8 @@ fn entry(target: &str, metadata: Option<&Option<BlacklistMetadata>>, now: i64) -
|
|||
None => legacy_metadata(now),
|
||||
};
|
||||
if record.expires_at_unix <= now
|
||||
|| chrono::DateTime::from_timestamp(record.created_at_unix, 0).is_none()
|
||||
|| chrono::DateTime::from_timestamp(record.expires_at_unix, 0).is_none()
|
||||
|| !crate::timeutil::is_valid_unix(record.created_at_unix)
|
||||
|| !crate::timeutil::is_valid_unix(record.expires_at_unix)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ pub async fn add_blacklist(
|
|||
}
|
||||
|
||||
let target = ip.to_string();
|
||||
let created_at_unix = chrono::Utc::now().timestamp();
|
||||
let created_at_unix = crate::timeutil::unix_now();
|
||||
let metadata = super::common::BlacklistMetadata {
|
||||
created_at_unix,
|
||||
expires_at_unix: created_at_unix + duration_secs as i64,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub struct Claims {
|
|||
}
|
||||
|
||||
pub fn create_token(secret: &str, expiration: u64, audience: &str) -> Result<String, jsonwebtoken::errors::Error> {
|
||||
let now = chrono::Utc::now().timestamp() as usize;
|
||||
let now = crate::timeutil::unix_now() as usize;
|
||||
let claims = Claims {
|
||||
sub: "rampart-admin".to_string(),
|
||||
aud: audience.to_string(),
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ async fn check_nodes(state: &AppState) -> anyhow::Result<()> {
|
|||
let mut conn = state.redis_client.get_multiplexed_async_connection().await?;
|
||||
let keys = collect_node_keys(&mut conn).await?;
|
||||
|
||||
let now = chrono::Utc::now().timestamp();
|
||||
let now = crate::timeutil::unix_now();
|
||||
|
||||
for key in &keys {
|
||||
let raw: Option<String> = conn.get(key).await?;
|
||||
|
|
@ -73,8 +73,7 @@ pub fn offline_update(raw: &str, now: i64) -> Option<String> {
|
|||
let mut node = serde_json::from_str::<serde_json::Value>(raw).ok()?;
|
||||
let hb = node["last_heartbeat"]
|
||||
.as_str()
|
||||
.and_then(|s| chrono::DateTime::parse_from_rfc3339(s).ok())
|
||||
.map(|t| t.timestamp())
|
||||
.and_then(crate::timeutil::parse_rfc3339_unix)
|
||||
.unwrap_or(0);
|
||||
if now - hb <= NODE_TTL_SECS {
|
||||
return None;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue