uvb_storage_api/
enrollment.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 EnrollmentError {
9 #[error("enrollment not found")]
10 NotFound,
11 #[error("already enrolled")]
12 AlreadyEnrolled,
13 #[error("storage error: {0}")]
14 Storage(String),
15}
16
17#[derive(Clone, Debug, Serialize, Deserialize)]
19pub struct EnrollmentRecord {
20 pub id: String,
21 pub user_id: String,
22 pub tenant_id: TenantId,
23 pub factor_id: String,
24 pub status: EnrollmentStatus,
25 pub display_name: Option<String>, pub metadata: serde_json::Value,
27 pub enrolled_at: SystemTime,
28 pub last_used_at: Option<SystemTime>,
29 pub use_count: u64,
30}
31
32#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
33pub enum EnrollmentStatus {
34 Active,
35 Suspended,
36 Revoked,
37}
38
39#[async_trait]
41pub trait EnrollmentStore: Send + Sync {
42 async fn create(&self, record: EnrollmentRecord) -> Result<String, EnrollmentError>;
44
45 async fn get(&self, id: &str) -> Result<Option<EnrollmentRecord>, EnrollmentError>;
47
48 async fn is_enrolled(
50 &self,
51 user_id: &str,
52 tenant_id: &TenantId,
53 factor_id: &str,
54 ) -> Result<bool, EnrollmentError>;
55
56 async fn list_by_user(
58 &self,
59 user_id: &str,
60 tenant_id: &TenantId,
61 ) -> Result<Vec<EnrollmentRecord>, EnrollmentError>;
62
63 async fn update(&self, record: EnrollmentRecord) -> Result<(), EnrollmentError>;
65
66 async fn delete(&self, id: &str) -> Result<(), EnrollmentError>;
68
69 async fn record_usage(&self, id: &str) -> Result<(), EnrollmentError>;
71}