use evault_core::model::{Group, VarId, VarKind};
use secrecy::SecretString;
use thiserror::Error;
use time::OffsetDateTime;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VarSummary {
pub id: VarId,
pub name: String,
pub group: Group,
pub kind: VarKind,
pub value_len: usize,
pub linked_projects: usize,
pub updated_at: OffsetDateTime,
}
#[non_exhaustive]
#[derive(Error, Debug)]
pub enum ProviderError {
#[error("data unavailable: {0}")]
DataUnavailable(String),
#[error("backend error: {0}")]
Backend(String),
}
pub trait VarProvider: Send + Sync {
fn list(&self) -> Result<Vec<VarSummary>, ProviderError>;
fn get_value(&self, id: VarId) -> Result<Option<SecretString>, ProviderError>;
}
pub trait VarMutator: Send + Sync {
fn delete(&self, id: VarId) -> Result<(), ProviderError>;
fn create(&self, draft: VarDraft) -> Result<VarId, ProviderError>;
fn update_value(&self, id: VarId, value: SecretString) -> Result<(), ProviderError>;
fn link_to_project(
&self,
var_id: VarId,
var_name: String,
project_path: std::path::PathBuf,
profile: String,
materialize: bool,
) -> Result<(), ProviderError>;
fn run_in_project(
&self,
project_path: std::path::PathBuf,
profile: String,
program: String,
args: Vec<String>,
) -> Result<Option<i32>, ProviderError>;
}
#[derive(Debug, Clone)]
pub struct VarDraft {
pub name: String,
pub group: Group,
pub kind: VarKind,
pub value: SecretString,
}