Skip to content

Commit

Permalink
fix: remove zone_id, zone_name and update functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo1107 committed Feb 5, 2025
1 parent dd34cb6 commit 026ca96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
30 changes: 18 additions & 12 deletions src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ trait Info {
}

pub trait Requests {
fn update_request(
&self,
fn update_request<'a>(
&'a self,
ip: IpAddr,
) -> Option<UpdateDnsRecord>;
id: &'a str,
) -> Option<UpdateDnsRecord<'a>>;
fn create_request<'a>(
ip: IpAddr,
name: &'a str,
id: &'a str,
) -> CreateDnsRecord<'a>;
fn delete_request(&self) -> DeleteDnsRecord;
fn delete_request<'a>(
&'a self,
id: &'a str,
) -> DeleteDnsRecord<'a>;
}
impl Clone_ for DnsRecord {
fn clone(&self) -> Self {
Expand All @@ -47,14 +51,12 @@ impl Clone_ for DnsRecord {
auto_added: self.meta.auto_added,
},
ttl: self.ttl,
zone_id: self.zone_id.to_owned(),
modified_on: self.modified_on,
created_on: self.created_on,
proxiable: self.proxiable,
proxied: self.proxied,
content: self.content.to_owned(),
id: self.id.to_owned(),
zone_name: self.zone_name.to_owned(),
}
}
}
Expand Down Expand Up @@ -84,10 +86,11 @@ impl Info for DnsContent {
}

impl Requests for DnsRecord {
fn update_request(
&self,
fn update_request<'a>(
&'a self,
ip: IpAddr,
) -> Option<UpdateDnsRecord> {
id: &'a str,
) -> Option<UpdateDnsRecord<'a>> {
let current_ip = self.content.get_ip()?;

if ip == current_ip {
Expand All @@ -111,7 +114,7 @@ impl Requests for DnsRecord {

log::info!("request: {} ({} → {})\n", self.name, current_ip, ip);
Some(UpdateDnsRecord {
zone_identifier: &self.zone_id,
zone_identifier: id,
identifier: &self.id,
params: UpdateDnsRecordParams {
name: &self.name,
Expand Down Expand Up @@ -142,14 +145,17 @@ impl Requests for DnsRecord {
}
}

fn delete_request(&self) -> DeleteDnsRecord {
fn delete_request<'a>(
&'a self,
id: &'a str,
) -> DeleteDnsRecord<'a> {
log::info!(
"deleting {} record: {}\n",
self.content.get_type(),
self.name
);
DeleteDnsRecord {
zone_identifier: &self.zone_id,
zone_identifier: id,
identifier: &self.id,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl DynDns for Option<IpAddr> {
match rec.content {
DnsContent::A { content: _ }
| DnsContent::AAAA { content: _ } => Some(tokio::spawn(async move {
if let Some(req) = rec.update_request(ip) {
if let Some(req) = rec.update_request(ip, &id) {
client.request(&req).await?;
}
Ok(())
Expand All @@ -51,7 +51,7 @@ impl DynDns for Option<IpAddr> {
} else {
rec.map(|rec| {
tokio::spawn(async move {
client.request(&rec.delete_request()).await?;
client.request(&rec.delete_request(&id)).await?;
Ok(())
})
})
Expand Down

0 comments on commit 026ca96

Please sign in to comment.