Skip to content

Commit 7030841

Browse files
tlimoncellidas7pad
andauthored
REFACTOR: BIND/GANDI_V5 add "RP" record type, rewrite CLOUDFLAREAPI CF_* and more (#3886)
# Issue * New record type: "RP" (supported by BIND and GANDI_V5) * Cloudflare: CF_REDIRECT/CF_TEMP_REDIRECT now generate CF_SINGLE_REDIRECT records. All PAGE_RULE-based code is removed. PAGE_RULEs are deprecated at Cloudflare. (be careful when upgrading!) * New "v2" RecordConfig: RP and CF_SINGLE_REDIRECT are the only record types that use this method. It shifts most of the work out of JavaScript and into the Go code, making new record types easier to make, easier to test, and easier to use by providers. This opens the door to new things like a potential code-generator for rtypes. Converting existing rtypes will happen over the next year. * When only the TTL changes (MODIFY-TTL), the output lists the TTL change first, not at the end of the line where it is visually lost. * CF_REDIRECT/CF_TEMP_REDIRECT generate different rule "names". They will be updated the first time you "push" with this release. The order of the rules may also change. If you rules depend on a particular order, be very careful with this upgrade! Refactoring: * New "v2" RecordConfig: Record types using this new method simply package the parameters from dnsconfig.js statements like CF_REDIRECT(foo,bar) and send them (raw) to the Go code. The Go code does all processing, validation, etc. and turns them into RecordConfig that store all the rdata in `RecordConfig.F`. No more adding fields to RecordConfig for each new record type! * RecordConfig.IsModernType() returns true if the record uses the new v2 record mechanism. * PostProcess is now a method on DnsConfig and DomainConfig. * DOC: How to create new rtypes using the v2 method (incomplete) Other things: * Integration tests for CF "full proxy" are removed. This feature doesn't exist any more. * DEV: Debugger tips now includes VSCode advice * TESTING: The names of testgroup's can now have extra spaces to make data align better * CF_TEMP_REDIRECT/CF_REDIRECT is now a "builder" that generates CLOUDFLAREAPI_SINGLE_REDIRECT records. * And more! # Resolution --------- Co-authored-by: Jakob Ackermann <[email protected]>
1 parent bcef7f5 commit 7030841

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1598
-950
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@ types-dnscontrol.d.ts
3333
dist/
3434
node_modules/
3535

36+
// Golang
37+
__debug_bin*
38+
3639
// Test artifact:
3740
*.ACTUAL

build/generate/featureMatrix.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func matrixData() *FeatureMatrix {
115115
DomainModifierNaptr = "[`NAPTR`](../language-reference/domain-modifiers/NAPTR.md)"
116116
DomainModifierOpenpgpkey = "[`DNSKEY`](../language-reference/domain-modifiers/OPENPGPKEY.md)"
117117
DomainModifierPtr = "[`PTR`](../language-reference/domain-modifiers/PTR.md)"
118+
DomainModifierRP = "[`RP`](../language-reference/domain-modifiers/RP.md)"
118119
DomainModifierSMIMEA = "[`SMIMEA`](../language-reference/domain-modifiers/SMIMEA.md)"
119120
DomainModifierSoa = "[`SOA`](../language-reference/domain-modifiers/SOA.md)"
120121
DomainModifierSrv = "[`SRV`](../language-reference/domain-modifiers/SRV.md)"
@@ -280,6 +281,10 @@ func matrixData() *FeatureMatrix {
280281
DomainModifierPtr,
281282
providers.CanUsePTR,
282283
)
284+
setCapability(
285+
DomainModifierRP,
286+
providers.CanUseRP,
287+
)
283288
setCapability(
284289
DomainModifierSMIMEA,
285290
providers.CanUseSMIMEA,

commands/printIR.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/StackExchange/dnscontrol/v4/pkg/js"
1313
"github.com/StackExchange/dnscontrol/v4/pkg/normalize"
1414
"github.com/StackExchange/dnscontrol/v4/pkg/rfc4183"
15-
"github.com/StackExchange/dnscontrol/v4/pkg/rtypes"
1615
"github.com/urfave/cli/v2"
1716
)
1817

@@ -130,7 +129,7 @@ func ExecuteDSL(args ExecuteDSLArgs) (*models.DNSConfig, error) {
130129
return nil, fmt.Errorf("executing %s: %w", args.JSFile, err)
131130
}
132131

133-
err = rtypes.PostProcess(dnsConfig.Domains)
132+
err = dnsConfig.PostProcess()
134133
if err != nil {
135134
return nil, err
136135
}

commands/types/dnscontrol.d.ts

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,13 @@ declare function CAA(name: string, tag: "issue" | "issuewild" | "iodef" | "conta
550550
declare function CAA_BUILDER(opts: { label?: string; iodef: string; iodef_critical?: boolean; issue: string[]|string; issue_critical?: boolean; issuewild: string[]|string; issuewild_critical?: boolean; issuevmc: string[]|string; issuevmc_critical?: boolean; issuemail: string[]|string; issuemail_critical?: boolean; ttl?: Duration }): DomainModifier;
551551

552552
/**
553-
* WARNING: Cloudflare is removing this feature and replacing it with a new
553+
* **WARNING:** Cloudflare is removing this feature and replacing it with a new
554554
* feature called "Dynamic Single Redirect". DNSControl will automatically
555555
* generate "Dynamic Single Redirects" for a limited number of use cases. See
556556
* [`CLOUDFLAREAPI`](../../provider/cloudflareapi.md) for details.
557557
*
558-
* `CF_REDIRECT` uses Cloudflare-specific features ("Forwarding URL" Page Rules) to
559-
* generate a HTTP 301 permanent redirect.
558+
* `CF_REDIRECT` uses Cloudflare-specific features ("Forwarding URL" Page
559+
* Rules) to generate a HTTP 301 permanent redirect.
560560
*
561561
* If _any_ `CF_REDIRECT` or [`CF_TEMP_REDIRECT`](CF_TEMP_REDIRECT.md) functions are used then
562562
* `dnscontrol` will manage _all_ "Forwarding URL" type Page Rules for the domain.
@@ -587,56 +587,73 @@ declare function CF_REDIRECT(source: string, destination: string, ...modifiers:
587587

588588
/**
589589
* `CF_SINGLE_REDIRECT` is a Cloudflare-specific feature for creating HTTP redirects. 301, 302, 303, 307, 308 are supported.
590-
* Typically one uses 302 (temporary) or (less likely) 301 (permanent).
590+
* Typically one uses 302 (temporary) or 301 (permanent).
591591
*
592592
* This feature manages dynamic "Single Redirects". (Single Redirects can be
593593
* static or dynamic but DNSControl only maintains dynamic redirects).
594594
*
595+
* DNSControl will delete any "single redirects" it doesn't recognize (i.e. ones created via the web UI) so please be careful.
596+
*
595597
* Cloudflare documentation: <https://developers.cloudflare.com/rules/url-forwarding/single-redirects/>
596598
*
597599
* ```javascript
598600
* D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
599-
* CF_SINGLE_REDIRECT("name", 302, "when", "then"),
600601
* CF_SINGLE_REDIRECT('redirect www.example.com', 302, 'http.host eq "www.example.com"', 'concat("https://otherplace.com", http.request.uri.path)'),
601602
* CF_SINGLE_REDIRECT('redirect yyy.example.com', 302, 'http.host eq "yyy.example.com"', 'concat("https://survey.stackoverflow.co", "")'),
603+
* CF_TEMP_REDIRECT("*example.com/*", "https://contests.otherexample.com/$2"),
602604
* );
603605
* ```
604606
*
605607
* The fields are:
606608
*
607-
* * name: The name (basically a comment, but it must be unique)
609+
* * name: The name (basically a comment)
608610
* * code: Any of 301, 302, 303, 307, 308. May be a number or string.
609611
* * when: What Cloudflare sometimes calls the "rule expression".
610612
* * then: The replacement expression.
611613
*
612-
* NOTE: The features [`CF_REDIRECT`](CF_REDIRECT.md) and [`CF_TEMP_REDIRECT`](CF_TEMP_REDIRECT.md) generate `CF_SINGLE_REDIRECT` if enabled in [`CLOUDFLAREAPI`](../../provider/cloudflareapi.md).
614+
* DNSControl does not currently choose the order of the rules. New rules are
615+
* added to the end of the list. Use Cloudflare's dashboard to re-order the rule,
616+
* DNSControl should not change them. (In the future we hope to add a feature
617+
* where the order the rules appear in dnsconfig.js is maintained in the
618+
* dashboard.)
619+
*
620+
* ## `CF_REDIRECT` and `CF_TEMP_REDIRECT`
621+
*
622+
* `CF_REDIRECT` and `CF_TEMP_REDIRECT` used to manage Cloudflare Page Rules.
623+
* However that feature is going away. To help with the migration, DNSControl now
624+
* translates those commands into CF_SINGLE_REDIRECT equivalents. The conversion
625+
* process is a transpiler that only understands certain formats. Please submit
626+
* a Github issue if you find something it can't handle.
613627
*
614628
* @see https://docs.dnscontrol.org/language-reference/domain-modifiers/service-provider-specific/cloudflare-dns/cf_single_redirect
615629
*/
616630
declare function CF_SINGLE_REDIRECT(name: string, code: number, when: string, then: string, ...modifiers: RecordModifier[]): DomainModifier;
617631

618632
/**
619-
* WARNING: Cloudflare is removing this feature and replacing it with a new
633+
* **WARNING:** Cloudflare is removing this feature and replacing it with a new
620634
* feature called "Dynamic Single Redirect". DNSControl will automatically
621635
* generate "Dynamic Single Redirects" for a limited number of use cases. See
622636
* [`CLOUDFLAREAPI`](../../provider/cloudflareapi.md) for details.
623637
*
624638
* `CF_TEMP_REDIRECT` uses Cloudflare-specific features ("Forwarding URL" Page
625639
* Rules) to generate a HTTP 302 temporary redirect.
626640
*
627-
* If _any_ [`CF_REDIRECT`](CF_REDIRECT.md) or `CF_TEMP_REDIRECT` functions are used then
641+
* If _any_ [`CF_REDIRECT`](CF_REDIRECT.md) or `CF_TEMP_REDIRECT functions are used then
628642
* `dnscontrol` will manage _all_ "Forwarding URL" type Page Rules for the domain.
629-
* Page Rule types other than "Forwarding URL will be left alone.
643+
* Page Rule types other than "Forwarding URL" will be left alone.
630644
*
631645
* WARNING: Cloudflare does not currently fully document the Page Rules API and
632646
* this interface is not extensively tested. Take precautions such as making
633647
* backups and manually verifying `dnscontrol preview` output before running
634648
* `dnscontrol push`. This is especially true when mixing Page Rules that are
635649
* managed by DNSControl and those that aren't.
636650
*
651+
* This example redirects the bare (aka apex, or naked) domain to www:
652+
*
637653
* ```javascript
638654
* D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
639-
* CF_TEMP_REDIRECT("example.example.com/*", "https://otherplace.yourdomain.com/$1"),
655+
* CF_TEMP_REDIRECT("example.com/*", "https://www.example.com/$1"),
656+
*
640657
* );
641658
* ```
642659
*
@@ -3205,6 +3222,21 @@ declare function REV(address: string): string;
32053222
*/
32063223
declare function REVCOMPAT(rfc: string): string;
32073224

3225+
/**
3226+
* `RP()` adds an RP record to a domain.
3227+
*
3228+
* The RP implementation in DNSControl is still experimental and may change.
3229+
*
3230+
* ```javascript
3231+
* D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
3232+
* RP("@", "user.example.com.", "example.com."),
3233+
* );
3234+
* ```
3235+
*
3236+
* @see https://docs.dnscontrol.org/language-reference/domain-modifiers/rp
3237+
*/
3238+
declare function RP(name: string, mbox: string, txt: string, ...modifiers: RecordModifier[]): DomainModifier;
3239+
32083240
/**
32093241
* `SMIMEA` adds a `SMIMEA` record to a domain. The name should be the hashed and stripped local part of the e-mail.
32103242
*

0 commit comments

Comments
 (0)