Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS: Trailing commas are no longer an issue #3248

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 107 additions & 107 deletions commands/types/dnscontrol.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion documentation/ci-cd-gitlab.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ D("cafferata.dev",
"v=spf1",
"-all"
].join(" ")),
END);
);
```
{% endcode %}

Expand Down
8 changes: 4 additions & 4 deletions documentation/cli-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ D("example.com", REG_NAMECOM, DnsProvider(DNS_NAMECOM), DnsProvider(DNS_BIND),
A("siteb", host01, TTL(1800)),
A("sitec", host02, TTL(1800)),
A("sited", host02, TTL(1800)),
END);
);
```
{% endcode %}

Expand All @@ -87,7 +87,7 @@ CLI_DEFAULTS({

D("example.com", REG_EXAMPLE, DnsProvider(DNS_EXAMPLE),
A("www", "10.10.10.10"),
END);
);

if (emergency) {
// Emergency mode: Configure A/B/C using CNAMEs to our alternate site.
Expand All @@ -96,7 +96,7 @@ if (emergency) {
CNAME("a", "a.othersite"),
CNAME("b", "b.othersite"),
CNAME("c", "c.othersite"),
END);
);

} else {
// Normal operation: Configure A/B/C using A records.
Expand All @@ -105,7 +105,7 @@ if (emergency) {
A("a", "10.10.10.10"),
A("b", "10.10.10.11"),
A("c", "10.10.10.12"),
END);
);

}
```
Expand Down
61 changes: 6 additions & 55 deletions documentation/code-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,18 @@ Solution: Use a "builder" to construct it for you.

# Trailing commas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem: Someone sees an old dnsconfig.js with END and can't find it in the docs.

Suggestion:

END

You may see D() statements written with END at the end. For example:

{% code title="dnsconfig.js" %}

D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
  A("foo", "1.2.3.4"),
END);

{% endcode %}

As of DNSControl v4.15.0 these END statements can be removed. END is a no-op which was added for reasons that no longer matter. They can be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Tom, for your feedback! I’ve incorporated it into this commit. You can preview the updated documentation here.


**Trailing commas** (sometimes called "final commas") can be useful when adding new Domain Modifiers to your DNSControl code. If you want to add a Domain Modifier, you can add a new line without modifying the previously last line if that line already uses a trailing comma. This makes version-control diffs cleaner and editing code might be less troublesome.

Because the DNSControl JavaScript DSL has no trailing commas, you can use the `END` constant within `D()`.

## Version-control diffs example

{% hint style="info" %}
**NOTE**: `END` is just an alias for `{}`, which is ignored by DNSControl.
{% endhint %}

Let's take an example with domain: `example.com`. We have recorded the [A-record](language-reference/domain-modifiers/A.md) 'foo' configured.

{% code title="dnsconfig.js" %}
```javascript
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
A("foo", "1.2.3.4")
);
```
{% endcode %}

Let's say we want to add an [A record](language-reference/domain-modifiers/A.md) 'bar' to this domain.
You might encounter `D()` statements in code examples that include `END` at the end, such as:

{% code title="dnsconfig.js" %}
```javascript
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
A("foo", "1.2.3.4"),
A("bar", "4.3.2.1")
);
```
{% endcode %}

This will generate the version-control diff below:

{% code title="dnsconfig.js" %}
```diff
- A("foo", "1.2.3.4"),
+ A("foo", "1.2.3.4"),
+ A("bar", "4.3.2.1")
);
```
{% endcode %}

Let's apply the same A-record 'foo' to the domain using the `END` constant.

{% code title="dnsconfig.js" %}
```javascript
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
A("foo", "1.2.3.4"),
A("test", "1.2.3.4"),
END);
```
{% endcode %}

This will generate the cleaner version-control diff below:

{% code title="dnsconfig.js" %}
```diff
A("foo", "1.2.3.4"),
+ A("bar", "4.3.2.1"),
END);
```
{% endcode %}
As of [DNSControl v4.15.0](https://github.com/StackExchange/dnscontrol/releases/tag/v4.15.0), the `END` statements are no longer necessary.
These were originally included for historical reasons that are now irrelevant. You can safely remove them from your configurations.

# Repeat records in many domains (macros)

Expand Down Expand Up @@ -133,7 +84,7 @@ function PARKED_R53(name) {
A("@", "10.2.3.4"),
CNAME("www", "@"),
SPF_NONE, //deters spammers from using the domain in From: lines.
END);
);
}

PARKED_R53("example1.tld");
Expand All @@ -156,7 +107,7 @@ _.each(
D(d, REG_NAMECOM, DnsProvider(DSP_MY_PROVIDER),
A("@", "10.2.3.4"),
CNAME("www", "@"),
END);
);
}
);
```
Expand Down
22 changes: 11 additions & 11 deletions documentation/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
TXT("the", "message"),
NS("department2", "ns1.dnsexample.com."), // use different nameservers
NS("department2", "ns2.dnsexample.com."), // for department2.example.com
END);
);
```
{% endcode %}

Expand All @@ -32,7 +32,7 @@ D("example.com", REG_MY_PROVIDER,

A("@", "1.2.3.4", TTL("10m")), // individual record
CNAME("mail", "mx01"), // TTL of 5m, as defined per DefaultTTL()
END);
);
```
{% endcode %}

Expand All @@ -46,7 +46,7 @@ var DSP_R53 = NewDnsProvider("route53_user1");
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_R53),
A("@", addrA), // 1.2.3.4
A("www", addrA + 1), // 1.2.3.5
END);
);
```
{% endcode %}

Expand All @@ -72,7 +72,7 @@ var activeDC = dcA;

D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_R53),
A("@", activeDC + 5), // fixed address based on activeDC
END);
);
```
{% endcode %}

Expand Down Expand Up @@ -100,7 +100,7 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_R53),
GOOGLE_APPS_MX_RECORDS,
GOOGLE_APPS_CNAME_RECORDS,
A("@", "1.2.3.4"),
END);
);
```
{% endcode %}

Expand All @@ -123,7 +123,7 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
"~all"
]
}),
END);
);
```
{% endcode %}

Expand All @@ -134,7 +134,7 @@ DEFAULTS(
NAMESERVER_TTL("24h"),
DefaultTTL("12h"),
CF_PROXY_DEFAULT_OFF,
END);
);
```
{% endcode %}

Expand All @@ -149,19 +149,19 @@ var DSP_GCLOUD = NewDnsProvider("gcloud_admin");

D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_R53), DnsProvider(DSP_GCLOUD),
A("@", "1.2.3.4"),
END);
);

// 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_MY_PROVIDER, DnsProvider(DSP_R53, 2), DnsProvider(DSP_GCLOUD ,2),
A("@", "1.2.3.4"),
END);
);

// or set a Provider as a non-authoritative backup (don"t register its nameservers)
D("example3.com", REG_MY_PROVIDER, DnsProvider(DSP_R53), DnsProvider(DSP_GCLOUD, 0),
A("@", "1.2.3.4"),
END);
);
```
{% endcode %}

Expand Down Expand Up @@ -204,7 +204,7 @@ var DSP_R53_MAIN = NewDnsProvider("r53_main");
D("example.com", REG_NONE, DnsProvider(DSP_R53_MAIN),
FASTMAIL_MX,
FASTMAIL_DKIM("example.com"),
END);
);
```
{% endcode %}

Expand Down
2 changes: 1 addition & 1 deletion documentation/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var DNS_BIND = NewDnsProvider("bind");

D("example.com", REG_NONE, DnsProvider(DNS_BIND),
A("@", "1.2.3.4"),
END);
);
```
{% endcode %}

Expand Down
2 changes: 1 addition & 1 deletion documentation/language-reference/domain-modifiers/A.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
A("foo", "2.3.4.5"),
A("test.foo", IP("1.2.3.4"), TTL(5000)),
A("*", "1.2.3.4", {foo: 42}),
END);
);
```
{% endcode %}
2 changes: 1 addition & 1 deletion documentation/language-reference/domain-modifiers/AAAA.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
AAAA("foo", addrV6),
AAAA("test.foo", addrV6, TTL(5000)),
AAAA("*", addrV6, {foo: 42}),
END);
);
```
{% endcode %}
2 changes: 1 addition & 1 deletion documentation/language-reference/domain-modifiers/ALIAS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Target should be a string representing the target. If it is a single label we wi
```javascript
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
ALIAS("@", "google.com."), // example.com -> google.com
END);
);
```
{% endcode %}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ correct syntax is `AUTODNSSEC_ON` not `AUTODNSSEC_ON()`
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
AUTODNSSEC_ON, // Enable AutoDNSSEC.
A("@", "10.1.1.1"),
END);
);

D("insecure.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
AUTODNSSEC_OFF, // Disable AutoDNSSEC.
A("@", "10.2.2.2"),
END);
);
```
{% endcode %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ This arrangement is useful if you want some record sets to be aliases and some n
D("example.com", REG_MY_PROVIDER, DnsProvider("AZURE_DNS"),
AZURE_ALIAS("foo", "A", "/subscriptions/726f8cd6-6459-4db4-8e6d-2cd2716904e2/resourceGroups/test/providers/Microsoft.Network/trafficManagerProfiles/testpp2"), // record for traffic manager
AZURE_ALIAS("foo", "CNAME", "/subscriptions/726f8cd6-6459-4db4-8e6d-2cd2716904e2/resourceGroups/test/providers/Microsoft.Network/dnszones/example.com/A/quux."), // record in the same zone
END);
);
```
{% endcode %}
2 changes: 1 addition & 1 deletion documentation/language-reference/domain-modifiers/CAA.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
// Report all violation to [email protected]. If CA does not support
// this record then refuse to issue any certificate
CAA("@", "iodef", "mailto:[email protected]", CAA_CRITICAL),
END);
);
```
{% endcode %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
],
issuewild: "none",
}),
END);
);
```
{% endcode %}

Expand All @@ -56,7 +56,7 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
CAA("@", "issue", "letsencrypt.org"),
CAA("@", "issue", "comodoca.com"),
CAA("@", "issuewild", ";"),
END);
);
```
{% endcode %}

Expand Down Expand Up @@ -88,7 +88,7 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
issuewild: "none",
issuewild_critical: true,
}),
END);
);
```
{% endcode %}

Expand All @@ -101,7 +101,7 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
CAA("@", "issue", "letsencrypt.org", CAA_CRITICAL),
CAA("@", "issue", "comodoca.com", CAA_CRITICAL),
CAA("@", "issuewild", ";", CAA_CRITICAL),
END);
);
```
{% endcode %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ This example redirects the bare (aka apex, or naked) domain to www:
```javascript
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
CF_REDIRECT("example.com/*", "https://www.example.com/$1"),
END);
);
```
{% endcode %}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
CF_SINGLE_REDIRECT("name", 301, "when", "then"),
CF_SINGLE_REDIRECT('redirect www.example.com', 301, 'http.host eq "www.example.com"', 'concat("https://otherplace.com", http.request.uri.path)'),
CF_SINGLE_REDIRECT('redirect yyy.example.com', 301, 'http.host eq "yyy.example.com"', 'concat("https://survey.stackoverflow.co", "")'),
END);
);
```
{% endcode %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ managed by DNSControl and those that aren't.
```javascript
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
CF_TEMP_REDIRECT("example.example.com/*", "https://otherplace.yourdomain.com/$1"),
END);
);
```
{% endcode %}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ This example assigns the patterns `api.example.com/*` and `example.com/api/*` to
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
CF_WORKER_ROUTE("api.example.com/*", "my-worker"),
CF_WORKER_ROUTE("example.com/api/*", "my-worker"),
END);
);
```
{% endcode %}
2 changes: 1 addition & 1 deletion documentation/language-reference/domain-modifiers/CNAME.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
CNAME("foo", "google.com."), // foo.example.com -> google.com
CNAME("abc", "@"), // abc.example.com -> example.com
CNAME("def", "test"), // def.example.com -> test.example.com
END);
);
```
{% endcode %}
2 changes: 1 addition & 1 deletion documentation/language-reference/domain-modifiers/DHCID.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Digest should be a string.
```javascript
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
DHCID("example.com", "ABCDEFG"),
END);
);
```
{% endcode %}
Loading
Loading