Skip to content

Commit

Permalink
Merge branch 'main' into issue/3020
Browse files Browse the repository at this point in the history
  • Loading branch information
imlonghao committed Aug 4, 2024
2 parents afc6716 + 0869052 commit 88b2f84
Show file tree
Hide file tree
Showing 87 changed files with 1,411 additions and 555 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
gotestsum --junitfile ${TEST_RESULTS}/gotestsum-report.xml -- $PACKAGE_NAMES
- name: Enforce Go Formatted Code
run: "[ `go fmt ./... | wc -l` -eq 0 ]"
- uses: actions/upload-artifact@v4.3.3
- uses: actions/upload-artifact@v4.3.4
with:
name: unit-tests
path: ${{ env.TEST_RESULTS }}
Expand Down Expand Up @@ -206,7 +206,7 @@ jobs:
echo "Skip test for ${{ matrix.provider }} provider"
fi
working-directory: integrationTest
- uses: actions/upload-artifact@v4.3.3
- uses: actions/upload-artifact@v4.3.4
with:
name: integration-tests-${{ matrix.provider }}
path: ${{ env.TEST_RESULTS }}
3 changes: 3 additions & 0 deletions build/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ func main() {
if err := generateFeatureMatrix(); err != nil {
log.Fatal(err)
}
if err := generateOwnersFile(); err != nil {
log.Fatal(err)
}
funcs, err := generateFunctionTypes()
if err != nil {
log.Fatal(err)
Expand Down
68 changes: 68 additions & 0 deletions build/generate/ownersFile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"github.com/StackExchange/dnscontrol/v4/providers"
"os"
"sort"
"strings"
)

func generateOwnersFile() error {
maintainers := providers.ProviderMaintainers
sortedProviderNames := getSortedProviderNames(maintainers)

var ownersData strings.Builder
for _, providerName := range sortedProviderNames {
providerMaintainer := maintainers[providerName]
if providerMaintainer == "NEEDS VOLUNTEER" {
ownersData.WriteString("# ")
}
ownersData.WriteString("providers/")
ownersData.WriteString(getProviderDirectory(providerName))
ownersData.WriteString(" ")
ownersData.WriteString(providerMaintainer)
ownersData.WriteString("\n")
}

file, err := os.Create("OWNERS")
if err != nil {
return err
}
defer file.Close()

_, err = file.WriteString(ownersData.String())
if err != nil {
return err
}

return nil
}

func getProviderDirectory(providerName string) string {
// Strip the underscores from the providerName constants
providerDirectory := strings.ToLower(
strings.ReplaceAll(
providerName, "_", "",
),
)

// These providers use a different directory name
if providerDirectory == "cloudflareapi" {
providerDirectory = "cloudflare"
}
if providerDirectory == "dnsoverhttps" {
providerDirectory = "doh"
}

return providerDirectory
}

func getSortedProviderNames(maintainers map[string]string) []string {
providerNameSorted := make([]string, 0, len(maintainers))
for providerNameKey := range maintainers {
providerNameSorted = append(providerNameSorted, providerNameKey)
}
sort.Strings(providerNameSorted)

return providerNameSorted
}
7 changes: 7 additions & 0 deletions commands/printIR.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/StackExchange/dnscontrol/v4/pkg/js"
"github.com/StackExchange/dnscontrol/v4/pkg/normalize"
"github.com/StackExchange/dnscontrol/v4/pkg/rfc4183"
"github.com/StackExchange/dnscontrol/v4/pkg/rtypes"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -128,6 +129,12 @@ func ExecuteDSL(args ExecuteDSLArgs) (*models.DNSConfig, error) {
if err != nil {
return nil, fmt.Errorf("executing %s: %w", args.JSFile, err)
}

err = rtypes.PostProcess(dnsConfig.Domains)
if err != nil {
return nil, err
}

return dnsConfig, nil
}

Expand Down
49 changes: 45 additions & 4 deletions commands/types/dnscontrol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,17 @@ declare function CAA(name: string, tag: "issue" | "issuewild" | "iodef", value:
declare function CAA_BUILDER(opts: { label?: string; iodef: string; iodef_critical?: boolean; issue: string[]; issue_critical?: boolean; issuewild: string[]; issuewild_critical?: boolean; ttl?: Duration }): DomainModifier;

/**
* WARNING: Cloudflare is removing this feature and replacing it with a new
* feature called "Dynamic Single Redirect". DNSControl will automatically
* generate "Dynamic Single Redirects" for a limited number of use cases. See
* [`CLOUDFLAREAPI`](../provider/cloudflareapi.md) for details.
*
* `CF_REDIRECT` uses Cloudflare-specific features ("Forwarding URL" Page Rules) to
* generate a HTTP 301 permanent redirect.
*
* If _any_ `CF_REDIRECT` or [`CF_TEMP_REDIRECT`](CF_TEMP_REDIRECT.md) functions are used then
* `dnscontrol` will manage _all_ "Forwarding URL" type Page Rules for the domain.
* Page Rule types other than "Forwarding URL will be left alone.
* Page Rule types other than "Forwarding URL" will be left alone.
*
* WARNING: Cloudflare does not currently fully document the Page Rules API and
* this interface is not extensively tested. Take precautions such as making
Expand All @@ -503,6 +508,41 @@ declare function CAA_BUILDER(opts: { label?: string; iodef: string; iodef_critic
declare function CF_REDIRECT(source: string, destination: string, ...modifiers: RecordModifier[]): DomainModifier;

/**
* `CF_SINGLE_REDIRECT` is a Cloudflare-specific feature for creating HTTP 301
* (permanent) or 302 (temporary) redirects.
*
* This feature manages dynamic "Single Redirects". (Single Redirects can be
* static or dynamic but DNSControl only maintains dynamic redirects).
*
* Cloudflare documentation: <https://developers.cloudflare.com/rules/url-forwarding/single-redirects/>
*
* ```javascript
* 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);
* ```
*
* The fields are:
*
* * name: The name (basically a comment, but it must be unique)
* * code: Either 301 (permanent) or 302 (temporary) redirects. May be a number or string.
* * when: What Cloudflare sometimes calls the "rule expression".
* * then: The replacement expression.
*
* 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).
*
* @see https://docs.dnscontrol.org/language-reference/domain-modifiers/service-provider-specific/cloudflare-dns/cf_single_redirect
*/
declare function CF_SINGLE_REDIRECT(name: string, code: number, when: string, then: string, ...modifiers: RecordModifier[]): DomainModifier;

/**
* WARNING: Cloudflare is removing this feature and replacing it with a new
* feature called "Dynamic Single Redirect". DNSControl will automatically
* generate "Dynamic Single Redirects" for a limited number of use cases. See
* [`CLOUDFLAREAPI`](../provider/cloudflareapi.md) for details.
*
* `CF_TEMP_REDIRECT` uses Cloudflare-specific features ("Forwarding URL" Page
* Rules) to generate a HTTP 302 temporary redirect.
*
Expand Down Expand Up @@ -982,7 +1022,8 @@ declare function DS(name: string, keytag: number, algorithm: number, digesttype:
* not `domain.tld`.
*
* Some operators only act on an apex domain (e.g.
* [`CF_REDIRECT`](../domain-modifiers/CF_REDIRECT.md) and [`CF_TEMP_REDIRECT`](../domain-modifiers/CF_TEMP_REDIRECT.md)). Using them
* [`CF_SINGLE_REDIRECT`](../domain-modifiers/CF_SINGLE_REDIRECT.md),
* [`CF_REDIRECT`](../domain-modifiers/CF_REDIRECT.md), and [`CF_TEMP_REDIRECT`](../domain-modifiers/CF_TEMP_REDIRECT.md)). Using them
* in a `D_EXTEND` subdomain may not be what you expect.
*
* ```javascript
Expand Down Expand Up @@ -1779,7 +1820,7 @@ declare function LOC_BUILDER_STR(opts: { label?: string; str: string; alt?: numb
*
* ```javascript
* D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
* M365_BUILDER({
* M365_BUILDER("example.com", {
* initialDomain: "example.onmicrosoft.com",
* }),
* END);
Expand All @@ -1791,7 +1832,7 @@ declare function LOC_BUILDER_STR(opts: { label?: string; str: string; alt?: numb
*
* ```javascript
* D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
* M365_BUILDER({
* M365_BUILDER("example.com", {
* label: "test",
* mx: false,
* autodiscover: false,
Expand Down
1 change: 1 addition & 0 deletions documentation/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
* [AZURE_ALIAS](language-reference/domain-modifiers/AZURE_ALIAS.md)
* Cloudflare DNS
* [CF_REDIRECT](language-reference/domain-modifiers/CF_REDIRECT.md)
* [CF_SINGLE_REDIRECT](language-reference/domain-modifiers/CF_SINGLE_REDIRECT.md)
* [CF_TEMP_REDIRECT](language-reference/domain-modifiers/CF_TEMP_REDIRECT.md)
* [CF_WORKER_ROUTE](language-reference/domain-modifiers/CF_WORKER_ROUTE.md)
* ClouDNS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ parameter_types:
"modifiers...": RecordModifier[]
---

{% hint style="warning" %}
WARNING: Cloudflare is removing this feature and replacing it with a new
feature called "Dynamic Single Redirect". DNSControl will automatically
generate "Dynamic Single Redirects" for a limited number of use cases. See
[`CLOUDFLAREAPI`](../provider/cloudflareapi.md) for details.
{% endhint %}

`CF_REDIRECT` uses Cloudflare-specific features ("Forwarding URL" Page Rules) to
generate a HTTP 301 permanent redirect.

If _any_ `CF_REDIRECT` or [`CF_TEMP_REDIRECT`](CF_TEMP_REDIRECT.md) functions are used then
`dnscontrol` will manage _all_ "Forwarding URL" type Page Rules for the domain.
Page Rule types other than "Forwarding URL will be left alone.
Page Rule types other than "Forwarding URL" will be left alone.

{% hint style="warning" %}
**WARNING**: Cloudflare does not currently fully document the Page Rules API and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: CF_SINGLE_REDIRECT
parameters:
- name
- code
- when
- then
- modifiers...
provider: CLOUDFLAREAPI
parameter_types:
name: string
code: number
when: string
then: string
"modifiers...": RecordModifier[]
---

`CF_SINGLE_REDIRECT` is a Cloudflare-specific feature for creating HTTP 301
(permanent) or 302 (temporary) redirects.

This feature manages dynamic "Single Redirects". (Single Redirects can be
static or dynamic but DNSControl only maintains dynamic redirects).

Cloudflare documentation: <https://developers.cloudflare.com/rules/url-forwarding/single-redirects/>

{% code title="dnsconfig.js" %}
```javascript
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 %}

The fields are:

* name: The name (basically a comment, but it must be unique)
* code: Either 301 (permanent) or 302 (temporary) redirects. May be a number or string.
* when: What Cloudflare sometimes calls the "rule expression".
* then: The replacement expression.

{% hint style="info" %}
**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).
{% endhint %}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ parameter_types:
"modifiers...": RecordModifier[]
---

{% hint style="warning" %}
**WARNING**: Cloudflare is removing this feature and replacing it with a new
feature called "Dynamic Single Redirect". DNSControl will automatically
generate "Dynamic Single Redirects" for a limited number of use cases. See
[`CLOUDFLAREAPI`](../provider/cloudflareapi.md) for details.
{% endhint %}

`CF_TEMP_REDIRECT` uses Cloudflare-specific features ("Forwarding URL" Page
Rules) to generate a HTTP 302 temporary redirect.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ It doesn't set up SPF or DMARC. See [`SPF_BUILDER`](SPF_BUILDER.md) and [`DMARC_
{% code title="dnsconfig.js" %}
```javascript
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
M365_BUILDER({
M365_BUILDER("example.com", {
initialDomain: "example.onmicrosoft.com",
}),
END);
Expand All @@ -47,7 +47,7 @@ This sets up `MX` records, Autodiscover, and DKIM.
{% code title="dnsconfig.js" %}
```javascript
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
M365_BUILDER({
M365_BUILDER("example.com", {
label: "test",
mx: false,
autodiscover: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ defined as separate domains via separate [`D()`](D.md) statements, then
not `domain.tld`.

Some operators only act on an apex domain (e.g.
[`CF_REDIRECT`](../domain-modifiers/CF_REDIRECT.md) and [`CF_TEMP_REDIRECT`](../domain-modifiers/CF_TEMP_REDIRECT.md)). Using them
[`CF_SINGLE_REDIRECT`](../domain-modifiers/CF_SINGLE_REDIRECT.md),
[`CF_REDIRECT`](../domain-modifiers/CF_REDIRECT.md), and [`CF_TEMP_REDIRECT`](../domain-modifiers/CF_TEMP_REDIRECT.md)). Using them
in a `D_EXTEND` subdomain may not be what you expect.

{% code title="dnsconfig.js" %}
Expand Down
Loading

0 comments on commit 88b2f84

Please sign in to comment.