aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHristo Venev <hristo@venev.name>2019-03-19 10:30:17 +0200
committerHristo Venev <hristo@venev.name>2019-03-19 10:30:53 +0200
commit7eef7ad915a608f5cad510d079b9240ed11698f1 (patch)
tree4e65dd2a2210bfc893d3fb71252c8b574989f68f
parente143b186a3eba9c03af20156ad3a2e729c638dc9 (diff)
BREAKING CHANGE: The config file is now in toml.
The "sources" field is now [[source]].
-rw-r--r--Cargo.toml1
-rw-r--r--src/config.rs1
-rw-r--r--src/main.rs16
-rw-r--r--wgconfd@.service2
4 files changed, 14 insertions, 6 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 9567aeb..e7dbaf1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,6 +10,7 @@ serde = { version = "1.0.89" }
serde_derive = { version = "1.0.89" }
serde_json = { version = "1.0.39" }
chrono = { version = "0.4.6", default-features = false }
+toml = { version = "0.5" }
[profile.release]
panic = "abort"
diff --git a/src/config.rs b/src/config.rs
index 00874c2..cd874da 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -40,6 +40,7 @@ pub struct Config {
#[serde(flatten)]
pub update_config: UpdateConfig,
+ #[serde(rename = "source")]
pub sources: Vec<Source>,
}
diff --git a/src/main.rs b/src/main.rs
index f5ebb26..d556064 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -204,13 +204,19 @@ fn fetch_source(url: &str) -> io::Result<proto::Source> {
}
fn load_config(path: &str) -> io::Result<config::Config> {
- use serde_json;
+ use toml;
use std::fs;
- let config_file = fs::File::open(path)?;
- let rd = io::BufReader::new(config_file);
- let mut de = serde_json::Deserializer::from_reader(rd);
- Ok(serde::Deserialize::deserialize(&mut de)?)
+ let mut data = String::new();
+ {
+ use io::Read;
+ let mut config_file = fs::File::open(path)?;
+ config_file.read_to_string(&mut data)?;
+ }
+ let mut de = toml::Deserializer::new(&data);
+ serde::Deserialize::deserialize(&mut de).map_err(|e| {
+ io::Error::new(io::ErrorKind::InvalidData, e)
+ })
}
fn main() {
diff --git a/wgconfd@.service b/wgconfd@.service
index d6e4127..db71870 100644
--- a/wgconfd@.service
+++ b/wgconfd@.service
@@ -7,7 +7,7 @@ Before=network-pre.target nftables.service systemd-networkd.service NetworkManag
Type=simple
CapabilityBoundingSet=CAP_NET_ADMIN
ExecStartPre=/usr/bin/wg setconf %i /etc/wireguard/%i.conf
-ExecStart=/usr/local/bin/wgconfd %i /etc/wireguard/%i.json
+ExecStart=/usr/local/bin/wgconfd %i /etc/wireguard/%i.toml
StandardError=journal
SyslogLevelPrefix=true