diff --git a/Cargo.lock b/Cargo.lock index 1130c9b..482780e 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", diff --git a/auth/simple-auth-server/src/models.rs b/auth/simple-auth-server/src/models.rs index e4514b7..e03ab19 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 261e33f..b715ec2 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 e985b0a..6b28387 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;