27a8619
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<Arc<RedisCache>>,
}
impl GitSshService {
pub fn new(auth: GitAuthService, config: GitSshConfig) -> Self {
Self {
auth,
config,
kv: None,
}
}
pub fn with_kv(mut self, kv: Option<Arc<RedisCache>>) -> Self {
self.kv = kv;
self
}
pub fn push_coordinator(&self) -> PushCoordinator {
match &self.kv {
Some(kv) => {
let backend: Arc<dyn gitsmart::push::PushOperations> =
Arc::new(RedisPushBackend { kv: kv.clone() });
PushCoordinator::new(backend)
}
None => {
let backend: Arc<dyn gitsmart::push::PushOperations> = 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))
}
}