From bea38bc445e6e314c56236076668fe5a8fdfce3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sat, 23 Nov 2024 20:58:40 +0100 Subject: [PATCH] fix(clippy): enable more lints and fix issues We also add some more metadata to the Cargo.toml manifest --- Cargo.toml | 10 ++++++++++ src/auth.rs | 16 ++++++++-------- src/main.rs | 13 +++++-------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf93cf8..4067e58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,16 @@ description = "An HTTP server using HTTP basic auth to make secure calls to nsup name = "webnsupdate" version = "0.3.2-dev" edition = "2021" +license-file = "LICENSE" +readme = "README.md" +keywords = ["dns", "dyndns", "dynamic-ip"] +categories = ["networking", "dns", "dyndns"] +repository = "https://github.com/jalil-salame/webnsupdate" + +[lints.clippy] +cargo = { level = "warn", priority = -2 } +multiple_crate_versions = "allow" +pedantic = { level = "warn", priority = -1 } [dependencies] axum = "0.7" diff --git a/src/auth.rs b/src/auth.rs index 846b3ff..c0156d0 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -5,21 +5,21 @@ use tracing::{trace, warn}; use crate::password; -pub fn auth_layer<'a, ResBody>( +pub fn layer<'a, ResBody>( user_pass_hash: &'a [u8], salt: &'a str, -) -> ValidateRequestHeaderLayer> { - ValidateRequestHeaderLayer::custom(BasicAuth::new(user_pass_hash, salt)) +) -> ValidateRequestHeaderLayer> { + ValidateRequestHeaderLayer::custom(Basic::new(user_pass_hash, salt)) } #[derive(Copy)] -pub struct BasicAuth<'a, ResBody> { +pub struct Basic<'a, ResBody> { pass: &'a [u8], salt: &'a str, _ty: std::marker::PhantomData ResBody>, } -impl std::fmt::Debug for BasicAuth<'_, ResBody> { +impl std::fmt::Debug for Basic<'_, ResBody> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("BasicAuth") .field("pass", &self.pass) @@ -29,7 +29,7 @@ impl std::fmt::Debug for BasicAuth<'_, ResBody> { } } -impl Clone for BasicAuth<'_, ResBody> { +impl Clone for Basic<'_, ResBody> { fn clone(&self) -> Self { Self { pass: self.pass, @@ -39,7 +39,7 @@ impl Clone for BasicAuth<'_, ResBody> { } } -impl<'a, ResBody> BasicAuth<'a, ResBody> { +impl<'a, ResBody> Basic<'a, ResBody> { pub fn new(pass: &'a [u8], salt: &'a str) -> Self { Self { pass, @@ -81,7 +81,7 @@ impl<'a, ResBody> BasicAuth<'a, ResBody> { } } -impl tower_http::validate_request::ValidateRequest for BasicAuth<'_, ResBody> +impl tower_http::validate_request::ValidateRequest for Basic<'_, ResBody> where ResBody: Default, { diff --git a/src/main.rs b/src/main.rs index 07c06f5..b612c38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,7 @@ struct Opts { /// Set client IP source /// - /// see: https://docs.rs/axum-client-ip/latest/axum_client_ip/enum.SecureClientIpSource.html + /// see: #[clap(long, default_value = "RightmostXForwardedFor")] ip_source: SecureClientIpSource, @@ -281,19 +281,16 @@ fn main() -> Result<()> { } } } - Ok(None) => { - info!("No previous IP address set"); - } - Err(err) => { - error!("Failed to load last ip address: {err}") - } + Ok(None) => info!("No previous IP address set"), + + Err(err) => error!("Failed to load last ip address: {err}"), }; // Create services let app = Router::new().route("/update", get(update_records)); // if a password is provided, validate it let app = if let Some(pass) = password_hash { - app.layer(auth::auth_layer(Box::leak(pass), String::leak(salt))) + app.layer(auth::layer(Box::leak(pass), String::leak(salt))) } else { app }