Variables with arguments?

18 views
Skip to first unread message

Jay

unread,
Sep 28, 2022, 4:08:21 AM9/28/22
to DNSControl-discuss

Hi, I have a bunch of domains that use Fastmail as an MX. I already have a variable that I include for them:

var FASTMAIL = [
  MX('@', 10, 'in1-smtp.messagingengine.com.'),
  MX('@', 20, 'in2-smtp.messagingengine.com.'),
]

Fastmail also supplied CNAMES to implement DKIM, and they all match a pattern that includes the domain name:

CNAME('fm1._domainkey', 'fm1.example.com.dkim.fmhosted.com.'),
CNAME('fm2._domainkey', 'fm2.example.com.dkim.fmhosted.com.'),
CNAME('fm3._domainkey', 'fm3.example.com.dkim.fmhosted.com.'),

Is it possible to implement a variable that can substitute/infer the domain name? Or is it possible to make a variable that’s a function, that accepts the domain name as an argument?

There’s a strong recommendation in the Code Tricks docs (https://stackexchange.github.io/dnscontrol/code-tricks) about not getting too fancy. Is this getting too fancy?

Thank you.

Jay

unread,
Sep 28, 2022, 4:24:10 AM9/28/22
to DNSControl-discuss
I was able to accomplish this with the following:

var FASTMAIL_DKIM = function(the_domain){
    return [
        CNAME('fm1._domainkey', 'fm1.' + the_domain + '.dkim.fmhosted.com.'),
        CNAME('fm2._domainkey', 'fm2.' + the_domain + '.dkim.fmhosted.com.'),
        CNAME('fm3._domainkey', 'fm3.' + the_domain + '.dkim.fmhosted.com.')
    ]
}

D("example.com", REG_NONE, DnsProvider(DSP_R53_MAIN),
    FASTMAIL,
    FASTMAIL_ONLY_SPF,
    FASTMAIL_DKIM('example.com')
)

Tom Limoncelli

unread,
Sep 28, 2022, 4:26:26 PM9/28/22
to Jay, DNSControl-discuss
Jay,

This is an excellent example of the power of dynamic macros (i.e. functions).

I'd like to add this example to the documentation. Please take a look at:

https://github.com/StackExchange/dnscontrol/pull/1759

Thanks!
Tom

Jason Discount

unread,
Sep 28, 2022, 6:17:08 PM9/28/22
to Tom Limoncelli, DNSControl-discuss
Wow, that’s great. Please do. Thank you.
Reply all
Reply to author
Forward
0 new messages