Refactor config printing
This commit is contained in:
parent
6a6581b64f
commit
012e40eff8
1 changed files with 17 additions and 13 deletions
30
src/main.rs
30
src/main.rs
|
|
@ -134,25 +134,29 @@ fn get_config(_opts: &Opts, config_opts: &ConfigOpts) -> Result<(), anyhow::Erro
|
||||||
])?
|
])?
|
||||||
.into_json()?;
|
.into_json()?;
|
||||||
debug!("config = {:?}", &config);
|
debug!("config = {:?}", &config);
|
||||||
|
|
||||||
|
write_config(&mut std::io::stdout().lock(), &config, &keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_config(
|
||||||
|
output: &mut dyn Write,
|
||||||
|
config: &WireguardConfig,
|
||||||
|
keys: &WireguardKeyPair,
|
||||||
|
) -> Result<(), anyhow::Error> {
|
||||||
let mut endpoint_addrs = config.data.endpoint.to_socket_addrs()?;
|
let mut endpoint_addrs = config.data.endpoint.to_socket_addrs()?;
|
||||||
let endpoint_addr = endpoint_addrs
|
let endpoint_addr = endpoint_addrs
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| anyhow::anyhow!("no endpoint address received"))?;
|
.ok_or_else(|| anyhow::anyhow!("no endpoint address received"))?;
|
||||||
debug!("endpoint_addr = {:?}", &endpoint_addr);
|
debug!("endpoint_addr = {:?}", &endpoint_addr);
|
||||||
println!(
|
writeln!(output, "[Interface]")?;
|
||||||
r"[Interface]
|
writeln!(output, "PrivateKey = {}", &keys.private_key)?;
|
||||||
PrivateKey = {private_key}
|
writeln!(output, "Address = {}", &config.data.address)?;
|
||||||
Address = {address}
|
|
||||||
|
writeln!(output, "[Peer]")?;
|
||||||
|
writeln!(output, "PublicKey = {}", &config.data.public_key)?;
|
||||||
|
writeln!(output, "Endpoint = {}", &endpoint_addr)?;
|
||||||
|
writeln!(output, "AllowedIPs = 0.0.0.0/0 #, ::/0")?;
|
||||||
|
|
||||||
[Peer]
|
|
||||||
PublicKey = {public_key}
|
|
||||||
Endpoint = {endpoint_addr}
|
|
||||||
AllowedIPs = 0.0.0.0/0 #, ::/0",
|
|
||||||
public_key = &config.data.public_key,
|
|
||||||
private_key = &keys.private_key,
|
|
||||||
address = &config.data.address,
|
|
||||||
endpoint_addr = &endpoint_addr,
|
|
||||||
);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue