aboutsummaryrefslogtreecommitdiff
path: root/src/dns_updater.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dns_updater.rs')
-rw-r--r--src/dns_updater.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/dns_updater.rs b/src/dns_updater.rs
index e65689d..e525f8a 100644
--- a/src/dns_updater.rs
+++ b/src/dns_updater.rs
@@ -51,7 +51,10 @@ pub async fn dns_updater_task(
}
// Skip entries for unallowed domains
- if !allowed_domains.iter().any(|d| key.dns_path.ends_with(d)) {
+ if !allowed_domains
+ .iter()
+ .any(|d| key.dns_path == *d || key.dns_path.ends_with(&format!(".{}", d)))
+ {
error!(
domain = key.dns_path,
"domain/subdomain/hostname not in allowed list",
@@ -59,7 +62,9 @@ pub async fn dns_updater_task(
continue;
}
- let provider = providers.iter().find(|p| key.dns_path.ends_with(&p.domain));
+ let provider = providers.iter().find(|p| {
+ key.dns_path == p.domain || key.dns_path.ends_with(&format!(".{}", p.domain))
+ });
if let Some(provider) = provider {
if let Err(e) = update_dns_entry(key, value, provider).await {
@@ -87,11 +92,15 @@ async fn update_dns_entry(
value: &DnsEntryValue,
provider: &DomainProvider,
) -> Result<()> {
- let subdomain = key
- .dns_path
- .strip_suffix(&provider.domain)
- .unwrap()
- .trim_end_matches('.');
+ let subdomain = if key.dns_path == provider.domain {
+ None
+ } else {
+ Some(
+ key.dns_path
+ .strip_suffix(&format!(".{}", provider.domain))
+ .unwrap(),
+ )
+ };
info!(
record = key.to_string(),
target = value.to_string(),
@@ -116,7 +125,7 @@ async fn update_dns_entry(
}
provider
.provider
- .update_a(&provider.domain, &subdomain, &targets)
+ .update_a(&provider.domain, subdomain, &targets)
.await?;
}
DnsRecordType::AAAA => {
@@ -129,7 +138,7 @@ async fn update_dns_entry(
}
provider
.provider
- .update_aaaa(&provider.domain, &subdomain, &targets)
+ .update_aaaa(&provider.domain, subdomain, &targets)
.await?;
}
DnsRecordType::CNAME => {
@@ -145,7 +154,7 @@ async fn update_dns_entry(
}
provider
.provider
- .update_cname(&provider.domain, &subdomain, &targets[0])
+ .update_cname(&provider.domain, subdomain, &targets[0])
.await?;
}
}