From 1ec6bc2bca4df33414d25b3a6e6ecaa22f5857ec Mon Sep 17 00:00:00 2001 From: Jamie Murphy Date: Sat, 31 Aug 2024 19:15:52 -0700 Subject: [PATCH] clippy: Fix lints --- src/api/search.rs | 4 ++-- src/authentication.rs | 11 +++-------- src/database/db.rs | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/api/search.rs b/src/api/search.rs index 370aa6d..a74a7fe 100644 --- a/src/api/search.rs +++ b/src/api/search.rs @@ -45,9 +45,9 @@ fn get_filter_string(filter: &str, filter_added: &mut bool) -> String { let mut filter_string: String; if *filter_added { - filter_string = String::from(format!(" OR {filter} ")); + filter_string = format!(" OR {filter} "); } else { - filter_string = String::from(format!(" WHERE {filter} ")); + filter_string = format!(" WHERE {filter} "); *filter_added = true; } diff --git a/src/authentication.rs b/src/authentication.rs index 98341ff..c39503a 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -26,11 +26,10 @@ lazy_static::lazy_static! { pub static ref JWT_KEY: HS256Key = HS256Key::from_bytes(&STANDARD_NO_PAD.decode(std::env::var("JWT_KEY").unwrap()).unwrap()); } -pub struct ApiAuth { - pub token: String, -} +pub struct ApiAuth {} #[derive(Serialize, Deserialize)] + pub struct CustomClaims { // Admin is the only supported scope scopes: Vec, @@ -65,14 +64,10 @@ impl<'r> FromRequest<'r> for ApiAuth { let options = VerificationOptions::default(); if let Ok(claims) = JWT_KEY.verify_token::(token, Some(options)) { return match claims.custom.scopes.contains(&"admin".to_string()) { - true => request::Outcome::Success(ApiAuth { - token: token.to_string(), - }), + true => request::Outcome::Success(ApiAuth {}), false => request::Outcome::Error((Status::Forbidden, ApiError::NoAdminScope)), }; }; - - return request::Outcome::Error((Status::Forbidden, ApiError::NoAdminScope)); } request::Outcome::Error((Status::Forbidden, ApiError::Nil)) } diff --git a/src/database/db.rs b/src/database/db.rs index b3185df..19dd649 100644 --- a/src/database/db.rs +++ b/src/database/db.rs @@ -145,7 +145,7 @@ impl<'r, D: Database> FromRequest<'r> for Reloader { } } -impl<'a, D: Database> Sentinel for Reloader { +impl Sentinel for Reloader { fn abort(rocket: &Rocket) -> bool { D::fetch(rocket).is_none() }