use std::path::PathBuf; use std::sync::Arc; use cache::RedisCache; use gitauth::{GitAuthService, ResolvedRepo}; use gitsmart::push::{NoopPushBackend, PushCoordinator, RedisPushBackend}; use crate::config::GitSshConfig; #[derive(Clone)] pub struct GitSshService { pub auth: GitAuthService, pub config: GitSshConfig, pub kv: Option>, } impl GitSshService { pub fn new(auth: GitAuthService, config: GitSshConfig) -> Self { Self { auth, config, kv: None, } } pub fn with_kv(mut self, kv: Option>) -> Self { self.kv = kv; 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)) } }