1use serde::Deserialize;
2
3use crate::database::Database;
4#[derive(Debug, Deserialize)]
5pub struct Config {
6 pub hcloud_api_token: String,
7 pub ssh_key_path: String,
8 pub ssh_key_name: String,
9 pub image: String,
10 pub server_type: String,
11 pub location: String,
12 pub user_data: String,
13}
14
15impl Default for Config {
16 fn default() -> Self {
17 Self::new()
18 }
19}
20
21impl Config {
22 #[must_use]
23 pub fn new() -> Self {
24 let database = Database::new();
25 let hcloud_api_token = database.get("hcloud_token").unwrap_or_default();
26 let ssh_key_path = database.get("ssh_key_path").unwrap_or_default();
27 let ssh_key_name = database.get("ssh_key_name").unwrap_or_default();
28 let image = database.get("image").unwrap_or_default();
29 let server_type = database.get("server_type").unwrap_or_default();
30 let location = database.get("location").unwrap_or_default();
31 let user_data = database.get("user_data").unwrap_or_default();
32
33 Self {
34 hcloud_api_token,
35 ssh_key_path,
36 ssh_key_name,
37 image,
38 server_type,
39 location,
40 user_data,
41 }
42 }
43}
44
45pub fn load_config(_config_path: &str) -> Result<Config, Box<dyn std::error::Error + Send + Sync>> {
51 Ok(Config::new())
52}