Skip to main content

pipedash_core/infrastructure/
config_backend.rs

1use std::collections::HashMap;
2
3use async_trait::async_trait;
4use serde::{
5    Deserialize,
6    Serialize,
7};
8
9use crate::domain::{
10    DomainResult,
11    ProviderConfig,
12};
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct StoredPermissions {
16    pub permissions: HashMap<String, bool>,
17    pub last_checked: chrono::DateTime<chrono::Utc>,
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct ConfigExport {
22    pub version: String,
23    pub providers: Vec<ProviderConfig>,
24    pub table_preferences: HashMap<String, String>,
25    pub permissions: HashMap<i64, StoredPermissions>,
26}
27
28impl Default for ConfigExport {
29    fn default() -> Self {
30        Self {
31            version: "1.0".to_string(),
32            providers: Vec::new(),
33            table_preferences: HashMap::new(),
34            permissions: HashMap::new(),
35        }
36    }
37}
38
39#[async_trait]
40pub trait ConfigBackend: Send + Sync {
41    async fn list_providers(&self) -> DomainResult<Vec<ProviderConfig>>;
42
43    async fn get_provider(&self, id: i64) -> DomainResult<Option<ProviderConfig>>;
44
45    async fn create_provider(&self, config: &ProviderConfig) -> DomainResult<i64>;
46
47    async fn update_provider(&self, id: i64, config: &ProviderConfig) -> DomainResult<()>;
48
49    async fn delete_provider(&self, id: i64) -> DomainResult<()>;
50
51    async fn get_table_preferences(
52        &self, provider_id: i64, table_id: &str,
53    ) -> DomainResult<Option<String>>;
54
55    async fn set_table_preferences(
56        &self, provider_id: i64, table_id: &str, preferences_json: &str,
57    ) -> DomainResult<()>;
58
59    async fn store_permissions(
60        &self, provider_id: i64, permissions: &StoredPermissions,
61    ) -> DomainResult<()>;
62
63    async fn get_permissions(&self, provider_id: i64) -> DomainResult<Option<StoredPermissions>>;
64
65    async fn export_all(&self) -> DomainResult<ConfigExport>;
66
67    async fn import_all(&self, data: &ConfigExport) -> DomainResult<HashMap<i64, i64>>;
68}