Skip to content
Clone
f8c6a14
122 lines 3.3 KB Rust
use std::time::Duration;
use serde::{Deserialize, Serialize};
use crate::duration::{deserialize_opt_std_duration, deserialize_std_duration};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct SmartConfig {
pub bind_addr: String,
pub port: u16,
pub git_storage_root: String,
pub lfs_storage_root: String,
pub object_cache_prefix: String,
pub object_cache_ttl: u64,
pub max_lfs_object_size: u64,
}
impl Default for SmartConfig {
fn default() -> Self {
Self {
bind_addr: "0.0.0.0".to_string(),
port: 8080,
git_storage_root: "/var/lib/repo/git".to_string(),
lfs_storage_root: "/var/lib/repo/lfs".to_string(),
object_cache_prefix: "gitsmart".to_string(),
object_cache_ttl: 300,
max_lfs_object_size: 1 << 30,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct GitSshConfig {
pub bind_addr: String,
pub port: u16,
pub host_key_path: String,
pub git_storage_root: String,
pub max_sessions: usize,
pub banner: Option<String>,
#[serde(default, deserialize_with = "deserialize_std_duration")]
pub auth_rejection_time: Duration,
#[serde(default, deserialize_with = "deserialize_opt_std_duration")]
pub inactivity_timeout: Option<Duration>,
#[serde(default, deserialize_with = "deserialize_std_duration")]
pub keepalive_interval: Duration,
pub keepalive_max: u32,
}
impl Default for GitSshConfig {
fn default() -> Self {
Self {
bind_addr: "0.0.0.0".to_string(),
port: 2222,
host_key_path: "/etc/gitssh/ssh_host_ed25519_key".to_string(),
git_storage_root: "/var/lib/repo/git".to_string(),
max_sessions: 32,
banner: None,
auth_rejection_time: Duration::from_secs(1),
inactivity_timeout: Some(Duration::from_secs(300)),
keepalive_interval: Duration::from_secs(30),
keepalive_max: 3,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct GitAuthConfig {
pub allow_anonymous_read: bool,
}
impl Default for GitAuthConfig {
fn default() -> Self {
Self {
allow_anonymous_read: false,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct SyncSettings {
pub queue_topic: String,
pub dlq_topic: String,
pub group_id: String,
pub concurrency: usize,
pub lock_ttl_secs: u64,
pub max_commits_per_sync: usize,
pub max_lock_retries: u32,
pub language_timeout_secs: u64,
pub max_languages: usize,
}
impl Default for SyncSettings {
fn default() -> Self {
Self {
queue_topic: "gta.git.sync".to_string(),
dlq_topic: "gta.git.sync.dlq".to_string(),
group_id: "git-sync-workers".to_string(),
concurrency: 4,
lock_ttl_secs: 300,
max_commits_per_sync: 10_000,
max_lock_retries: 5,
language_timeout_secs: 30,
max_languages: 50,
}
}
}
impl SyncSettings {
#[must_use]
pub fn lock_ttl(&self) -> Duration {
Duration::from_secs(self.lock_ttl_secs)
}
#[must_use]
pub fn language_timeout(&self) -> Duration {
Duration::from_secs(self.language_timeout_secs)
}
}