mirror of
https://github.com/getnora-io/nora.git
synced 2026-04-12 16:10:31 +00:00
fix: resolve clippy warnings and format code
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Commands>,
|
||||
|
||||
@@ -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("#>-"),
|
||||
);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,10 +178,7 @@ async fn put_manifest(
|
||||
}
|
||||
}
|
||||
|
||||
async fn list_tags(
|
||||
State(state): State<Arc<AppState>>,
|
||||
Path(name): Path<String>,
|
||||
) -> Response {
|
||||
async fn list_tags(State(state): State<Arc<AppState>>, Path(name): Path<String>) -> Response {
|
||||
if let Err(e) = validate_docker_name(&name) {
|
||||
return (StatusCode::BAD_REQUEST, e.to_string()).into_response();
|
||||
}
|
||||
|
||||
@@ -76,10 +76,8 @@ impl Storage {
|
||||
|
||||
pub async fn list(&self, prefix: &str) -> Vec<String> {
|
||||
// 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
|
||||
}
|
||||
|
||||
@@ -59,7 +59,13 @@ pub fn render_dashboard(stats: &RegistryStats) -> String {
|
||||
</div>
|
||||
</div>
|
||||
"##,
|
||||
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#"<path fill="currentColor" d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/>"#,
|
||||
_ => {
|
||||
r#"<path fill="currentColor" d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/>"#
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user