From d61ea368985d06b091e4e91e1efb57d0612c5032 Mon Sep 17 00:00:00 2001 From: Asmir Avdicevic Date: Mon, 9 Oct 2023 11:02:02 +0200 Subject: [PATCH] fix(derper): update config to auto generate keys --- iroh-net/src/bin/derper.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/iroh-net/src/bin/derper.rs b/iroh-net/src/bin/derper.rs index ef19b3d7592..b7dc6866fbe 100644 --- a/iroh-net/src/bin/derper.rs +++ b/iroh-net/src/bin/derper.rs @@ -284,10 +284,23 @@ impl Config { if !path.as_ref().is_file() { bail!("config-path must be a valid toml file"); } - let config_ser = tokio::fs::read_to_string(path) + let mut config_ser = tokio::fs::read_to_string(&path) .await .context("unable to read config")?; - let config = toml::from_str(&config_ser).context("unable to decode config")?; + let secret_key_injected = false; + if !config_ser.contains("secret_key") { + config_ser = format!( + r#" + secret_key = "{}" + {}"#, + SecretKey::generate(), + config_ser + ); + } + let config: Self = toml::from_str(&config_ser).context("unable to decode config")?; + if secret_key_injected { + config.write_to_file(path).await?; + } Ok(config) }