Skip to content

Commit 8fb46d4

Browse files
authored
fix(derper): update config to auto generate keys (#1599)
## Description Deploying a derper node is a bit cumbersome right now if you don't run with default config. You have to provide a `secret_key` but have no easy path to generate one so either you dance to create a fresh config and then modify it or need to use some external thing to generate keys for you. Either way it's cumbersome. This just adds an extra handler to inject a secret key if not present already in the supplied config. ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [x] Self-review. - [ ] Documentation updates if relevant. - [ ] Tests if relevant.
1 parent fda9c60 commit 8fb46d4

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

iroh-net/src/bin/derper.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ fn load_secret_key(filename: impl AsRef<Path>) -> Result<rustls::PrivateKey> {
166166
struct Config {
167167
/// [`SecretKey`] for this Derper.
168168
#[serde_as(as = "DisplayFromStr")]
169+
#[serde(default = "SecretKey::generate")]
169170
secret_key: SecretKey,
170171
/// Server listen address.
171172
///
@@ -284,10 +285,14 @@ impl Config {
284285
if !path.as_ref().is_file() {
285286
bail!("config-path must be a valid toml file");
286287
}
287-
let config_ser = tokio::fs::read_to_string(path)
288+
let config_ser = tokio::fs::read_to_string(&path)
288289
.await
289290
.context("unable to read config")?;
290-
let config = toml::from_str(&config_ser).context("unable to decode config")?;
291+
let config: Self = toml::from_str(&config_ser).context("unable to decode config")?;
292+
if !config_ser.contains("secret_key") {
293+
info!("generating new secret key and updating config file");
294+
config.write_to_file(path).await?;
295+
}
291296

292297
Ok(config)
293298
}

0 commit comments

Comments
 (0)