Fix class methods
This commit is contained in:
parent
4525eb1974
commit
add93f26f4
1 changed files with 55 additions and 48 deletions
23
src/main.rs
23
src/main.rs
|
@ -55,17 +55,25 @@ struct DnsEntry {
|
|||
}
|
||||
|
||||
impl DnsEntry {
|
||||
fn update(&self, change4: &mut ChangeTracker, change6: &mut ChangeTracker, agent: &Instance, ips: &Ips) {
|
||||
fn update(
|
||||
&self,
|
||||
change4: &mut ChangeTracker,
|
||||
change6: &mut ChangeTracker,
|
||||
agent: &Instance,
|
||||
ips: &Ips,
|
||||
zone: &DnsZone
|
||||
) {
|
||||
let mut found4 = false;
|
||||
let mut found6 = false;
|
||||
|
||||
for cloudflare_entry in &agent.dns_entries {
|
||||
|
||||
// Update IPv4 Entry
|
||||
if cloudflare_entry.is_equal(&self.name) {
|
||||
found4 = true;
|
||||
if cloudflare_entry.r#type == CloudflareDnsType::A && self.type4 {
|
||||
let success = agent.update_entry(cloudflare_entry, &ips.ipv4);
|
||||
|
||||
if cloudflare_entry.is_ip_new(&ips.ipv4) {
|
||||
if success {
|
||||
change4.updated += 1;
|
||||
}
|
||||
|
@ -96,12 +104,12 @@ impl DnsEntry {
|
|||
}
|
||||
}
|
||||
// ignore otherwise
|
||||
else {
|
||||
|
||||
else {}
|
||||
}
|
||||
}
|
||||
|
||||
if !found4 && self.type4 {
|
||||
let success = agent.create_entry(&cloudflare_entry.zone_id, "A", &self.name, &ips.ipv4);
|
||||
let success = agent.create_entry(&zone.id, "A", &self.name, &ips.ipv4);
|
||||
if success {
|
||||
change4.created += 1;
|
||||
}
|
||||
|
@ -112,7 +120,7 @@ impl DnsEntry {
|
|||
|
||||
if !found6 && self.type6 {
|
||||
let ipv6 = ips.ipv6base.clone() + self.interface.as_ref().unwrap();
|
||||
let success = agent.create_entry(&cloudflare_entry.zone_id, "AAAA", &self.name, &ipv6);
|
||||
let success = agent.create_entry(&zone.id, "AAAA", &self.name, &ipv6);
|
||||
if success {
|
||||
change6.created += 1;
|
||||
}
|
||||
|
@ -122,7 +130,6 @@ impl DnsEntry {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct DnsZone {
|
||||
|
@ -139,7 +146,7 @@ impl DnsZone {
|
|||
agent.load_entries(&self.email, &self.id);
|
||||
|
||||
for entry in &self.dns_entries {
|
||||
entry.update(change4, change6, &agent, &ips);
|
||||
entry.update(change4, change6, &agent, &ips, &self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue