b2_backblaze/
config.rs

1
2#[derive(Debug,Clone)]
3pub struct Config{
4    pub id:String,
5    pub key:String,
6}
7
8impl Config{
9    pub fn new(
10        id:String,
11        key:String,
12    )->Config{
13        Config{
14            id:id,
15            key:key,
16        }
17    }
18}
19
20impl Config{
21    pub async fn from_file(path:&str)->Result<Config,&'static str>{
22        let data = crate::io::read_as_json(path).await?;
23        if !data["keyID"].is_string(){
24            return Err("not_found-keyID");
25        }
26        if !data["applicationKey"].is_string(){
27            return Err("not_found-applicationKey");
28        }
29        let id = data["keyID"].as_str().unwrap();
30        let key = data["applicationKey"].as_str().unwrap();
31        Ok(Config{
32            id:id.to_string(),
33            key:key.to_string()
34        })
35    }
36}
37