use std::path::PathBuf; use std::sync::Arc; use cache::RedisCache; use gitauth::{GitAuthService, ResolvedRepo}; use gitsmart::push::{NoopPushBackend, PushCoordinator, RedisPushBackend}; use config::git::GitSshConfig; #[derive(Clone)] pub struct GitSshService { pub auth: GitAuthService, pub config: GitSshConfig, pub kv: Option>, pub queue: Option>, pub sync_settings: config::git::SyncSettings, } impl GitSshService { pub fn new(auth: GitAuthService, config: GitSshConfig) -> Self { Self { auth, config, kv: None, queue: None, sync_settings: config::git::SyncSettings::default(), } } pub fn with_kv(mut self, kv: Option>) -> Self { self.kv = kv; self } pub fn with_queue(mut self, queue: Option>) -> Self { self.queue = queue; self } pub fn with_sync_settings(mut self, settings: config::git::SyncSettings) -> Self { self.sync_settings = settings; self } pub fn push_coordinator(&self) -> PushCoordinator { match &self.kv { Some(kv) => { let backend: Arc = Arc::new(RedisPushBackend { kv: kv.clone() }); PushCoordinator::new(backend) } None => { let backend: Arc = Arc::new(NoopPushBackend); PushCoordinator::new(backend) } } } pub fn bare_path(&self, resolved: &ResolvedRepo) -> PathBuf { PathBuf::from(&self.config.git_storage_root) .join(resolved.channel.id.to_string()) .join(format!("{}.git", resolved.repo.id)) } }