<commit_before>---
layout: default
---

# Examples

* TOC
{:toc}

## Typical DNS Records

{% highlight javascript %}

D('example.com', REG, DnsProvider('GCLOUD'),
    A('@', '172.16.17.32'),  // The naked or 'apex' domain.
    A('server1', '172.16.31.10'),
    AAAA('wide', '2001:0db8:85a3:0000:0000:8a2e:0370:7334'),
    CNAME('www', 'server1'),
    CNAME('another', 'service.mycloud.com.'),
    MX('mail', 10, 'mailserver'),
    MX('mail', 20, 'mailqueue'),
    TXT('the', 'message'),
    NS('delegated', 'ns1.dnsexample.com.'),
    NS('delegated', 'ns2.dnsexample.com.')
)

{% endhighlight %}

## Set a specific TTL for a record

{% highlight javascript %}
    A('one', '172.16.17.32', TTL(400)),
{% endhighlight %}

## Variables for common IP Addresses

{% highlight javascript %}

var addrA = IP('1.2.3.4')

D('example.com', REG, DnsProvider('R53'),
    A('@', addrA), //1.2.3.4
    A('www', addrA + 1), //172.16.31.10
)
{% endhighlight %}

## Variables to swap active Data Center

{% highlight javascript %}

var dcA = IP('5.5.5.5');
var dcB = IP('6.6.6.6');

// switch to dcB to failover
var activeDC = dcA;

D('example.com', REG, DnsProvider('R53'),
    A('@', activeDC + 5), // fixed address based on activeDC
)
{% endhighlight %}

## Macro to group repeated records

{% highlight javascript %}

var GOOGLE_APPS_DOMAIN_MX = [
    MX('@', 1, 'aspmx.l.google.com.'),
    MX('@', 5, 'alt1.aspmx.l.google.com.'),
    MX('@', 5, 'alt2.aspmx.l.google.com.'),
    MX('@', 10, 'alt3.aspmx.l.google.com.'),
    MX('@', 10, 'alt4.aspmx.l.google.com.'),
    CNAME('calendar', 'ghs.googlehosted.com.'),
    CNAME('drive', 'ghs.googlehosted.com.'),
    CNAME('mail', 'ghs.googlehosted.com.'),
    CNAME('groups', 'ghs.googlehosted.com.'),
    CNAME('sites', 'ghs.googlehosted.com.'),
]

D('example.com', REG, DnsProvider('R53'),
   GOOGLE_APPS_DOMAIN_MX,
   A('@', '172.16.17.32')
)
{% endhighlight %}

## Dual DNS Providers

{% highlight javascript %}

D('example.com', REG, DnsProvider('R53'), DnsProvider('GCLOUD'),
   A('@', '172.16.17.32')
)

// above zone uses 8 NS records total (4 from each provider dynamically gathered)
// below zone will only take 2 from each for a total of 4. May be better for performance reasons.

D('example2.com', REG, DnsProvider('R53',2), DnsProvider('GCLOUD',2),
   A('@', '172.16.17.32')
)

// or set a Provider as a non-authoritative backup (don't register its nameservers)
D('example3.com', REG, DnsProvider('R53'), DnsProvider('GCLOUD',0),
   A('@', '172.16.17.32')
)

{% endhighlight %}
<commit_msg>docs/examples.md: Add "commented SPF" example.<commit_after>---
layout: default
---

# Examples

* TOC
{:toc}

## Typical DNS Records

{% highlight javascript %}

D('example.com', REG, DnsProvider('GCLOUD'),
    A('@', '172.16.17.32'),  // The naked or 'apex' domain.
    A('server1', '172.16.31.10'),
    AAAA('wide', '2001:0db8:85a3:0000:0000:8a2e:0370:7334'),
    CNAME('www', 'server1'),
    CNAME('another', 'service.mycloud.com.'),
    MX('mail', 10, 'mailserver'),
    MX('mail', 20, 'mailqueue'),
    TXT('the', 'message'),
    NS('delegated', 'ns1.dnsexample.com.'),
    NS('delegated', 'ns2.dnsexample.com.')
)

{% endhighlight %}

## Set a specific TTL for a record

{% highlight javascript %}
    A('one', '1.2.3.4', TTL(400)),
{% endhighlight %}

## Variables for common IP Addresses

{% highlight javascript %}

var addrA = IP('1.2.3.4')

D('example.com', REG, DnsProvider('R53'),
    A('@', addrA), //1.2.3.4
    A('www', addrA + 1), //1.2.3.5
)
{% endhighlight %}

## Variables to swap active Data Center

{% highlight javascript %}

var dcA = IP('5.5.5.5');
var dcB = IP('6.6.6.6');

// switch to dcB to failover
var activeDC = dcA;

D('example.com', REG, DnsProvider('R53'),
    A('@', activeDC + 5), // fixed address based on activeDC
)
{% endhighlight %}

## Macro to group repeated records

{% highlight javascript %}

var GOOGLE_APPS_RECORDS = [
    MX('@', 1, 'aspmx.l.google.com.'),
    MX('@', 5, 'alt1.aspmx.l.google.com.'),
    MX('@', 5, 'alt2.aspmx.l.google.com.'),
    MX('@', 10, 'alt3.aspmx.l.google.com.'),
    MX('@', 10, 'alt4.aspmx.l.google.com.'),
    CNAME('calendar', 'ghs.googlehosted.com.'),
    CNAME('drive', 'ghs.googlehosted.com.'),
    CNAME('mail', 'ghs.googlehosted.com.'),
    CNAME('groups', 'ghs.googlehosted.com.'),
    CNAME('sites', 'ghs.googlehosted.com.'),
]

D('example.com', REG, DnsProvider('R53'),
   GOOGLE_APPS_RECORDS,
   A('@', '1.2.3.4')
)
{% endhighlight %}

## Add comments along complex SPF records

You can't normally put comments in the middle of a string,
but with a little bit of creativity you can document
each element of an SPF record this way.

{% highlight javascript %}

var SPF_RECORDS = TXT('@', [
    'v=spf1',
    'ip4:192.168.3.11/24',           // NY mail server
    'ip4:172.16.58.3/24',           // CO mail server
    'include:_spf.google.com',  // Google Apps
    'include:mailgun.org',      // Mailgun (requested by Ticket#12345)
    'include:servers.mcsv.net', // MailChimp (requested by Ticket#54321)
    'include:sendgrid.net',     // SendGrid (requested by Ticket#23456)
    'include:spf.mtasv.net',    // Desk.com (needed by IT team)
    '~all'
].join(' '));

{% endhighlight %}

## Dual DNS Providers

{% highlight javascript %}

D('example.com', REG, DnsProvider('R53'), DnsProvider('GCLOUD'),
   A('@', '1.2.3.4')
)

// above zone uses 8 NS records total (4 from each provider dynamically gathered)
// below zone will only take 2 from each for a total of 4. May be better for performance reasons.

D('example2.com', REG, DnsProvider('R53',2), DnsProvider('GCLOUD',2),
   A('@', '172.16.17.32')
)

// or set a Provider as a non-authoritative backup (don't register its nameservers)
D('example3.com', REG, DnsProvider('R53'), DnsProvider('GCLOUD',0),
   A('@', '1.2.3.4')
)

{% endhighlight %}

{'fraction_non_alphanumeric': 0.20961373390557939, 'fraction_numerical': 0.057339055793991414, 'mean_word_length': 3.5946372239747633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 26, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5783906', 'n_tokens_mistral': 2518, 'n_tokens_neox': 2235, 'n_words': 518}