From b0bf5ce5dca161bde78cfe987593abd5660beba8 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sat, 28 Dec 2024 13:14:11 +0100 Subject: [PATCH] chore: add linter rules --- Cargo.toml | 13 +++++++++++++ src/auth.rs | 1 + src/main.rs | 15 +++++++++------ src/sender.rs | 13 +++++++------ 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 119ae53..99e7c78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,19 @@ version = "0.16" git = "https://github.com/ccc-mf/bwhc-dto-rs" branch = "master" +# Lints + +[lints.clippy] +unwrap_used = "deny" +expect_used = "deny" +panic = "deny" +pedantic = { level = "warn", priority = -1 } + +[lints.rust] +unused_must_use = "deny" + +# Profiles + [profile.release] opt-level = "s" codegen-units = 1 diff --git a/src/auth.rs b/src/auth.rs index b63a9de..f4bc86c 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,6 +1,7 @@ use base64::prelude::BASE64_STANDARD; use base64::Engine; +#[allow(clippy::module_name_repetitions)] pub fn check_basic_auth(auth_header: &str, expected_token: &str) -> bool { let split = auth_header.split(' ').collect::>(); if split.len() == 2 && split.first().map(|first| first.to_lowercase()) == Some("basic".into()) { diff --git a/src/main.rs b/src/main.rs index 06b530e..c1e9987 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,11 @@ -use axum::{Extension, Json, Router}; use axum::body::Body; use axum::extract::Path; -use axum::http::{Request, StatusCode}; use axum::http::header::AUTHORIZATION; +use axum::http::{Request, StatusCode}; use axum::middleware::{from_fn, Next}; use axum::response::{IntoResponse, Response}; use axum::routing::{delete, post}; +use axum::{Extension, Json, Router}; use bwhc_dto::MtbFile; use clap::Parser; use lazy_static::lazy_static; @@ -13,9 +13,9 @@ use serde::{Deserialize, Serialize}; #[cfg(debug_assertions)] use tower_http::trace::TraceLayer; -use crate::AppResponse::{Accepted, InternalServerError, Unauthorized}; use crate::cli::Cli; use crate::sender::MtbFileSender; +use crate::AppResponse::{Accepted, InternalServerError, Unauthorized}; mod auth; mod cli; @@ -33,6 +33,7 @@ enum AppResponse<'a> { InternalServerError, } +#[allow(clippy::expect_used)] impl IntoResponse for AppResponse<'_> { fn into_response(self) -> Response { match self { @@ -52,7 +53,7 @@ lazy_static! { } #[tokio::main] -async fn main() { +async fn main() -> Result<(), ()> { #[cfg(debug_assertions)] { tracing_subscriber::fmt() @@ -60,7 +61,7 @@ async fn main() { .init(); } - let sender = MtbFileSender::new(&CONFIG.topic, &CONFIG.bootstrap_server); + let sender = MtbFileSender::new(&CONFIG.topic, &CONFIG.bootstrap_server)?; let app = Router::new() .route("/mtbfile", post(handle_post)) @@ -75,11 +76,13 @@ async fn main() { Ok(listener) => { log::info!("Starting application listening on '{}'", CONFIG.listen); if let Err(err) = axum::serve(listener, app).await { - log::error!("Error starting application: {}", err) + log::error!("Error starting application: {}", err); } } Err(err) => log::error!("Error listening on '{}': {}", CONFIG.listen, err), }; + + Ok(()) } async fn check_basic_auth(request: Request, next: Next) -> Response { diff --git a/src/sender.rs b/src/sender.rs index 10ec86a..0e0b63f 100644 --- a/src/sender.rs +++ b/src/sender.rs @@ -8,6 +8,7 @@ use uuid::Uuid; use crate::RecordKey; +#[allow(clippy::module_name_repetitions)] #[derive(Clone)] pub struct MtbFileSender { topic: String, @@ -15,17 +16,17 @@ pub struct MtbFileSender { } impl MtbFileSender { - pub fn new(topic: &str, bootstrap_server: &str) -> Self { - let producer: FutureProducer = ClientConfig::new() + pub fn new(topic: &str, bootstrap_server: &str) -> Result { + let producer = ClientConfig::new() .set("bootstrap.servers", bootstrap_server) .set("message.timeout.ms", "5000") - .create() - .expect("Producer creation error"); + .create::() + .map_err(|_| ())?; - Self { + Ok(Self { topic: topic.to_string(), producer, - } + }) } pub async fn send(&self, mtb_file: MtbFile) -> Result {