uvb_storage_api/
secret.rs1use async_trait::async_trait;
2use serde::{Deserialize, Serialize};
3use std::time::SystemTime;
4use thiserror::Error;
5use uvb_core::TenantId;
6
7#[derive(Debug, Error)]
8pub enum SecretError {
9 #[error("secret not found")]
10 NotFound,
11 #[error("storage error: {0}")]
12 Storage(String),
13 #[error("encryption error: {0}")]
14 Encryption(String),
15}
16
17#[derive(Clone, Debug, Serialize, Deserialize)]
19pub struct SecretRecord {
20 pub id: String,
21 pub user_id: String,
22 pub tenant_id: TenantId,
23 pub factor_id: String,
24 pub secret_data: Vec<u8>, pub metadata: serde_json::Value,
26 pub created_at: SystemTime,
27 pub updated_at: SystemTime,
28}
29
30#[async_trait]
40pub trait SecretStore: Send + Sync {
41 async fn set(
43 &self,
44 user_id: &str,
45 tenant_id: &TenantId,
46 factor_id: &str,
47 secret_data: &[u8],
48 metadata: serde_json::Value,
49 ) -> Result<String, SecretError>;
50
51 async fn get(
53 &self,
54 user_id: &str,
55 tenant_id: &TenantId,
56 factor_id: &str,
57 ) -> Result<Option<SecretRecord>, SecretError>;
58
59 async fn get_by_id(&self, id: &str) -> Result<Option<SecretRecord>, SecretError>;
61
62 async fn delete(&self, id: &str) -> Result<(), SecretError>;
64
65 async fn list(
67 &self,
68 user_id: &str,
69 tenant_id: &TenantId,
70 factor_id: Option<&str>,
71 ) -> Result<Vec<SecretRecord>, SecretError>;
72
73 async fn rotate_encryption(&self) -> Result<usize, SecretError> {
75 Ok(0)
77 }
78}