StackExchange / dnscontrol

Infrastructure as code for DNS!
https://dnscontrol.org/
MIT License
3.17k stars 399 forks source link

add ability to "fmt' to output sorted records #3054

Closed ank-everstake closed 3 months ago

ank-everstake commented 4 months ago

When you backup zone records using get-zones dnscontrol creates files with sorted records

$> dnscontrol get-zones --out=out.js --format=js  cloudflare - example.com
$> cat out.js
D("example.com", REG_CHANGEME,
    DnsProvider(DSP_CLOUDFLARE),
    DefaultTTL(1),
    A("proxy-test", "1.2.3.5", CF_PROXY_ON),
    A("z11", "8.8.8.8"),
    A("z1", "8.8.8.8"),
    A("z21", "8.8.8.8"),
    A("z", "8.8.8.8"),
    CNAME("test", "test.pages.dev.", CF_PROXY_ON),
    TXT("_dmarc", "v=DMARC1; p=reject; sp=reject; adkim=s; aspf=s;"),
    TXT("*._domainkey", "v=DKIM1; p="),
    TXT("*", "v=spf1 -all"),
    TXT("@", "v=spf1 -all"),
END);

Our use-case (2 git branches):

main - current files that get pushed to prod
backup - files downloaded using get-zone. Protected branch

This way, we can create proper diff between files in main and backup branches visually even without running dnscontrol. It will also allow to see duplicate records clearly before they get pushed to prod.

I propose to add ability to fmt that allows to get similar output with records that are sorted.

tlimoncelli commented 4 months ago

Hi friend!

That's an interesting idea!

Sadly the fmt command is pretty dumb. It basically counts parens, commas, and semicolons and intelligently inserts whitespace along the way. Have it re-order lines is a much different problem.

I had never imagined gete-zones as a backup mechanism. It was created as a way to make "a decent first draft" of dnsconfig.js when migrating zones.

tlimoncelli commented 3 months ago

Closing. No possible given current architecture.