Added some logging lines.

This commit is contained in:
shad0wflame 2021-12-22 17:34:54 +01:00
parent cae24f70c1
commit 504fc87b83
2 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,6 @@
use std::fs::read_to_string; use std::fs::read_to_string;
use std::path::Path; use std::path::Path;
use log::{debug, info};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -57,16 +58,18 @@ struct DNSRecordCreateTypeName {
/// ///
/// * `secret` - A &str holding the GoDaddy developer secret. /// * `secret` - A &str holding the GoDaddy developer secret.
pub async fn exec(domain: &str, key: &str, secret: &str) -> Result<(), Box<dyn std::error::Error>> { pub async fn exec(domain: &str, key: &str, secret: &str) -> Result<(), Box<dyn std::error::Error>> {
info!("Checking if the IP has changed.");
let new_ip = get_ip_to_publish().await; let new_ip = get_ip_to_publish().await;
// There's no need to do anything here. So we stop the execution. // There's no need to do anything here. So we stop the execution.
if Option::is_none(&new_ip) { if Option::is_none(&new_ip) {
info!("The IP hasn't changed. Let's stop the execution here.");
return Ok(()); return Ok(());
} }
let records = get_records(); info!("The IP has changed. Let's update the DNS records.");
for record in get_records() {
for record in records { debug!("{:?}", record);
update_record(&record, &new_ip.clone().unwrap(), domain, key, secret).await; update_record(&record, &new_ip.clone().unwrap(), domain, key, secret).await;
} }

View File

@ -2,6 +2,7 @@ use serde::Deserialize;
use std::fs::{read_to_string, File}; use std::fs::{read_to_string, File};
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::Path;
use log::debug;
const IP_FILE_NAME: &'static str = "ddns_ip"; const IP_FILE_NAME: &'static str = "ddns_ip";
const WEBSITE_URL: &'static str = "https://httpbin.org/ip"; const WEBSITE_URL: &'static str = "https://httpbin.org/ip";
@ -22,6 +23,8 @@ pub async fn get_ip_to_publish() -> Option<String> {
.await .await
.expect("Error getting the current IP."); .expect("Error getting the current IP.");
debug!("Current IP: {}, Previous IP: {}", current_ip, previous_ip);
if current_ip.eq(&previous_ip) { if current_ip.eq(&previous_ip) {
return None; return None;
} }