1
0
mirror of https://github.com/CCC-MF/bwhc-kafka-rest-proxy.git synced 2025-04-19 19:16:51 +00:00

chore: add linter rules

This commit is contained in:
Paul-Christian Volkmer 2024-12-28 13:14:11 +01:00
parent fd28df39c8
commit b0bf5ce5dc
4 changed files with 30 additions and 12 deletions

View File

@ -61,6 +61,19 @@ version = "0.16"
git = "https://github.com/ccc-mf/bwhc-dto-rs" git = "https://github.com/ccc-mf/bwhc-dto-rs"
branch = "master" 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] [profile.release]
opt-level = "s" opt-level = "s"
codegen-units = 1 codegen-units = 1

View File

@ -1,6 +1,7 @@
use base64::prelude::BASE64_STANDARD; use base64::prelude::BASE64_STANDARD;
use base64::Engine; use base64::Engine;
#[allow(clippy::module_name_repetitions)]
pub fn check_basic_auth(auth_header: &str, expected_token: &str) -> bool { pub fn check_basic_auth(auth_header: &str, expected_token: &str) -> bool {
let split = auth_header.split(' ').collect::<Vec<_>>(); let split = auth_header.split(' ').collect::<Vec<_>>();
if split.len() == 2 && split.first().map(|first| first.to_lowercase()) == Some("basic".into()) { if split.len() == 2 && split.first().map(|first| first.to_lowercase()) == Some("basic".into()) {

View File

@ -1,11 +1,11 @@
use axum::{Extension, Json, Router};
use axum::body::Body; use axum::body::Body;
use axum::extract::Path; use axum::extract::Path;
use axum::http::{Request, StatusCode};
use axum::http::header::AUTHORIZATION; use axum::http::header::AUTHORIZATION;
use axum::http::{Request, StatusCode};
use axum::middleware::{from_fn, Next}; use axum::middleware::{from_fn, Next};
use axum::response::{IntoResponse, Response}; use axum::response::{IntoResponse, Response};
use axum::routing::{delete, post}; use axum::routing::{delete, post};
use axum::{Extension, Json, Router};
use bwhc_dto::MtbFile; use bwhc_dto::MtbFile;
use clap::Parser; use clap::Parser;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -13,9 +13,9 @@ use serde::{Deserialize, Serialize};
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
use tower_http::trace::TraceLayer; use tower_http::trace::TraceLayer;
use crate::AppResponse::{Accepted, InternalServerError, Unauthorized};
use crate::cli::Cli; use crate::cli::Cli;
use crate::sender::MtbFileSender; use crate::sender::MtbFileSender;
use crate::AppResponse::{Accepted, InternalServerError, Unauthorized};
mod auth; mod auth;
mod cli; mod cli;
@ -33,6 +33,7 @@ enum AppResponse<'a> {
InternalServerError, InternalServerError,
} }
#[allow(clippy::expect_used)]
impl IntoResponse for AppResponse<'_> { impl IntoResponse for AppResponse<'_> {
fn into_response(self) -> Response { fn into_response(self) -> Response {
match self { match self {
@ -52,7 +53,7 @@ lazy_static! {
} }
#[tokio::main] #[tokio::main]
async fn main() { async fn main() -> Result<(), ()> {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ {
tracing_subscriber::fmt() tracing_subscriber::fmt()
@ -60,7 +61,7 @@ async fn main() {
.init(); .init();
} }
let sender = MtbFileSender::new(&CONFIG.topic, &CONFIG.bootstrap_server); let sender = MtbFileSender::new(&CONFIG.topic, &CONFIG.bootstrap_server)?;
let app = Router::new() let app = Router::new()
.route("/mtbfile", post(handle_post)) .route("/mtbfile", post(handle_post))
@ -75,11 +76,13 @@ async fn main() {
Ok(listener) => { Ok(listener) => {
log::info!("Starting application listening on '{}'", CONFIG.listen); log::info!("Starting application listening on '{}'", CONFIG.listen);
if let Err(err) = axum::serve(listener, app).await { 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), Err(err) => log::error!("Error listening on '{}': {}", CONFIG.listen, err),
}; };
Ok(())
} }
async fn check_basic_auth(request: Request<Body>, next: Next) -> Response { async fn check_basic_auth(request: Request<Body>, next: Next) -> Response {

View File

@ -8,6 +8,7 @@ use uuid::Uuid;
use crate::RecordKey; use crate::RecordKey;
#[allow(clippy::module_name_repetitions)]
#[derive(Clone)] #[derive(Clone)]
pub struct MtbFileSender { pub struct MtbFileSender {
topic: String, topic: String,
@ -15,17 +16,17 @@ pub struct MtbFileSender {
} }
impl MtbFileSender { impl MtbFileSender {
pub fn new(topic: &str, bootstrap_server: &str) -> Self { pub fn new(topic: &str, bootstrap_server: &str) -> Result<Self, ()> {
let producer: FutureProducer = ClientConfig::new() let producer = ClientConfig::new()
.set("bootstrap.servers", bootstrap_server) .set("bootstrap.servers", bootstrap_server)
.set("message.timeout.ms", "5000") .set("message.timeout.ms", "5000")
.create() .create::<FutureProducer>()
.expect("Producer creation error"); .map_err(|_| ())?;
Self { Ok(Self {
topic: topic.to_string(), topic: topic.to_string(),
producer, producer,
} })
} }
pub async fn send(&self, mtb_file: MtbFile) -> Result<String, ()> { pub async fn send(&self, mtb_file: MtbFile) -> Result<String, ()> {