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

View File

@ -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::<Vec<_>>();
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::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<Body>, next: Next) -> Response {

View File

@ -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<Self, ()> {
let producer = ClientConfig::new()
.set("bootstrap.servers", bootstrap_server)
.set("message.timeout.ms", "5000")
.create()
.expect("Producer creation error");
.create::<FutureProducer>()
.map_err(|_| ())?;
Self {
Ok(Self {
topic: topic.to_string(),
producer,
}
})
}
pub async fn send(&self, mtb_file: MtbFile) -> Result<String, ()> {