Skip to main content

kellnr_settings/
registry.rs

1use clap_serde_derive::ClapSerde;
2use serde::{Deserialize, Serialize};
3
4use crate::compile_time_config;
5
6fn default_data_dir() -> String {
7    // Priority: runtime env var > compile-time > empty (must be set via CLI or config)
8    std::env::var("KELLNR_DATA_DIR")
9        .ok()
10        .or_else(|| compile_time_config::KELLNR_COMPTIME__DATA_DIR.map(String::from))
11        .unwrap_or_default()
12}
13
14#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone, ClapSerde)]
15#[serde(default)]
16#[allow(clippy::struct_excessive_bools)]
17pub struct Registry {
18    /// Data directory for crates, index, and database
19    #[default(default_data_dir())]
20    #[arg(id = "registry-data-dir", long = "registry-data-dir", short = 'd')]
21    pub data_dir: String,
22
23    /// Session timeout in seconds
24    #[default(60 * 60 * 8)]
25    #[arg(id = "registry-session-age", long = "registry-session-age")]
26    pub session_age_seconds: u64,
27
28    /// Cache size
29    #[default(1000)]
30    #[arg(id = "registry-cache-size", long = "registry-cache-size")]
31    pub cache_size: u64,
32
33    /// Max crate size in MB
34    #[default(10)]
35    #[arg(id = "registry-max-crate-size", long = "registry-max-crate-size")]
36    pub max_crate_size: u64,
37
38    /// Max database connections (0 = unlimited)
39    #[default(0)]
40    #[arg(
41        id = "registry-max-db-connections",
42        long = "registry-max-db-connections"
43    )]
44    pub max_db_connections: u32,
45
46    /// Require authentication for all operations
47    #[default(false)]
48    #[arg(id = "registry-auth-required", long = "registry-auth-required")]
49    pub auth_required: bool,
50
51    /// Required crate fields (comma-separated)
52    #[default(Vec::new())]
53    #[arg(
54        id = "registry-required-crate-fields",
55        long = "registry-required-crate-fields",
56        value_delimiter = ','
57    )]
58    pub required_crate_fields: Vec<String>,
59
60    /// Restrict new crate uploads to admins
61    #[default(false)]
62    #[arg(
63        id = "registry-new-crates-restricted",
64        long = "registry-new-crates-restricted"
65    )]
66    pub new_crates_restricted: bool,
67
68    /// Cookie signing key (for multi-instance setups)
69    #[default(None)]
70    #[arg(
71        id = "registry-cookie-signing-key",
72        long = "registry-cookie-signing-key"
73    )]
74    pub cookie_signing_key: Option<String>,
75
76    /// Allow crates without owners
77    #[default(false)]
78    #[arg(
79        id = "registry-allow-ownerless-crates",
80        long = "registry-allow-ownerless-crates"
81    )]
82    pub allow_ownerless_crates: bool,
83
84    /// Enable token cache
85    #[default(true)]
86    #[arg(
87        id = "registry-token-cache-enabled",
88        long = "registry-token-cache-enabled"
89    )]
90    pub token_cache_enabled: bool,
91
92    /// Token cache TTL in seconds
93    #[default(1800)]
94    #[arg(id = "registry-token-cache-ttl", long = "registry-token-cache-ttl")]
95    pub token_cache_ttl_seconds: u64,
96
97    /// Token cache max capacity
98    #[default(10000)]
99    #[arg(
100        id = "registry-token-cache-max-capacity",
101        long = "registry-token-cache-max-capacity"
102    )]
103    pub token_cache_max_capacity: u64,
104
105    /// Token DB retry count
106    #[default(3)]
107    #[arg(
108        id = "registry-token-db-retry-count",
109        long = "registry-token-db-retry-count"
110    )]
111    pub token_db_retry_count: u32,
112
113    /// Token DB retry delay in ms
114    #[default(100)]
115    #[arg(
116        id = "registry-token-db-retry-delay",
117        long = "registry-token-db-retry-delay"
118    )]
119    pub token_db_retry_delay_ms: u64,
120
121    /// Download request timeout in seconds (0 = disabled)
122    #[default(60)]
123    #[arg(id = "registry-download-timeout", long = "registry-download-timeout")]
124    pub download_timeout_seconds: u64,
125
126    /// Max concurrent download requests (0 = unlimited)
127    #[default(20)]
128    #[arg(
129        id = "registry-download-max-concurrent",
130        long = "registry-download-max-concurrent"
131    )]
132    pub download_max_concurrent: usize,
133    /// Download counter flush interval in seconds (0 = flush every download)
134    #[default(30)]
135    #[arg(
136        id = "registry-download-counter-flush",
137        long = "registry-download-counter-flush"
138    )]
139    pub download_counter_flush_seconds: u64,
140}