fix(clippy): enable more lints and fix issues
All checks were successful
/ build (push) Successful in 3s
/ check (push) Successful in 7s

We also add some more metadata to the Cargo.toml manifest
This commit is contained in:
Jalil David Salamé Messina 2024-11-23 20:58:40 +01:00
parent 846a0675d1
commit bea38bc445
Signed by: jalil
GPG key ID: F016B9E770737A0B
3 changed files with 23 additions and 16 deletions

View file

@ -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"

View file

@ -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<BasicAuth<'a, ResBody>> {
ValidateRequestHeaderLayer::custom(BasicAuth::new(user_pass_hash, salt))
) -> ValidateRequestHeaderLayer<Basic<'a, ResBody>> {
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<fn() -> ResBody>,
}
impl<ResBody> std::fmt::Debug for BasicAuth<'_, ResBody> {
impl<ResBody> 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<ResBody> std::fmt::Debug for BasicAuth<'_, ResBody> {
}
}
impl<ResBody> Clone for BasicAuth<'_, ResBody> {
impl<ResBody> Clone for Basic<'_, ResBody> {
fn clone(&self) -> Self {
Self {
pass: self.pass,
@ -39,7 +39,7 @@ impl<ResBody> 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<B, ResBody> tower_http::validate_request::ValidateRequest<B> for BasicAuth<'_, ResBody>
impl<B, ResBody> tower_http::validate_request::ValidateRequest<B> for Basic<'_, ResBody>
where
ResBody: Default,
{

View file

@ -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: <https://docs.rs/axum-client-ip/latest/axum_client_ip/enum.SecureClientIpSource.html>
#[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
}