Fix subdomain matching
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b26d4d7bba
commit
2e3442faa9
3 changed files with 57 additions and 19 deletions
|
@ -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?;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,10 +56,16 @@ impl DnsProvider for GandiProvider {
|
|||
"gandi"
|
||||
}
|
||||
|
||||
async fn update_a(&self, domain: &str, subdomain: &str, targets: &[Ipv4Addr]) -> Result<()> {
|
||||
async fn update_a(
|
||||
&self,
|
||||
domain: &str,
|
||||
subdomain: Option<&str>,
|
||||
targets: &[Ipv4Addr],
|
||||
) -> Result<()> {
|
||||
let url = format!(
|
||||
"https://api.gandi.net/v5/livedns/domains/{}/records/{}/A",
|
||||
domain, subdomain
|
||||
domain,
|
||||
subdomain.unwrap_or("@")
|
||||
);
|
||||
|
||||
let rrset = GandiRrset {
|
||||
|
@ -70,10 +76,16 @@ impl DnsProvider for GandiProvider {
|
|||
self.put_rrset(&url, &rrset).await
|
||||
}
|
||||
|
||||
async fn update_aaaa(&self, domain: &str, subdomain: &str, targets: &[Ipv6Addr]) -> Result<()> {
|
||||
async fn update_aaaa(
|
||||
&self,
|
||||
domain: &str,
|
||||
subdomain: Option<&str>,
|
||||
targets: &[Ipv6Addr],
|
||||
) -> Result<()> {
|
||||
let url = format!(
|
||||
"https://api.gandi.net/v5/livedns/domains/{}/records/{}/AAAA",
|
||||
domain, subdomain
|
||||
domain,
|
||||
subdomain.unwrap_or("@")
|
||||
);
|
||||
|
||||
let rrset = GandiRrset {
|
||||
|
@ -84,10 +96,16 @@ impl DnsProvider for GandiProvider {
|
|||
self.put_rrset(&url, &rrset).await
|
||||
}
|
||||
|
||||
async fn update_cname(&self, domain: &str, subdomain: &str, target: &str) -> Result<()> {
|
||||
async fn update_cname(
|
||||
&self,
|
||||
domain: &str,
|
||||
subdomain: Option<&str>,
|
||||
target: &str,
|
||||
) -> Result<()> {
|
||||
let url = format!(
|
||||
"https://api.gandi.net/v5/livedns/domains/{}/records/{}/CNAME",
|
||||
domain, subdomain
|
||||
domain,
|
||||
subdomain.unwrap_or("@")
|
||||
);
|
||||
|
||||
let rrset = GandiRrset {
|
||||
|
|
|
@ -8,9 +8,20 @@ use async_trait::async_trait;
|
|||
#[async_trait]
|
||||
pub trait DnsProvider: Send + Sync {
|
||||
fn provider(&self) -> &'static str;
|
||||
async fn update_a(&self, domain: &str, subdomain: &str, targets: &[Ipv4Addr]) -> Result<()>;
|
||||
async fn update_aaaa(&self, domain: &str, subdomain: &str, targets: &[Ipv6Addr]) -> Result<()>;
|
||||
async fn update_cname(&self, domain: &str, subdomain: &str, target: &str) -> Result<()>;
|
||||
async fn update_a(
|
||||
&self,
|
||||
domain: &str,
|
||||
subdomain: Option<&str>,
|
||||
targets: &[Ipv4Addr],
|
||||
) -> Result<()>;
|
||||
async fn update_aaaa(
|
||||
&self,
|
||||
domain: &str,
|
||||
subdomain: Option<&str>,
|
||||
targets: &[Ipv6Addr],
|
||||
) -> Result<()>;
|
||||
async fn update_cname(&self, domain: &str, subdomain: Option<&str>, target: &str)
|
||||
-> Result<()>;
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for dyn DnsProvider {
|
||||
|
|
Loading…
Reference in a new issue