From 00fbd201127defee9c24a8edeb01eba3c053f306 Mon Sep 17 00:00:00 2001 From: DevITWay Date: Mon, 26 Jan 2026 08:31:00 +0000 Subject: [PATCH] fix: resolve clippy warnings and format code --- nora-registry/src/auth.rs | 4 +++- nora-registry/src/error.rs | 1 + nora-registry/src/main.rs | 6 +----- nora-registry/src/migrate.rs | 11 ++++------- nora-registry/src/rate_limit.rs | 11 ++++++----- nora-registry/src/registry/docker.rs | 5 +---- nora-registry/src/storage/mod.rs | 6 ++---- nora-registry/src/ui/templates.rs | 12 ++++++++++-- nora-registry/src/validation.rs | 3 ++- nora-storage/src/main.rs | 4 +--- 10 files changed, 31 insertions(+), 32 deletions(-) diff --git a/nora-registry/src/auth.rs b/nora-registry/src/auth.rs index 9b59334..e8cd9fb 100644 --- a/nora-registry/src/auth.rs +++ b/nora-registry/src/auth.rs @@ -405,7 +405,9 @@ mod tests { // Protected paths assert!(!is_public_path("/v2/myimage/blobs/sha256:abc")); assert!(!is_public_path("/v2/library/nginx/manifests/latest")); - assert!(!is_public_path("/maven2/com/example/artifact/1.0/artifact.jar")); + assert!(!is_public_path( + "/maven2/com/example/artifact/1.0/artifact.jar" + )); assert!(!is_public_path("/npm/lodash")); } diff --git a/nora-registry/src/error.rs b/nora-registry/src/error.rs index 7b33030..90ef176 100644 --- a/nora-registry/src/error.rs +++ b/nora-registry/src/error.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] //! Application error handling with HTTP response conversion //! //! Provides a unified error type that can be converted to HTTP responses diff --git a/nora-registry/src/main.rs b/nora-registry/src/main.rs index 4e9cb2f..796bde5 100644 --- a/nora-registry/src/main.rs +++ b/nora-registry/src/main.rs @@ -29,11 +29,7 @@ pub use storage::Storage; use tokens::TokenStore; #[derive(Parser)] -#[command( - name = "nora", - version, - about = "Multi-protocol artifact registry" -)] +#[command(name = "nora", version, about = "Multi-protocol artifact registry")] struct Cli { #[command(subcommand)] command: Option, diff --git a/nora-registry/src/migrate.rs b/nora-registry/src/migrate.rs index 52bfa0d..e5f3702 100644 --- a/nora-registry/src/migrate.rs +++ b/nora-registry/src/migrate.rs @@ -8,17 +8,12 @@ use indicatif::{ProgressBar, ProgressStyle}; use tracing::{info, warn}; /// Migration options +#[derive(Default)] pub struct MigrateOptions { /// If true, show what would be migrated without copying pub dry_run: bool, } -impl Default for MigrateOptions { - fn default() -> Self { - Self { dry_run: false } - } -} - /// Migration statistics #[derive(Debug, Default)] pub struct MigrateStats { @@ -64,7 +59,9 @@ pub async fn migrate( let pb = ProgressBar::new(keys.len() as u64); pb.set_style( ProgressStyle::default_bar() - .template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})") + .template( + "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})", + ) .expect("Invalid progress bar template") .progress_chars("#>-"), ); diff --git a/nora-registry/src/rate_limit.rs b/nora-registry/src/rate_limit.rs index 0f47a8b..4c0e2c8 100644 --- a/nora-registry/src/rate_limit.rs +++ b/nora-registry/src/rate_limit.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] //! Rate limiting configuration and middleware //! //! Provides rate limiting to protect against: @@ -27,11 +28,11 @@ pub struct RateLimitConfig { impl Default for RateLimitConfig { fn default() -> Self { Self { - auth_rps: 1, // 1 req/sec for auth (strict) - auth_burst: 5, // Allow burst of 5 - upload_rps: 10, // 10 req/sec for uploads - upload_burst: 20, // Allow burst of 20 - general_rps: 100, // 100 req/sec general + auth_rps: 1, // 1 req/sec for auth (strict) + auth_burst: 5, // Allow burst of 5 + upload_rps: 10, // 10 req/sec for uploads + upload_burst: 20, // Allow burst of 20 + general_rps: 100, // 100 req/sec general general_burst: 200, // Allow burst of 200 } } diff --git a/nora-registry/src/registry/docker.rs b/nora-registry/src/registry/docker.rs index a724d99..b9da170 100644 --- a/nora-registry/src/registry/docker.rs +++ b/nora-registry/src/registry/docker.rs @@ -178,10 +178,7 @@ async fn put_manifest( } } -async fn list_tags( - State(state): State>, - Path(name): Path, -) -> Response { +async fn list_tags(State(state): State>, Path(name): Path) -> Response { if let Err(e) = validate_docker_name(&name) { return (StatusCode::BAD_REQUEST, e.to_string()).into_response(); } diff --git a/nora-registry/src/storage/mod.rs b/nora-registry/src/storage/mod.rs index 891c348..74a36be 100644 --- a/nora-registry/src/storage/mod.rs +++ b/nora-registry/src/storage/mod.rs @@ -76,10 +76,8 @@ impl Storage { pub async fn list(&self, prefix: &str) -> Vec { // Empty prefix is valid for listing all - if !prefix.is_empty() { - if let Err(_) = validate_storage_key(prefix) { - return Vec::new(); - } + if !prefix.is_empty() && validate_storage_key(prefix).is_err() { + return Vec::new(); } self.inner.list(prefix).await } diff --git a/nora-registry/src/ui/templates.rs b/nora-registry/src/ui/templates.rs index 4960809..f280518 100644 --- a/nora-registry/src/ui/templates.rs +++ b/nora-registry/src/ui/templates.rs @@ -59,7 +59,13 @@ pub fn render_dashboard(stats: &RegistryStats) -> String { "##, - stat_card("Docker", icons::DOCKER, stats.docker, "/ui/docker", "images"), + stat_card( + "Docker", + icons::DOCKER, + stats.docker, + "/ui/docker", + "images" + ), stat_card("Maven", icons::MAVEN, stats.maven, "/ui/maven", "artifacts"), stat_card("npm", icons::NPM, stats.npm, "/ui/npm", "packages"), stat_card("Cargo", icons::CARGO, stats.cargo, "/ui/cargo", "crates"), @@ -455,7 +461,9 @@ fn get_registry_icon(registry_type: &str) -> &'static str { "npm" => icons::NPM, "cargo" => icons::CARGO, "pypi" => icons::PYPI, - _ => r#""#, + _ => { + r#""# + } } } diff --git a/nora-registry/src/validation.rs b/nora-registry/src/validation.rs index 8acf074..ea6d534 100644 --- a/nora-registry/src/validation.rs +++ b/nora-registry/src/validation.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] //! Input validation for artifact registry paths and identifiers //! //! Provides security validation to prevent path traversal attacks and @@ -92,7 +93,7 @@ pub fn validate_storage_key(key: &str) -> Result<(), ValidationError> { // Check each segment for segment in key.split('/') { - if segment.is_empty() && key != "" { + if segment.is_empty() && !key.is_empty() { // Allow trailing slash but not double slashes continue; } diff --git a/nora-storage/src/main.rs b/nora-storage/src/main.rs index e215b35..1c75db3 100644 --- a/nora-storage/src/main.rs +++ b/nora-storage/src/main.rs @@ -133,9 +133,7 @@ async fn main() { .expect("Failed to bind to address"); info!("nora-storage (S3 compatible) running on http://{}", addr); - axum::serve(listener, app) - .await - .expect("Server error"); + axum::serve(listener, app).await.expect("Server error"); } async fn list_buckets(State(state): State>) -> Response {