Added logging.

This commit is contained in:
shad0wflame 2021-12-22 17:18:10 +01:00
parent 0de0754e5b
commit cae24f70c1
4 changed files with 77 additions and 6 deletions

55
Cargo.lock generated
View File

@ -2,6 +2,17 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.0.1" version = "1.0.1"
@ -44,6 +55,17 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "colored"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"
dependencies = [
"atty",
"lazy_static",
"winapi",
]
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.2" version = "0.9.2"
@ -154,9 +176,11 @@ dependencies = [
name = "godaddy_ddns" name = "godaddy_ddns"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"log",
"reqwest", "reqwest",
"serde", "serde",
"serde_json", "serde_json",
"simple_logger",
"tokio", "tokio",
] ]
@ -350,6 +374,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"serde",
] ]
[[package]] [[package]]
@ -731,6 +756,19 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "simple_logger"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45b60258a35dc3cb8a16890b8fd6723349bfa458d7960e25e633f1b1c19d7b5e"
dependencies = [
"atty",
"colored",
"log",
"time",
"winapi",
]
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.5" version = "0.4.5"
@ -778,6 +816,23 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "time"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41effe7cfa8af36f439fac33861b66b049edc6f9a32331e2312660529c1c24ad"
dependencies = [
"itoa 0.4.8",
"libc",
"time-macros",
]
[[package]]
name = "time-macros"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25eb0ca3468fc0acc11828786797f6ef9aa1555e4a211a60d64cc8e4d1be47d6"
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.5.1" version = "1.5.1"

View File

@ -10,3 +10,5 @@ reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
serde = { version = "1.0.132", features = ["derive"]} serde = { version = "1.0.132", features = ["derive"]}
serde_json = "1.0" serde_json = "1.0"
log = { version = "0.4", features = ["std", "serde"] }
simple_logger = "1.16.0"

View File

@ -97,8 +97,13 @@ fn get_records() -> Vec<DNSRecord> {
/// * `key` - A &str holding the GoDaddy developer key. /// * `key` - A &str holding the GoDaddy developer key.
/// ///
/// * `secret` - A &str holding the GoDaddy developer secret. /// * `secret` - A &str holding the GoDaddy developer secret.
async fn update_record(record: &DNSRecord, value: &str, domain: &str, key: &str, secret: &str) -> () { async fn update_record(
record: &DNSRecord,
value: &str,
domain: &str,
key: &str,
secret: &str,
) -> () {
let url = format!( let url = format!(
"https://api.godaddy.com/v1/domains/{domain}/records/{record_type}/{name}", "https://api.godaddy.com/v1/domains/{domain}/records/{record_type}/{name}",
domain = domain, domain = domain,

View File

@ -1,13 +1,22 @@
mod go_daddy_ddns; mod go_daddy_ddns;
mod ip_handler; mod ip_handler;
use log::LevelFilter;
use simple_logger::SimpleLogger;
use std::env; use std::env;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
let domain = env::var("DOMAIN").unwrap(); SimpleLogger::new()
let key = env::var("KEY").unwrap(); .with_colors(true)
let secret = env::var("SECRET").unwrap(); .with_utc_timestamps()
.with_level(LevelFilter::Debug)
.init()
.unwrap();
let domain = env::var("DOMAIN").expect("You need to set DOMAIN env variable first.");
let key = env::var("KEY").expect("You need to set KEY env variable first.");
let secret = env::var("SECRET").expect("You need to set SECRET env variable first.");
go_daddy_ddns::exec(&domain, &key, &secret).await go_daddy_ddns::exec(&domain, &key, &secret).await
} }