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()?;
|
||||
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 endpoint_addr = endpoint_addrs
|
||||
.next()
|
||||
.ok_or_else(|| anyhow::anyhow!("no endpoint address received"))?;
|
||||
debug!("endpoint_addr = {:?}", &endpoint_addr);
|
||||
println!(
|
||||
r"[Interface]
|
||||
PrivateKey = {private_key}
|
||||
Address = {address}
|
||||
writeln!(output, "[Interface]")?;
|
||||
writeln!(output, "PrivateKey = {}", &keys.private_key)?;
|
||||
writeln!(output, "Address = {}", &config.data.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(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue