cloudflare / cloudflare-rs

Rust library for the Cloudflare v4 API
255 stars 79 forks source link

DNS: Support for additional record types #219

Open maxhoesel opened 1 year ago

maxhoesel commented 1 year ago

It seems like this crate currently only supports the most common DNS record types:

// in cloudflare/src/endpoints/dns.rs
pub enum DnsContent {
    A { content: Ipv4Addr },
    AAAA { content: Ipv6Addr },
    CNAME { content: String },
    NS { content: String },
    MX { content: String, priority: u16 },
    TXT { content: String },
}

However, the Cloudflare API lists several additional record types that are currently not implemented, including CAA, CERT, DNSKEY and more.

From what I can tell, adding any of these records to a zone causes the ListDnsRecords query to fail with an unknown variant error during deserialization, effectively making the ListDnsRecords query unavailable for such a zone (example below). I'm running into this issue on my own zones, since I have a CAA record set on them.

I have a fork that fixes this for CAA records, but I'd be interested in seeing support for these record types in this main crate. Adding simple enum variants for these records with the content field should be sufficient to allow the ListDnsRecords request to succeed (the API also returns a structured data field for some record types, but I don't think this is necessary for basic support).

If support for these record types is desired, I'd be more than happy to make the required changes and open a PR!


Steps to reproduce:

  1. Create a zone and create a CAA record through the Web Interface (such as 0 issue letsencrypt.org).
  2. Attempt to list all records in that zone using the cloudflare-examples utility like so:
cargo run -p cloudflare-examples -- --auth-token <redacted> dns <zone-id>
  1. The client will return the following error:
Error: error decoding response body: unknown variant `CAA`, expected one of `A`, `AAAA`, `CNAME`, `NS`, `MX`, `TXT`, `SRV` at line 1 column 8705
taladar commented 2 months ago

I ran into that with the SSHFP record type in my zones.