zuka
zuka/src/core/mod.rs

worklyn / zukapublic

Agent-first git hosting. One Rust binary: git over HTTP and SSH, a REST API, MCP, CI, and multi-tenant isolation.

Get a copy: git clone https://zuka.worklyn.com/worklyn/zuka.git
zuka/src/core/mod.rs
RSmod.rs1.7 KBDownload
1// Domain operations shared by every facade.
2//
3// REST, MCP and SSH translate wire formats; the decisions live here and in `git/`.
4// Anything a facade would otherwise implement twice belongs in this module.
5
6pub mod repo;
7
8use crate::account::Identity;
9use crate::error::{Error, Result};
10use crate::git::validate::Name;
11use crate::http::AppState;
12use crate::store::RepoRecord;
13use std::path::PathBuf;
14
15/// What a caller intends to do with a repository.
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum Access {
18 Read,
19 Write,
20 Admin,
21}
22
23impl AppState {
24 /// Resolve a repository for a caller: check access, confirm it is ready, and
25 /// return its record and path.
26 ///
27 /// This sequence appeared seven times before it lived here — in both facades,
28 /// the git transport, the SSH session and three separate handlers — with three
29 /// of them quietly differing. `Write` additionally enforces the disk reserve and
30 /// the storage quota, so no write path can forget them.
31 pub fn open_repo(
32 &self,
33 identity: &Identity,
34 account: &Name,
35 repo: &Name,
36 access: Access,
37 ) -> Result<(RepoRecord, PathBuf)> {
38 match access {
39 Access::Read => identity.require_read(account, repo)?,
40 Access::Write => identity.require_write(account, repo)?,
41 Access::Admin => identity.require_repo_admin(account, repo)?,
42 }
43
44 let record = self
45 .meta
46 .get_ready_repo(account, repo)?
47 .ok_or(Error::NotFound("repository"))?;
48
49 if access == Access::Write {
50 self.ensure_space()?;
51 self.check_write_quota(account, repo)?;
52 }
53
54 Ok((record, self.git.repo_path(account, repo)?))
55 }
56}