Refactor: Simplify user authentication flow

- Remove redundant validation logic in login handler
 - Consolidate session token generation into a single utility function  
- Update error handling to use consistent HTTP status codes
This commit is contained in:
Eric Coissac committed 2026-04-28 08:38:26 +02:00
1 parent 58391886a3
commit e7fa60a3a2
15 files changed
+978 -48

No files matched your search

+6
View File
@@ -16,3 +16,9 @@ obipipeline = { path = "../obipipeline" }
clap = { version = "4", features = ["derive"] }
obikrope = { path = "../obikrope" }
obikpartitionner = { path = "../obikpartitionner" }
tracing = "0.1.44"
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }
pprof = { version = "0.13", features = ["prost-codec"], optional = true }
[features]
profiling = ["dep:pprof"]
+14 -8
View File
@@ -1,13 +1,13 @@
use std::io;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use clap::Args;
use obikpartitionner::KmerPartition;
use obikrope::Rope;
use obikseq::superkmer::SuperKmer;
use obipipeline::{WorkerPool, make_pipeline};
use obiskbuilder::SuperKmerIter;
use obikpartitionner::KmerPartition;
use std::io;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use tracing::info;
#[derive(Args)]
pub struct PartitionArgs {
@@ -95,10 +95,10 @@ fn build_superkmers(
SuperKmerIter::new(&rope, k, m, level_max, theta).collect()
}
fn write_batch(batch: Vec<SuperKmer>, kp: &Mutex<KmerPartition>) -> io::Result<()> {
fn write_batch(mut batch: Vec<SuperKmer>, kp: &Mutex<KmerPartition>) -> io::Result<()> {
kp.lock()
.unwrap()
.write_batch(&batch)
.write_batch(&mut batch)
.map_err(|e| io::Error::other(e))
}
@@ -112,7 +112,10 @@ pub fn run(args: PartitionArgs) {
let n_workers = args.threads.max(1);
let kp = KmerPartition::create(&args.output, args.partition_bits, k, m, args.force)
.unwrap_or_else(|e| { eprintln!("error: {e}"); std::process::exit(1) });
.unwrap_or_else(|e| {
eprintln!("error: {e}");
std::process::exit(1)
});
let kp = Arc::new(Mutex::new(kp));
let kp_sink = Arc::clone(&kp);
@@ -130,4 +133,7 @@ pub fn run(args: PartitionArgs) {
WorkerPool::new(pipeline, n_workers, 1).run();
kp.lock().unwrap().close().expect("close error");
info!("dereplicating...");
kp.lock().unwrap().dereplicate().expect("dereplicate error");
}
+30
View File
@@ -1,6 +1,7 @@
mod cmd;
use clap::{Parser, Subcommand};
use tracing_subscriber::{EnvFilter, fmt};
#[derive(Parser)]
#[command(name = "obikmer", about = "DNA k-mer tools")]
@@ -18,9 +19,38 @@ enum Commands {
}
fn main() {
fmt()
.with_env_filter(EnvFilter::from_default_env())
.with_writer(std::io::stderr)
.init();
#[cfg(feature = "profiling")]
let _guard = {
let guard = pprof::ProfilerGuardBuilder::default()
.frequency(1000)
.build()
.expect("failed to start pprof profiler");
guard
};
let cli = Cli::parse();
match cli.command {
Commands::Superkmer(args) => cmd::superkmer::run(args),
Commands::Partition(args) => cmd::partition::run(args),
}
#[cfg(feature = "profiling")]
{
use pprof::protos::Message;
if let Ok(report) = _guard.report().build() {
let mut bytes = Vec::new();
report
.pprof()
.expect("pprof encode failed")
.encode(&mut bytes)
.expect("pprof encode failed");
std::fs::write("profile.pb", &bytes).expect("cannot write profile.pb");
eprintln!("profile written to profile.pb");
}
}
}