Use logging
This commit is contained in:
parent
719eab73b8
commit
cca44441b5
3 changed files with 62 additions and 4 deletions
53
Cargo.lock
generated
53
Cargo.lock
generated
|
|
@ -1,5 +1,14 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.41"
|
||||
|
|
@ -29,6 +38,8 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"env_logger",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"ureq",
|
||||
|
|
@ -102,6 +113,19 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"humantime",
|
||||
"log",
|
||||
"regex",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.0.1"
|
||||
|
|
@ -136,6 +160,12 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.3"
|
||||
|
|
@ -199,6 +229,12 @@ version = "0.1.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.8.0"
|
||||
|
|
@ -259,6 +295,23 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.16.20"
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ edition = "2018"
|
|||
[dependencies]
|
||||
anyhow = "1.0.41"
|
||||
clap = "3.0.0-beta.2"
|
||||
env_logger = "0.8.4"
|
||||
log = "0.4.14"
|
||||
serde = { version = "1.0.126", features = ["derive"] }
|
||||
serde_json = "1.0.64"
|
||||
ureq = { version = "2.1.1", features = ["json"] }
|
||||
|
|
|
|||
11
src/main.rs
11
src/main.rs
|
|
@ -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 = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue