Files
gitks/config.rs
T

85 lines
2.9 KiB
Rust

//! Copyright (c) 2022-2026 GitDataAi All rights reserved.
//! Centralized configuration constants for GitKS.
//!
//! All magic numbers and resource limits are defined here for easy auditing,
//! tuning, and documentation. Runtime overrides are supported via environment
//! variables where noted.
use std::time::Duration;
/// Maximum number of file actions in a single commit request.
pub const MAX_ACTIONS_PER_COMMIT: usize = 10_000;
/// Maximum commit message size in bytes.
pub const MAX_COMMIT_MESSAGE_BYTES: usize = 10 * 1024 * 1024; // 10 MB
/// Maximum content size for a single file action in bytes.
pub const MAX_ACTION_CONTENT_BYTES: usize = 100 * 1024 * 1024; // 100 MB
/// Maximum packet size for receive-pack streaming (bytes).
pub const MAX_RECEIVE_PACKET_BYTES: usize = 16 * 1024 * 1024; // 16 MB
/// Maximum stderr capture size for receive-pack (bytes).
pub const MAX_RECEIVE_STDERR_BYTES: u64 = 64 * 1024; // 64 KB
/// Timeout for git receive-pack operations.
pub const RECEIVE_PACK_TIMEOUT: Duration = Duration::from_secs(1800); // 30 min
/// Timeout for git upload-pack operations.
pub const UPLOAD_PACK_TIMEOUT: Duration = Duration::from_secs(600); // 10 min
/// Stale lease threshold: leases older than this are considered stale.
pub const LEASE_STALE_THRESHOLD_SECS: u64 = 30;
/// Maximum custom hook script size in bytes.
pub const MAX_HOOK_SCRIPT_SIZE: usize = 65536; // 64 KB
/// Maximum git reference name length.
pub const MAX_REF_NAME_LENGTH: usize = 255;
/// Maximum revision string length.
pub const MAX_REVISION_LENGTH: usize = 256;
/// Maximum ancestry traversal depth (~N and ^N).
pub const MAX_ANCESTRY_DEPTH: u32 = 10_000;
/// Maximum file path length in commit actions.
pub const MAX_FILE_PATH_LENGTH: usize = 4096;
/// Maximum remote URL length.
pub const MAX_REMOTE_URL_LENGTH: usize = 4096;
/// Maximum refspec length.
pub const MAX_REFSPEC_LENGTH: usize = 1024;
/// Maximum relative path length for repository addressing.
pub const MAX_RELATIVE_PATH_LENGTH: usize = 4096;
/// Maximum OID hex length (SHA-256).
pub const MAX_OID_HEX_LENGTH: usize = 64;
/// Minimum OID hex length (short SHA).
pub const MIN_OID_HEX_LENGTH: usize = 4;
/// In-memory cache max weight (key + value allocated bytes).
pub const CACHE_MAX_WEIGHT: u64 = 256 * 1024 * 1024; // 256 MB
/// Hard time-to-live for cache entries.
pub const CACHE_MAX_TTL: Duration = Duration::from_secs(600); // 10 min
/// Time-to-idle for cache entries.
pub const CACHE_TTI: Duration = Duration::from_secs(120); // 2 min
/// Per-entry overhead estimate added to weigher result.
pub const CACHE_ENTRY_OVERHEAD: u32 = 128;
/// Idle threshold for rate-limiter semaphore cleanup.
pub const SEMAPHORE_IDLE_THRESHOLD_SECS: u64 = 300; // 5 min
/// Default max concurrent operations per repository.
pub const DEFAULT_MAX_CONCURRENT_OPS: usize = 5;
/// Rate limit acquire timeout.
pub const RATE_LIMIT_TIMEOUT_SECS: u64 = 30;