1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

DOCS: consistency in code examples in language reference (#2394)

This commit is contained in:
Jeffrey Cafferata
2023-05-24 22:09:22 +02:00
committed by GitHub
parent 0b7dabacc8
commit e97cf01744
59 changed files with 691 additions and 548 deletions

View File

@ -23,22 +23,22 @@ Modifier arguments are processed according to type as follows:
{% code title="dnsconfig.js" %}
```javascript
var REGISTRAR = NewRegistrar("name.com");
var REG_NAMECOM = NewRegistrar("name.com");
var r53 = NewDnsProvider("R53");
// simple domain
D("example.com", REGISTRAR, DnsProvider(r53),
D("example.com", REG_NAMECOM, DnsProvider(r53),
A("@","1.2.3.4"),
CNAME("test", "foo.example2.com.")
);
// "macro" for records that can be mixed into any zone
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.'),
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."),
]
D("example.com", REGISTRAR, DnsProvider(r53),
@ -62,15 +62,15 @@ To differentiate the different domains, specify the domains as
{% code title="dnsconfig.js" %}
```javascript
var REG = NewRegistrar("Third-Party");
var REG_THIRDPARTY = NewRegistrar("ThirdParty");
var DNS_INSIDE = NewDnsProvider("Cloudflare");
var DNS_OUTSIDE = NewDnsProvider("bind");
D("example.com!inside", REG, DnsProvider(DNS_INSIDE),
D("example.com!inside", REG_THIRDPARTY, DnsProvider(DNS_INSIDE),
A("www", "10.10.10.10")
);
D("example.com!outside", REG, DnsProvider(DNS_OUTSIDE),
D("example.com!outside", REG_THIRDPARTY, DnsProvider(DNS_OUTSIDE),
A("www", "20.20.20.20")
);
@ -94,7 +94,7 @@ define domains `example.com!george` and `example.com!john` then:
* `--domains=example.com` will not match either domain.
* `--domains='example.com!george'` will match only match the first.
* `--domains='example.com!george',example.com!john` will match both.
* `--domains='example.com!george",example.com!john` will match both.
{% hint style="info" %}
**NOTE**: The quotes are required if your shell treats `!` as a special

View File

@ -19,7 +19,7 @@ The domain `example.com` will have the defaults set.
var COMMON = NewDnsProvider("foo");
DEFAULTS(
DnsProvider(COMMON, 0),
DefaultTTL('1d')
DefaultTTL("1d")
);
D("example.com",

View File

@ -25,7 +25,7 @@ names (labels), and targets (as appropriate). See the examples below.
Matching the domain name to previously-defined domains is done using a
`longest match` algorithm. If `domain.tld` and `sub.domain.tld` are
defined as separate domains via separate [`D()`](D.md) statements, then
`D_EXTEND('sub.sub.domain.tld', ...)` would match `sub.domain.tld`,
`D_EXTEND("sub.sub.domain.tld", ...)` would match `sub.domain.tld`,
not `domain.tld`.
Some operators only act on an apex domain (e.g.
@ -34,7 +34,7 @@ in a `D_EXTEND` subdomain may not be what you expect.
{% code title="dnsconfig.js" %}
```javascript
D("domain.tld", REG, DnsProvider(DNS),
D("domain.tld", REG_MY_PROVIDER, DnsProvider(DNS),
A("@", "127.0.0.1"), // domain.tld
A("www", "127.0.0.2"), // www.domain.tld
CNAME("a", "b") // a.domain.tld -> b.domain.tld

View File

@ -22,14 +22,14 @@ Otherwise the syntax of `FETCH` is the same as `fetch`.
{% code title="dnsconfig.js" %}
```javascript
var REG_NONE = NewRegistrar('none');
var DNS_BIND = NewDnsProvider('bind');
var REG_NONE = NewRegistrar("none");
var DNS_BIND = NewDnsProvider("bind");
D('example.com', REG_NONE, DnsProvider(DNS_BIND), [
A('@', '1.2.3.4'),
D("example.com", REG_NONE, DnsProvider(DNS_BIND), [
A("@", "1.2.3.4"),
]);
FETCH('https://example.com', {
FETCH("https://example.com", {
// All three options below are optional
headers: {"X-Authentication": "barfoo"},
method: "POST",
@ -38,8 +38,8 @@ FETCH('https://example.com', {
return r.text();
}).then(function(t) {
// Example of generating record based on response
D_EXTEND('example.com', [
TXT('@', t.slice(0, 100)),
D_EXTEND("example.com", [
TXT("@", t.slice(0, 100)),
]);
});
```

View File

@ -11,7 +11,7 @@ Converts an IPv4 address from string to an integer. This allows performing mathe
{% code title="dnsconfig.js" %}
```javascript
var addrA = IP('1.2.3.4')
var addrA = IP("1.2.3.4")
var addrB = addrA + 1
// addrB = 1.2.3.5
```

View File

@ -12,7 +12,7 @@ example `REV('1.2.3.0/24')` returns `3.2.1.in-addr.arpa.` and
`REV('2001:db8:302::/48)` returns `2.0.3.0.8.b.d.0.1.0.0.2.ip6.arpa.`.
This is used in [`D()`](D.md) functions to create reverse DNS lookup zones.
This is a convenience function. You could specify `D('3.2.1.in-addr.arpa',
This is a convenience function. You could specify `D("3.2.1.in-addr.arpa",
...` if you like to do things manually but why would you risk making
typos?
@ -29,24 +29,24 @@ If the address does not include a "/" then `REV` assumes /32 for IPv4 addresses
and /128 for IPv6 addresses.
Note that the lower bits (the ones outside the netmask) must be zeros. They are not
zeroed out automatically. Thus, `REV('1.2.3.4/24')` is an error. This is done
zeroed out automatically. Thus, `REV("1.2.3.4/24")` is an error. This is done
to catch typos.
{% code title="dnsconfig.js" %}
```javascript
D(REV('1.2.3.0/24'), REGISTRAR, DnsProvider(BIND),
PTR("1", 'foo.example.com.'),
PTR("2", 'bar.example.com.'),
PTR("3", 'baz.example.com.'),
D(REV("1.2.3.0/24"), REGISTRAR, DnsProvider(BIND),
PTR("1", "foo.example.com."),
PTR("2", "bar.example.com."),
PTR("3", "baz.example.com."),
// These take advantage of DNSControl's ability to generate the right name:
PTR("1.2.3.10", 'ten.example.com.'),
PTR("1.2.3.10", "ten.example.com."),
);
D(REV('2001:db8:302::/48'), REGISTRAR, DnsProvider(BIND),
PTR("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0", 'foo.example.com.'), // 2001:db8:302::1
D(REV("2001:db8:302::/48"), REGISTRAR, DnsProvider(BIND),
PTR("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0", "foo.example.com."), // 2001:db8:302::1
// These take advantage of DNSControl's ability to generate the right name:
PTR("2001:db8:302::2", 'two.example.com.'), // 2.0.0...
PTR("2001:db8:302::3", 'three.example.com.'), // 3.0.0...
PTR("2001:db8:302::2", "two.example.com."), // 2.0.0...
PTR("2001:db8:302::3", "three.example.com."), // 3.0.0...
);
```
{% endcode %}

View File

@ -15,7 +15,7 @@ Example for adding records to all configured domains:
var domains = getConfiguredDomains();
for(i = 0; i < domains.length; i++) {
D_EXTEND(domains[i],
TXT('_important', 'BLA') // I know, not really creative.
TXT("_important", "BLA") // I know, not really creative.
)
}
```
@ -47,7 +47,7 @@ This example might be more useful, specially for configuring the DMARC report re
var domains = getConfiguredDomains();
for(i = 0; i < domains.length; i++) {
D_EXTEND("domain1.tld",
TXT(domains[i] + '._report._dmarc', 'v=DMARC1')
TXT(domains[i] + "._report._dmarc", "v=DMARC1")
);
}
```

View File

@ -21,9 +21,9 @@ of the call.
{% code title="dnsconfig.js" %}
```javascript
require('kubernetes/clusters.js');
require("kubernetes/clusters.js");
D("mydomain.net", REG, PROVIDER,
D("mydomain.net", REG_MY_PROVIDER, PROVIDER,
IncludeKubernetes()
);
```
@ -31,8 +31,8 @@ D("mydomain.net", REG, PROVIDER,
{% code title="kubernetes/clusters.js" %}
```javascript
require('./clusters/prod.js');
require('./clusters/dev.js');
require("./clusters/prod.js");
require("./clusters/dev.js");
function IncludeKubernetes() {
return [includeK8Sprod(), includeK8Sdev()];
@ -64,10 +64,10 @@ You can also use it to require JSON files and initialize variables with it:
{% code title="dnsconfig.js" %}
```javascript
var domains = require('./domain-ip-map.json')
var domains = require("./domain-ip-map.json")
for (var domain in domains) {
D(domain, REG, PROVIDER,
D(domain, REG_MY_PROVIDER, PROVIDER,
A("@", domains[domain])
);
}