From 6fc3534aa3b74bdb4b7fb7092068abc26e4753e1 Mon Sep 17 00:00:00 2001 From: Vincent Hagen Date: Sun, 25 Jul 2021 18:03:58 +0200 Subject: [PATCH] Add INCLUDE statement to include records from other domains (#1219) --- docs/_functions/domain/INCLUDE.md | 23 ++++++++++++ docs/_includes/matrix.html | 58 +++++++++++++++++++++++++++-- pkg/js/helpers.js | 10 +++++ pkg/js/parse_tests/039-include.js | 12 ++++++ pkg/js/parse_tests/039-include.json | 49 ++++++++++++++++++++++++ 5 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 docs/_functions/domain/INCLUDE.md create mode 100644 pkg/js/parse_tests/039-include.js create mode 100644 pkg/js/parse_tests/039-include.json diff --git a/docs/_functions/domain/INCLUDE.md b/docs/_functions/domain/INCLUDE.md new file mode 100644 index 000000000..ec88a3057 --- /dev/null +++ b/docs/_functions/domain/INCLUDE.md @@ -0,0 +1,23 @@ +--- +name: INCLUDE +parameters: + - domain +--- + +Includes all records from a given domain + + +{% include startExample.html %} +{% highlight js %} + +D("example.com!external", REGISTRAR, DnsProvider(R53), + A("test", "8.8.8.8") +); + +D("example.com!internal", REGISTRAR, DnsProvider(R53), + INCLUDE("example.com!external"), + A("home", "127.0.0.1") +); + +{%endhighlight%} +{% include endExample.html %} diff --git a/docs/_includes/matrix.html b/docs/_includes/matrix.html index 6f6e885d1..3f76558eb 100644 --- a/docs/_includes/matrix.html +++ b/docs/_includes/matrix.html @@ -41,6 +41,7 @@
POWERDNS
ROUTE53
SOFTLAYER
+
TRANSIP
VULTR
@@ -155,6 +156,9 @@ + + + DNS Provider @@ -266,6 +270,9 @@ + + + Registrar @@ -377,6 +384,9 @@ + + + ALIAS @@ -464,6 +474,9 @@ + + + AUTODNSSEC @@ -520,6 +533,9 @@ + + + @@ -616,6 +632,9 @@ + + + PTR @@ -710,6 +729,7 @@ + @@ -757,7 +777,9 @@ - + + + @@ -773,6 +795,9 @@ + + + @@ -817,6 +842,7 @@ + SRV @@ -918,6 +944,9 @@ + + + SSHFP @@ -995,6 +1024,9 @@ + + + TLSA @@ -1077,6 +1109,9 @@ + + + @@ -1119,6 +1154,7 @@ + R53_ALIAS @@ -1164,6 +1200,7 @@ + AZURE_ALIAS @@ -1209,6 +1246,7 @@ + DS @@ -1271,6 +1309,9 @@ + + + @@ -1313,6 +1354,7 @@ + dual host @@ -1408,6 +1450,7 @@ + create-domains @@ -1516,6 +1559,9 @@ + + + @@ -1630,6 +1676,9 @@ + + + get-zones @@ -1699,8 +1748,8 @@ - - + + @@ -1731,6 +1780,9 @@ + + + diff --git a/pkg/js/helpers.js b/pkg/js/helpers.js index 3689c6693..b11859383 100644 --- a/pkg/js/helpers.js +++ b/pkg/js/helpers.js @@ -103,6 +103,16 @@ function D(name, registrar) { conf.domain_names.push(name); } +function INCLUDE(name) { + var domain = _getDomainObject(name); + if (domain == null) { + throw name + ' was not declared yet and therefore cannot be updated. Use D() before.'; + } + return function(d) { + d.records.push.apply(d.records, domain.obj.records); + } +} + // D_EXTEND(name): Update a DNS Domain already added with D(), or subdomain thereof function D_EXTEND(name) { var domain = _getDomainObject(name); diff --git a/pkg/js/parse_tests/039-include.js b/pkg/js/parse_tests/039-include.js new file mode 100644 index 000000000..3d75ffbc5 --- /dev/null +++ b/pkg/js/parse_tests/039-include.js @@ -0,0 +1,12 @@ + +var REG = NewRegistrar("Third-Party","NONE"); +var CF = NewDnsProvider("Cloudflare", "CLOUDFLAREAPI"); + +D("foo.com!external",REG,DnsProvider(CF), + A("@","1.2.3.4") +); + +D("foo.com!internal",REG,DnsProvider(CF), + INCLUDE("foo.com!external"), + A("local","127.0.0.1") +); diff --git a/pkg/js/parse_tests/039-include.json b/pkg/js/parse_tests/039-include.json new file mode 100644 index 000000000..e7014a613 --- /dev/null +++ b/pkg/js/parse_tests/039-include.json @@ -0,0 +1,49 @@ +{ + "registrars": [ + { + "name": "Third-Party", + "type": "NONE" + } + ], + "dns_providers": [ + { + "name": "Cloudflare", + "type": "CLOUDFLAREAPI" + } + ], + "domains": [ + { + "name": "foo.com!external", + "registrar": "Third-Party", + "dnsProviders": { + "Cloudflare": -1 + }, + "records": [ + { + "type": "A", + "name": "@", + "target": "1.2.3.4" + } + ] + }, + { + "name": "foo.com!internal", + "registrar": "Third-Party", + "dnsProviders": { + "Cloudflare": -1 + }, + "records": [ + { + "type": "A", + "name": "@", + "target": "1.2.3.4" + }, + { + "type": "A", + "name": "local", + "target": "127.0.0.1" + } + ] + } + ] +}