fix(clippy): enable more lints and fix issues
We also add some more metadata to the Cargo.toml manifest
This commit is contained in:
parent
846a0675d1
commit
bea38bc445
3 changed files with 23 additions and 16 deletions
10
Cargo.toml
10
Cargo.toml
|
@ -5,6 +5,16 @@ description = "An HTTP server using HTTP basic auth to make secure calls to nsup
|
||||||
name = "webnsupdate"
|
name = "webnsupdate"
|
||||||
version = "0.3.2-dev"
|
version = "0.3.2-dev"
|
||||||
edition = "2021"
|
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]
|
[dependencies]
|
||||||
axum = "0.7"
|
axum = "0.7"
|
||||||
|
|
16
src/auth.rs
16
src/auth.rs
|
@ -5,21 +5,21 @@ use tracing::{trace, warn};
|
||||||
|
|
||||||
use crate::password;
|
use crate::password;
|
||||||
|
|
||||||
pub fn auth_layer<'a, ResBody>(
|
pub fn layer<'a, ResBody>(
|
||||||
user_pass_hash: &'a [u8],
|
user_pass_hash: &'a [u8],
|
||||||
salt: &'a str,
|
salt: &'a str,
|
||||||
) -> ValidateRequestHeaderLayer<BasicAuth<'a, ResBody>> {
|
) -> ValidateRequestHeaderLayer<Basic<'a, ResBody>> {
|
||||||
ValidateRequestHeaderLayer::custom(BasicAuth::new(user_pass_hash, salt))
|
ValidateRequestHeaderLayer::custom(Basic::new(user_pass_hash, salt))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy)]
|
#[derive(Copy)]
|
||||||
pub struct BasicAuth<'a, ResBody> {
|
pub struct Basic<'a, ResBody> {
|
||||||
pass: &'a [u8],
|
pass: &'a [u8],
|
||||||
salt: &'a str,
|
salt: &'a str,
|
||||||
_ty: std::marker::PhantomData<fn() -> ResBody>,
|
_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 {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.debug_struct("BasicAuth")
|
f.debug_struct("BasicAuth")
|
||||||
.field("pass", &self.pass)
|
.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 {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
pass: self.pass,
|
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 {
|
pub fn new(pass: &'a [u8], salt: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
pass,
|
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
|
where
|
||||||
ResBody: Default,
|
ResBody: Default,
|
||||||
{
|
{
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -77,7 +77,7 @@ struct Opts {
|
||||||
|
|
||||||
/// Set client IP source
|
/// 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")]
|
#[clap(long, default_value = "RightmostXForwardedFor")]
|
||||||
ip_source: SecureClientIpSource,
|
ip_source: SecureClientIpSource,
|
||||||
|
|
||||||
|
@ -281,19 +281,16 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(None) => {
|
Ok(None) => info!("No previous IP address set"),
|
||||||
info!("No previous IP address set");
|
|
||||||
}
|
Err(err) => error!("Failed to load last ip address: {err}"),
|
||||||
Err(err) => {
|
|
||||||
error!("Failed to load last ip address: {err}")
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create services
|
// Create services
|
||||||
let app = Router::new().route("/update", get(update_records));
|
let app = Router::new().route("/update", get(update_records));
|
||||||
// if a password is provided, validate it
|
// if a password is provided, validate it
|
||||||
let app = if let Some(pass) = password_hash {
|
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 {
|
} else {
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue