aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index a1dff3e..36e5572 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -12,6 +12,7 @@ use std::path::PathBuf;
pub struct Source {
pub name: String,
pub url: String,
+ #[serde(default, deserialize_with = "deserialize_key_from_file")]
pub psk: Option<Secret>,
pub ipv4: Ipv4Set,
pub ipv6: Ipv6Set,
@@ -26,6 +27,7 @@ pub struct Source {
pub struct Peer {
pub source: Option<String>,
pub endpoint: Option<Endpoint>,
+ #[serde(default, deserialize_with = "deserialize_key_from_file")]
pub psk: Option<Secret>,
pub keepalive: Option<u32>,
}
@@ -153,3 +155,11 @@ const fn default_max_keepalive() -> u32 {
const fn default_refresh_sec() -> u32 {
1200
}
+
+fn deserialize_key_from_file<'de, D>(d: D) -> Result<Option<Secret>, D::Error>
+where
+ D: serde::Deserializer<'de>,
+{
+ let path = <PathBuf as serde::Deserialize<'de>>::deserialize(d)?;
+ Secret::from_file(&path).map_err(|e| <D::Error as serde::de::Error>::custom(e.to_string()))
+}