use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::time::SystemTime;
use thiserror::Error;
use uvb_core::TenantId;
#[derive(Debug, Error)]
pub enum SecretError {
#[error("secret not found")]
NotFound,
#[error("storage error: {0}")]
Storage(String),
#[error("encryption error: {0}")]
Encryption(String),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SecretRecord {
pub id: String,
pub user_id: String,
pub tenant_id: TenantId,
pub factor_id: String,
pub secret_data: Vec<u8>, pub metadata: serde_json::Value,
pub created_at: SystemTime,
pub updated_at: SystemTime,
}
#[async_trait]
pub trait SecretStore: Send + Sync {
async fn set(
&self,
user_id: &str,
tenant_id: &TenantId,
factor_id: &str,
secret_data: &[u8],
metadata: serde_json::Value,
) -> Result<String, SecretError>;
async fn get(
&self,
user_id: &str,
tenant_id: &TenantId,
factor_id: &str,
) -> Result<Option<SecretRecord>, SecretError>;
async fn get_by_id(&self, id: &str) -> Result<Option<SecretRecord>, SecretError>;
async fn delete(&self, id: &str) -> Result<(), SecretError>;
async fn list(
&self,
user_id: &str,
tenant_id: &TenantId,
factor_id: Option<&str>,
) -> Result<Vec<SecretRecord>, SecretError>;
async fn rotate_encryption(&self) -> Result<usize, SecretError> {
Ok(0)
}
}