mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
CLOUDFLAREAPI: Adds CF_WORKER_ROUTE (#1243)
* CLOUDFLAREAPI: Adds CF_WORKER_ROUTE. - CLOUDFLAREAPI: Initial support for CF_WORKER_ROUTE. - Put CF_WORKER_ROUTE behind a per-domain feature-flag. - Adds Integration Test. - Create Cloudflare workers for tests. - Updates documentation. * Workaround for updateWorkerRoute causing stack overflow. * Sets AccountID. * Updates to latest master (Thanks @tresni!). * Removes $CLOUDFLAREAPI_ACCOUNTNAME. * Add alltrue() filter and -cfworkers flag * Final workers changes * alltrue() should be implemented like other filters. * Update documentation. Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
@@ -722,7 +722,8 @@ function recordBuilder(type, opts) {
|
||||
// Handle D_EXTEND() with subdomains.
|
||||
if (d.subdomain &&
|
||||
record.type != 'CF_REDIRECT' &&
|
||||
record.type != 'CF_TEMP_REDIRECT') {
|
||||
record.type != 'CF_TEMP_REDIRECT' &&
|
||||
record.type != 'CF_WORKER_ROUTE') {
|
||||
fqdn = [d.subdomain, d.name].join(".")
|
||||
|
||||
record.subdomain = d.subdomain;
|
||||
@@ -856,6 +857,18 @@ var CF_TEMP_REDIRECT = recordBuilder('CF_TEMP_REDIRECT', {
|
||||
},
|
||||
});
|
||||
|
||||
var CF_WORKER_ROUTE = recordBuilder('CF_WORKER_ROUTE', {
|
||||
args: [
|
||||
['pattern', _validateCloudflareRedirect],
|
||||
['script', _validateCloudflareRedirect],
|
||||
],
|
||||
transform: function(record, args, modifiers) {
|
||||
record.name = '@';
|
||||
record.target = args.pattern + ',' + args.script;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
var URL = recordBuilder('URL');
|
||||
var URL301 = recordBuilder('URL301');
|
||||
var FRAME = recordBuilder('FRAME');
|
||||
|
@@ -132,6 +132,7 @@ func TestErrors(t *testing.T) {
|
||||
{"MX reversed", `D("foo.com","reg",MX("@","test.", 5))`},
|
||||
{"CF_REDIRECT With comma", `D("foo.com","reg",CF_REDIRECT("foo.com,","baaa"))`},
|
||||
{"CF_TEMP_REDIRECT With comma", `D("foo.com","reg",CF_TEMP_REDIRECT("foo.com","baa,a"))`},
|
||||
{"CF_WORKER_ROUTE With comma", `D("foo.com","reg",CF_WORKER_ROUTE("foo.com","baa,a"))`},
|
||||
{"Bad cidr", `D(reverse("foo.com"), "reg")`},
|
||||
{"Dup domains", `D("example.org", "reg"); D("example.org", "reg")`},
|
||||
{"Bad NAMESERVER", `D("example.com","reg", NAMESERVER("@","ns1.foo.com."))`},
|
||||
|
@@ -5,6 +5,8 @@ D("foo.com", REG, DnsProvider(CF));
|
||||
D_EXTEND("sub.foo.com",
|
||||
A("test1.foo.com","10.2.3.1"),
|
||||
A("test2.foo.com","10.2.3.2"),
|
||||
A("test3.foo.com","10.2.3.3"),
|
||||
CF_REDIRECT("test1.foo.com","https://goo.com/$1"),
|
||||
CF_TEMP_REDIRECT("test2.foo.com","https://goo.com/$1")
|
||||
CF_TEMP_REDIRECT("test2.foo.com","https://goo.com/$1"),
|
||||
CF_WORKER_ROUTE("test3.foo.com","test-worker")
|
||||
);
|
||||
|
@@ -24,6 +24,12 @@
|
||||
"target": "10.2.3.2",
|
||||
"type": "A"
|
||||
},
|
||||
{
|
||||
"name": "test3.foo.com.sub",
|
||||
"subdomain": "sub",
|
||||
"target": "10.2.3.3",
|
||||
"type": "A"
|
||||
},
|
||||
{
|
||||
"name": "@",
|
||||
"target": "test1.foo.com,https://goo.com/$1",
|
||||
@@ -33,6 +39,11 @@
|
||||
"name": "@",
|
||||
"target": "test2.foo.com,https://goo.com/$1",
|
||||
"type": "CF_TEMP_REDIRECT"
|
||||
},
|
||||
{
|
||||
"name": "@",
|
||||
"target": "test3.foo.com,test-worker",
|
||||
"type": "CF_WORKER_ROUTE"
|
||||
}
|
||||
],
|
||||
"registrar": "Third-Party"
|
||||
|
@@ -1,5 +1,7 @@
|
||||
$TTL 300
|
||||
;@ IN CF_REDIRECT test1.foo.com,https://goo.com/$1
|
||||
;@ IN CF_TEMP_REDIRECT test2.foo.com,https://goo.com/$1
|
||||
;@ IN CF_WORKER_ROUTE test3.foo.com,test-worker
|
||||
test1.foo.com.sub IN A 10.2.3.1
|
||||
test2.foo.com.sub IN A 10.2.3.2
|
||||
test3.foo.com.sub IN A 10.2.3.3
|
||||
|
3
pkg/js/parse_tests/040-cfWorkerRoute.js
Normal file
3
pkg/js/parse_tests/040-cfWorkerRoute.js
Normal file
@@ -0,0 +1,3 @@
|
||||
D("foo.com","none",
|
||||
CF_WORKER_ROUTE("test.foo.com","test-worker")
|
||||
);
|
18
pkg/js/parse_tests/040-cfWorkerRoute.json
Normal file
18
pkg/js/parse_tests/040-cfWorkerRoute.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"registrars": [],
|
||||
"dns_providers": [],
|
||||
"domains": [
|
||||
{
|
||||
"name": "foo.com",
|
||||
"registrar": "none",
|
||||
"dnsProviders": {},
|
||||
"records": [
|
||||
{
|
||||
"type": "CF_WORKER_ROUTE",
|
||||
"name": "@",
|
||||
"target": "test.foo.com,test-worker"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
2
pkg/js/parse_tests/040-cfWorkerRoute/foo.com.zone
Normal file
2
pkg/js/parse_tests/040-cfWorkerRoute/foo.com.zone
Normal file
@@ -0,0 +1,2 @@
|
||||
$TTL 300
|
||||
;@ IN CF_WORKER_ROUTE test.foo.com,test-worker
|
Reference in New Issue
Block a user