diff options
Diffstat (limited to 'src/configuration.rs')
-rw-r--r-- | src/configuration.rs | 31 |
1 files changed, 0 insertions, 31 deletions
diff --git a/src/configuration.rs b/src/configuration.rs deleted file mode 100644 index 839db24..0000000 --- a/src/configuration.rs +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | use serde::Deserialize; | ||
2 | use anyhow::{Result, anyhow, Context}; | ||
3 | use std::fs::read_to_string; | ||
4 | |||
5 | #[derive(Deserialize)] | ||
6 | pub struct Configuration { | ||
7 | pub endpoint: String, | ||
8 | pub wgconf: String, | ||
9 | pub port: Option<u32>, | ||
10 | pub dns: Option<String>, | ||
11 | } | ||
12 | |||
13 | pub fn find_configuration_file(argument: Option<&String>) -> Result<Configuration> { | ||
14 | match argument { | ||
15 | Some(p) => { | ||
16 | if let Ok(t) = read_to_string(p) { | ||
17 | let c: Configuration = toml::from_str(&t).context("parsing configuration file")?; | ||
18 | return Ok(c) | ||
19 | } | ||
20 | }, | ||
21 | None => { | ||
22 | // Try /etc/wgmgr.toml | ||
23 | if let Ok(t) = read_to_string("/etc/wgmgr.toml") { | ||
24 | let c: Configuration = toml::from_str(&t).context("parsing /etc/wgmgr.toml")?; | ||
25 | return Ok(c) | ||
26 | } | ||
27 | }, | ||
28 | }; | ||
29 | |||
30 | Err(anyhow!("Could not find a valid configuration file for wgmgr.")) | ||
31 | } | ||