Files
zesdex/crates/zesdex-iam/src/domain/repository.rs
T

51 lines
1.8 KiB
Rust
Raw Normal View History

#![allow(
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::cast_precision_loss,
clippy::cast_possible_wrap
)]
//! Repository trait definitions (pure — no impls, no concrete persistence).
use std::path::Path;
use crate::domain::oauth::OAuthToken;
use crate::domain::session::Session;
/// Repository for loading, saving, listing, and deleting sessions.
pub trait SessionRepository {
/// List all loadable sessions under `<base_dir>/sessions/`.
fn list_sessions(&self, base_dir: &Path) -> anyhow::Result<Vec<Session>>;
/// Load a single session by id.
fn load_session(&self, base_dir: &Path, id: &str) -> anyhow::Result<Session>;
/// Save a session's metadata to disk.
fn save_session(&self, base_dir: &Path, session: &Session) -> anyhow::Result<()>;
/// Delete a session directory and all its contents.
fn delete_session(&self, base_dir: &Path, id: &str) -> anyhow::Result<()>;
}
/// Repository for per-session PID-file advisory locks.
pub trait SessionLockRepository {
/// Try to acquire the lock for a session directory.
/// Returns `true` if the lock was acquired, `false` if another live
/// process holds it.
fn try_lock(&self, session_dir: &Path) -> anyhow::Result<bool>;
/// Release the lock by removing the lock file.
fn unlock(&self, session_dir: &Path) -> anyhow::Result<()>;
/// Check whether a process with the given PID is alive.
fn is_alive(&self, pid: u32) -> bool;
}
/// Repository for persisting and loading OAuth tokens.
pub trait OAuthRepository {
/// Persist an OAuth token to a JSON file.
fn save_token(&self, path: &Path, token: &OAuthToken) -> anyhow::Result<()>;
/// Load an OAuth token from a JSON file, returning `None` if the file
/// does not exist.
fn load_token(&self, path: &Path) -> anyhow::Result<Option<OAuthToken>>;
}