diff --git a/Cargo.lock b/Cargo.lock index ced3029..01a2a0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. 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]] name = "autocfg" version = "1.0.1" @@ -44,6 +55,17 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "core-foundation" version = "0.9.2" @@ -154,9 +176,11 @@ dependencies = [ name = "godaddy_ddns" version = "0.1.0" dependencies = [ + "log", "reqwest", "serde", "serde_json", + "simple_logger", "tokio", ] @@ -350,6 +374,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ "cfg-if", + "serde", ] [[package]] @@ -731,6 +756,19 @@ dependencies = [ "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]] name = "slab" version = "0.4.5" @@ -778,6 +816,23 @@ dependencies = [ "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]] name = "tinyvec" version = "1.5.1" diff --git a/Cargo.toml b/Cargo.toml index e6a3f4e..af284de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,6 @@ edition = "2021" reqwest = { version = "0.11", features = ["json"] } tokio = { version = "1", features = ["full"] } serde = { version = "1.0.132", features = ["derive"]} -serde_json = "1.0" \ No newline at end of file +serde_json = "1.0" +log = { version = "0.4", features = ["std", "serde"] } +simple_logger = "1.16.0" \ No newline at end of file diff --git a/src/go_daddy_ddns/mod.rs b/src/go_daddy_ddns/mod.rs index c1a9ec2..e877ec1 100644 --- a/src/go_daddy_ddns/mod.rs +++ b/src/go_daddy_ddns/mod.rs @@ -97,8 +97,13 @@ fn get_records() -> Vec { /// * `key` - A &str holding the GoDaddy developer key. /// /// * `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!( "https://api.godaddy.com/v1/domains/{domain}/records/{record_type}/{name}", domain = domain, diff --git a/src/main.rs b/src/main.rs index 8973c59..2bd189e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,22 @@ mod go_daddy_ddns; mod ip_handler; +use log::LevelFilter; +use simple_logger::SimpleLogger; use std::env; #[tokio::main] async fn main() -> Result<(), Box> { - let domain = env::var("DOMAIN").unwrap(); - let key = env::var("KEY").unwrap(); - let secret = env::var("SECRET").unwrap(); + SimpleLogger::new() + .with_colors(true) + .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 }