aboutsummaryrefslogtreecommitdiff
path: root/src/configuration.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/configuration.rs')
-rw-r--r--src/configuration.rs31
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 @@
1use serde::Deserialize;
2use anyhow::{Result, anyhow, Context};
3use std::fs::read_to_string;
4
5#[derive(Deserialize)]
6pub struct Configuration {
7 pub endpoint: String,
8 pub wgconf: String,
9 pub port: Option<u32>,
10 pub dns: Option<String>,
11}
12
13pub 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}