From cccda67c1e8c6c41e8b7a413e88bd0a56eb0a610 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 18:02:59 +0000 Subject: [PATCH 1/2] chore(deps): bump chrono from 0.4.34 to 0.4.35 Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.34 to 0.4.35. - [Release notes](https://github.com/chronotope/chrono/releases) - [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md) - [Commits](https://github.com/chronotope/chrono/compare/v0.4.34...v0.4.35) --- updated-dependencies: - dependency-name: chrono dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 24346ae4..37918f26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2016,9 +2016,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", From 327cc9a549d57dcfddff279dcff80ef2472f6019 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 11 Mar 2024 19:47:15 +0000 Subject: [PATCH 2/2] chore: address deprecations --- auth/simple-auth-server/src/models.rs | 12 +++++++----- background-jobs/src/routes.rs | 6 +++--- middleware/rate-limit/src/rate_limit.rs | 10 +++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/auth/simple-auth-server/src/models.rs b/auth/simple-auth-server/src/models.rs index e4514b7f..e03ab19c 100644 --- a/auth/simple-auth-server/src/models.rs +++ b/auth/simple-auth-server/src/models.rs @@ -1,7 +1,9 @@ #![allow(clippy::extra_unused_lifetimes)] +use chrono::{NaiveDateTime, TimeDelta, Utc}; use diesel::{r2d2::ConnectionManager, PgConnection}; use serde::{Deserialize, Serialize}; +use uuid::Uuid; use super::schema::*; @@ -13,7 +15,7 @@ pub type Pool = r2d2::Pool>; pub struct User { pub email: String, pub hash: String, - pub created_at: chrono::NaiveDateTime, + pub created_at: NaiveDateTime, } impl User { @@ -29,9 +31,9 @@ impl User { #[derive(Debug, Serialize, Deserialize, Queryable, Insertable)] #[diesel(table_name = invitations)] pub struct Invitation { - pub id: uuid::Uuid, + pub id: Uuid, pub email: String, - pub expires_at: chrono::NaiveDateTime, + pub expires_at: NaiveDateTime, } // any type that implements Into can be used to create Invitation @@ -41,9 +43,9 @@ where { fn from(email: T) -> Self { Invitation { - id: uuid::Uuid::new_v4(), + id: Uuid::new_v4(), email: email.into(), - expires_at: chrono::Local::now().naive_local() + chrono::Duration::hours(24), + expires_at: (Utc::now() + TimeDelta::try_hours(24).unwrap()).naive_utc(), } } } diff --git a/background-jobs/src/routes.rs b/background-jobs/src/routes.rs index 261e33fa..b715ec23 100644 --- a/background-jobs/src/routes.rs +++ b/background-jobs/src/routes.rs @@ -4,7 +4,7 @@ use actix_web::{ HttpResponse, Responder, }; use apalis::{prelude::*, redis::RedisStorage}; -use chrono::{Duration, Utc}; +use chrono::{TimeDelta, Utc}; use serde::Deserialize; use crate::{persistent_jobs::Email, ItemCache}; @@ -12,7 +12,7 @@ use crate::{persistent_jobs::Email, ItemCache}; #[derive(Debug, Deserialize)] pub(crate) struct CacheInsert { data: String, - duration: u64, + duration: u32, } #[get("/cache")] @@ -26,7 +26,7 @@ pub(crate) async fn cache_item( cache: Data, web::Json(form): web::Json, ) -> actix_web::Result { - let expires = Utc::now() + Duration::seconds(form.duration as i64); + let expires = Utc::now() + TimeDelta::try_seconds(form.duration as i64).unwrap(); // insert into item cache cache.lock().unwrap().insert(form.data, expires); diff --git a/middleware/rate-limit/src/rate_limit.rs b/middleware/rate-limit/src/rate_limit.rs index e985b0a6..6b283870 100644 --- a/middleware/rate-limit/src/rate_limit.rs +++ b/middleware/rate-limit/src/rate_limit.rs @@ -11,8 +11,8 @@ use actix_web::{ dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform}, Error, HttpResponse, }; -use chrono::{Local, NaiveDateTime}; -use futures_util::{future::LocalBoxFuture, FutureExt, TryFutureExt}; +use chrono::{DateTime, Utc}; +use futures_util::{future::LocalBoxFuture, FutureExt as _, TryFutureExt as _}; #[doc(hidden)] pub struct RateLimitService { @@ -95,7 +95,7 @@ struct TokenBucket { capacity: u64, /// Time that last request was accepted. - last_req_time: NaiveDateTime, + last_req_time: DateTime, /// Numbers of tokens remaining. /// @@ -108,7 +108,7 @@ impl TokenBucket { fn new(limit: u64) -> Self { TokenBucket { limit, - last_req_time: NaiveDateTime::UNIX_EPOCH, + last_req_time: DateTime::::UNIX_EPOCH, capacity: limit, tokens: 0, } @@ -116,7 +116,7 @@ impl TokenBucket { /// Mutates leaky bucket for accepted request. fn allow_query(&mut self) -> bool { - let current_time = Local::now().naive_local(); + let current_time = Utc::now(); let time_elapsed = (current_time.timestamp() - self.last_req_time.timestamp()) as u64;