-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.rs
38 lines (33 loc) · 965 Bytes
/
config.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub providers: Vec<ProviderConfig>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProviderConfig {
pub name: String,
pub enabled: bool,
pub credentials: ProviderCredentials,
pub mappings: Vec<FolderMapping>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProviderCredentials {
#[serde(rename = "type")]
pub provider_type: String,
pub client_id: String,
pub client_secret: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FolderMapping {
pub local_path: PathBuf,
pub remote_path: String,
}
impl Config {
pub async fn from_file<P: AsRef<Path>>(path: P) -> Result<Self> {
let content = tokio::fs::read_to_string(path).await?;
let config = toml::from_str(&content)?;
Ok(config)
}
}