Use logging

This commit is contained in:
Andrey Golovizin 2021-06-29 23:01:55 +02:00
parent 719eab73b8
commit cca44441b5
3 changed files with 62 additions and 4 deletions

View file

@ -2,6 +2,8 @@ use std::io::Write;
use std::net::ToSocketAddrs;
use std::process;
use log::debug;
use clap::Clap;
use serde::{Deserialize, Serialize};
@ -72,6 +74,7 @@ struct WireguardKeyPair {
}
fn main() -> Result<(), anyhow::Error> {
env_logger::init();
let opts = Opts::parse();
match &opts.command {
Command::List(list_opts) => list(&list_opts)?,
@ -112,9 +115,9 @@ fn get_config(opts: &GetConfigOpts) -> Result<(), anyhow::Error> {
.iter()
.find(|location| location.name == opts.location)
.ok_or_else(|| anyhow::anyhow!("no such location"))?;
dbg!(&location);
debug!("location = {:?}", &location);
let keys = generage_keys()?;
dbg!(&keys);
debug!("keys = {:?}", &keys);
let config: WireguardConfig = ureq::post(&location.endpoints.wireguard)
.send_form(&[
("username", &opts.username),
@ -122,12 +125,12 @@ fn get_config(opts: &GetConfigOpts) -> Result<(), anyhow::Error> {
("pubkey", &keys.public_key),
])?
.into_json()?;
dbg!(&config);
debug!("config = {:?}", &config);
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"))?;
dbg!(&endpoint_addr);
debug!("endpoint_addr = {:?}", &endpoint_addr);
println!(
r"[Interface]
PrivateKey = {}