From c24b0a70f2fc74686dd898bdf461c0400b4c6744 Mon Sep 17 00:00:00 2001 From: Gerard Zinn Date: Mon, 21 Oct 2024 10:16:45 +0200 Subject: [PATCH] Import changes --- crates/api/src/config/mod.rs | 4 ++-- crates/api/src/handlers/admin/mod.rs | 4 ++-- crates/api/src/handlers/auth/mod.rs | 8 ++++---- crates/api/src/handlers/championships/stream.rs | 6 ++++-- crates/api/src/handlers/mod.rs | 4 ++-- crates/api/src/handlers/user/mod.rs | 4 ++-- crates/api/src/middlewares/mod.rs | 8 ++++---- crates/api/src/routes/mod.rs | 6 +++--- crates/api/src/states/mod.rs | 4 ++-- crates/db/src/cache/mod.rs | 8 ++++---- crates/db/src/db.rs | 4 ++-- crates/entities/src/entities.rs | 12 ++++++------ crates/error/src/error.rs | 16 ++++++++-------- crates/id-generator/src/id_generator.rs | 7 ++++--- crates/intelli-core/src/repositories/mod.rs | 12 ++++++------ crates/intelli-core/src/services/mod.rs | 10 +++++----- crates/structs/src/structs.rs | 12 ++++++------ crates/telemetry/src/f1.rs | 2 +- crates/telemetry/src/firewall.rs | 3 ++- crates/telemetry/src/manager.rs | 3 ++- crates/token_manager/src/persistence.rs | 12 ++++++++---- crates/token_manager/src/token.rs | 3 ++- crates/token_manager/src/token_manager.rs | 9 +++++---- 23 files changed, 86 insertions(+), 75 deletions(-) diff --git a/crates/api/src/config/mod.rs b/crates/api/src/config/mod.rs index de249f24..341a6d35 100644 --- a/crates/api/src/config/mod.rs +++ b/crates/api/src/config/mod.rs @@ -1,3 +1,3 @@ -pub(crate) use local_tracing::*; - mod local_tracing; + +pub(crate) use local_tracing::*; diff --git a/crates/api/src/handlers/admin/mod.rs b/crates/api/src/handlers/admin/mod.rs index 04cc94ab..a25db5b1 100644 --- a/crates/api/src/handlers/admin/mod.rs +++ b/crates/api/src/handlers/admin/mod.rs @@ -1,3 +1,3 @@ -pub(crate) use conn::*; - mod conn; + +pub(crate) use conn::*; diff --git a/crates/api/src/handlers/auth/mod.rs b/crates/api/src/handlers/auth/mod.rs index a94ea590..d2edf0f3 100644 --- a/crates/api/src/handlers/auth/mod.rs +++ b/crates/api/src/handlers/auth/mod.rs @@ -1,7 +1,7 @@ -pub(crate) use discord::*; -pub(crate) use user::*; -pub(crate) use verify::*; - mod discord; mod user; mod verify; + +pub(crate) use discord::*; +pub(crate) use user::*; +pub(crate) use verify::*; diff --git a/crates/api/src/handlers/championships/stream.rs b/crates/api/src/handlers/championships/stream.rs index 0ffb4a70..7a530788 100644 --- a/crates/api/src/handlers/championships/stream.rs +++ b/crates/api/src/handlers/championships/stream.rs @@ -1,5 +1,7 @@ -use std::pin::Pin; -use std::task::{Context, Poll}; +use std::{ + pin::Pin, + task::{Context, Poll}, +}; use garde::Validate; use ntex::{ diff --git a/crates/api/src/handlers/mod.rs b/crates/api/src/handlers/mod.rs index 664621a5..eb2efb01 100644 --- a/crates/api/src/handlers/mod.rs +++ b/crates/api/src/handlers/mod.rs @@ -1,10 +1,10 @@ -use ntex::web::HttpResponse; - pub(crate) mod admin; pub(crate) mod auth; pub(crate) mod championships; pub(crate) mod user; +use ntex::web::HttpResponse; + pub(crate) async fn system_health_check() -> HttpResponse { HttpResponse::Ok().finish() } diff --git a/crates/api/src/handlers/user/mod.rs b/crates/api/src/handlers/user/mod.rs index 1dfd0b3a..9a78f4c7 100644 --- a/crates/api/src/handlers/user/mod.rs +++ b/crates/api/src/handlers/user/mod.rs @@ -1,3 +1,5 @@ +pub(crate) mod admin; + use garde::Validate; use ntex::web::{ types::{Json, State}, @@ -11,8 +13,6 @@ use structs::{UserProfileData, UserUpdateData}; use crate::states::AppState; -pub(crate) mod admin; - #[inline] pub(crate) async fn get(req: HttpRequest, state: State) -> AppResult { let user = req.user()?; diff --git a/crates/api/src/middlewares/mod.rs b/crates/api/src/middlewares/mod.rs index 4c988b8e..b5e5f3a9 100644 --- a/crates/api/src/middlewares/mod.rs +++ b/crates/api/src/middlewares/mod.rs @@ -1,7 +1,7 @@ -pub(crate) use admin::*; -pub(crate) use authenticated::*; -pub(crate) use login::*; - mod admin; mod authenticated; mod login; + +pub(crate) use admin::*; +pub(crate) use authenticated::*; +pub(crate) use login::*; diff --git a/crates/api/src/routes/mod.rs b/crates/api/src/routes/mod.rs index d369d2c9..133da09b 100644 --- a/crates/api/src/routes/mod.rs +++ b/crates/api/src/routes/mod.rs @@ -1,5 +1,5 @@ -pub(crate) use admin::*; -pub(crate) use api::*; - mod admin; mod api; + +pub(crate) use admin::*; +pub(crate) use api::*; diff --git a/crates/api/src/states/mod.rs b/crates/api/src/states/mod.rs index 303c2aec..49f83f0f 100644 --- a/crates/api/src/states/mod.rs +++ b/crates/api/src/states/mod.rs @@ -1,3 +1,3 @@ -pub(crate) use app::*; - mod app; + +pub(crate) use app::*; diff --git a/crates/db/src/cache/mod.rs b/crates/db/src/cache/mod.rs index 61b4937f..5e431019 100644 --- a/crates/db/src/cache/mod.rs +++ b/crates/db/src/cache/mod.rs @@ -1,13 +1,13 @@ +mod championship; +mod driver; +mod user; + use std::sync::Arc; use driver::DriverCache; use self::{championship::ChampionshipCache, user::UserCache}; -mod championship; -mod driver; -mod user; - const CACHE_CAPACITY: usize = 2_000; /// Caching layer for users, championships, and tokens. diff --git a/crates/db/src/db.rs b/crates/db/src/db.rs index ba1a0d66..a94ace02 100644 --- a/crates/db/src/db.rs +++ b/crates/db/src/db.rs @@ -1,3 +1,5 @@ +mod cache; + use std::{ops::DerefMut, str::FromStr}; use cache::ServiceCache; @@ -11,8 +13,6 @@ use tracing::info; pub use cache::EntityCache; -mod cache; - embed_migrations!("migrations"); /// Encapsulates Postgres database connections. diff --git a/crates/entities/src/entities.rs b/crates/entities/src/entities.rs index 7e9e232c..e67bda38 100644 --- a/crates/entities/src/entities.rs +++ b/crates/entities/src/entities.rs @@ -1,3 +1,9 @@ +mod championship; +mod driver; +mod race; +mod result; +mod user; + pub use championship::*; pub use driver::*; #[allow(unused)] @@ -5,9 +11,3 @@ pub use race::*; #[allow(unused)] pub use result::*; pub use user::*; - -mod championship; -mod driver; -mod race; -mod result; -mod user; diff --git a/crates/error/src/error.rs b/crates/error/src/error.rs index aa4fcb77..afcf37fc 100644 --- a/crates/error/src/error.rs +++ b/crates/error/src/error.rs @@ -1,3 +1,11 @@ +mod championship; +mod common; +mod driver; +mod f1; +mod firewall; +mod token; +mod user; + use deadpool_postgres::{tokio_postgres::Error as PgError, PoolError}; use ntex::{ http::{ @@ -17,14 +25,6 @@ pub use firewall::*; pub use token::*; pub use user::*; -mod championship; -mod common; -mod driver; -mod f1; -mod firewall; -mod token; -mod user; - pub type AppResult = Result; // TODO: Handle 3rd party errors in a better way diff --git a/crates/id-generator/src/id_generator.rs b/crates/id-generator/src/id_generator.rs index aec9378d..ffeb151f 100644 --- a/crates/id-generator/src/id_generator.rs +++ b/crates/id-generator/src/id_generator.rs @@ -1,12 +1,13 @@ #![feature(portable_simd)] -use ahash::AHashSet; -use parking_lot::Mutex; -use ring::rand::{SecureRandom, SystemRandom}; use std::{ ops::Range, simd::{i32x16, num::SimdInt, Simd}, }; +use ahash::AHashSet; +use parking_lot::Mutex; +use ring::rand::{SecureRandom, SystemRandom}; + const IDS_POOL_SIZE: usize = 1024; /// A structure to manage a set of bits efficiently. diff --git a/crates/intelli-core/src/repositories/mod.rs b/crates/intelli-core/src/repositories/mod.rs index ad5731e9..ccacd4af 100644 --- a/crates/intelli-core/src/repositories/mod.rs +++ b/crates/intelli-core/src/repositories/mod.rs @@ -1,11 +1,11 @@ -pub use championship::*; -pub use discord::*; -pub use driver::*; -pub use server::*; -pub use user::*; - mod championship; mod discord; mod driver; mod server; mod user; + +pub use championship::*; +pub use discord::*; +pub use driver::*; +pub use server::*; +pub use user::*; diff --git a/crates/intelli-core/src/services/mod.rs b/crates/intelli-core/src/services/mod.rs index dbea376d..96fd4a2d 100644 --- a/crates/intelli-core/src/services/mod.rs +++ b/crates/intelli-core/src/services/mod.rs @@ -1,9 +1,9 @@ -pub use championship::*; -pub use driver::*; -pub use email::*; -pub use user::*; - mod championship; mod driver; mod email; mod user; + +pub use championship::*; +pub use driver::*; +pub use email::*; +pub use user::*; diff --git a/crates/structs/src/structs.rs b/crates/structs/src/structs.rs index 71558f1e..10a80a96 100644 --- a/crates/structs/src/structs.rs +++ b/crates/structs/src/structs.rs @@ -1,11 +1,11 @@ -pub use auth::*; -pub use championship::*; -pub use server::*; -pub use templates::*; -pub use user::*; - mod auth; mod championship; mod server; mod templates; mod user; + +pub use auth::*; +pub use championship::*; +pub use server::*; +pub use templates::*; +pub use user::*; diff --git a/crates/telemetry/src/f1.rs b/crates/telemetry/src/f1.rs index faeed932..44915f9d 100644 --- a/crates/telemetry/src/f1.rs +++ b/crates/telemetry/src/f1.rs @@ -2,7 +2,7 @@ // -------------- ORIGINAL GAME ---------------- // --------------------------------------------- -use core::str; +use std::str; use error::{AppError, ChampionshipError}; diff --git a/crates/telemetry/src/firewall.rs b/crates/telemetry/src/firewall.rs index 52a5289a..861e6161 100644 --- a/crates/telemetry/src/firewall.rs +++ b/crates/telemetry/src/firewall.rs @@ -1,7 +1,8 @@ +use std::{net::IpAddr, process::Command as StdCommand, str}; + use ahash::AHashMap; use error::{AppResult, FirewallError}; use regex::Regex; -use std::{net::IpAddr, process::Command as StdCommand, str}; use tokio::process::Command; use tokio::sync::RwLock; use tracing::{error, warn}; diff --git a/crates/telemetry/src/manager.rs b/crates/telemetry/src/manager.rs index c4d39233..cb2d83a8 100644 --- a/crates/telemetry/src/manager.rs +++ b/crates/telemetry/src/manager.rs @@ -1,3 +1,5 @@ +use std::{ops::Deref, sync::Arc, time::Duration}; + use ahash::{AHashMap, AHashSet}; use ntex::{ time::interval, @@ -5,7 +7,6 @@ use ntex::{ }; use parking_lot::{Mutex, RwLock}; use prost::Message; -use std::{ops::Deref, sync::Arc, time::Duration}; use tokio::sync::{ broadcast::{Receiver, Sender}, oneshot, diff --git a/crates/token_manager/src/persistence.rs b/crates/token_manager/src/persistence.rs index 3d154e1b..e0750c86 100644 --- a/crates/token_manager/src/persistence.rs +++ b/crates/token_manager/src/persistence.rs @@ -1,8 +1,12 @@ +use std::{ + collections::VecDeque, + fs::{File, OpenOptions}, + io::{Read, Write}, + mem::size_of, +}; + use dashmap::DashMap; -use std::collections::VecDeque; -use std::fs::{File, OpenOptions}; -use std::io::{Read, Write}; -use std::mem::size_of; + use utils::current_timestamp_s; use crate::token::{Header, Token, TokenEntry}; diff --git a/crates/token_manager/src/token.rs b/crates/token_manager/src/token.rs index 46baf83f..411ad8de 100644 --- a/crates/token_manager/src/token.rs +++ b/crates/token_manager/src/token.rs @@ -1,9 +1,10 @@ use std::slice; use base64_simd::{Out, URL_SAFE_NO_PAD}; -use error::{AppResult, TokenError}; use ring::rand::{SecureRandom, SystemRandom}; +use error::{AppResult, TokenError}; + #[repr(C)] #[derive(Clone, Copy, PartialEq, Eq, Hash)] pub struct Token([u8; 16]); diff --git a/crates/token_manager/src/token_manager.rs b/crates/token_manager/src/token_manager.rs index 26ef4f29..76aec193 100644 --- a/crates/token_manager/src/token_manager.rs +++ b/crates/token_manager/src/token_manager.rs @@ -1,16 +1,17 @@ +mod persistence; +mod token; + use std::{collections::VecDeque, time::Duration}; use dashmap::DashMap; use error::{AppResult, TokenError}; use token::TokenEntry; -mod persistence; -mod token; - -pub use token::{Token, TokenIntent}; use tokio::{task, time::sleep}; use utils::current_timestamp_s; +pub use token::{Token, TokenIntent}; + const MAX_TOKENS_PER_USER: usize = 10; const PURGE_INTERVAL: Duration = Duration::from_secs(900);