fixing tests

This commit is contained in:
Thomas Limoncelli 2025-11-26 23:13:39 -05:00
parent 3d5f5a1c49
commit 4b68c79d4f
No known key found for this signature in database
26 changed files with 202 additions and 216 deletions

3
.gitignore vendored
View file

@ -33,5 +33,8 @@ types-dnscontrol.d.ts
dist/
node_modules/
// Golang
__debug_bin*
// Test artifact:
*.ACTUAL

View file

@ -5,8 +5,9 @@ package models
// NOTE: Only newer rtypes are processed this way. Eventually the
// legacy types will be converted.
type RawRecordConfig struct {
Type string `json:"type"`
Args []any `json:"args,omitempty"`
Metas []map[string]any `json:"metas,omitempty"`
TTL uint32 `json:"ttl,omitempty"`
Type string `json:"type"`
Args []any `json:"args,omitempty"`
Metas []map[string]any `json:"metas,omitempty"`
TTL uint32 `json:"ttl,omitempty"`
FilePos string `json:"filepos"` // Where in the file this record was defined.
}

View file

@ -24,9 +24,9 @@ type RecordConfig struct {
// Name is the shortname i.e. the FQDN without the parent directory's suffix.
// It should never be "". Record at the apex (naked domain) are represented by "@".
Name string `json:"name"` // The short name, PunyCode. See above.
NameRaw string `json:"name_raw"` // .Name as the user entered it in dnsconfig.js (downcased).
NameUnicode string `json:"name_unicode"` // .Name as Unicode (downcased, then convertedot Unicode).
Name string `json:"name"` // The short name, PunyCode. See above.
NameRaw string `json:"name_raw,omitempty"` // .Name as the user entered it in dnsconfig.js (downcased).
NameUnicode string `json:"name_unicode,omitempty"` // .Name as Unicode (downcased, then convertedot Unicode).
// This is the FQDN version of .Name. It should never have a trailing ".".
NameFQDN string `json:"-"` // Must end with ".$origin".
@ -35,7 +35,7 @@ type RecordConfig struct {
// F is the binary representation of the record's data usually a dns.XYZ struct.
// Always stored in Punycode, not Unicode. Downcased where applicable.
F any `json:"fields"`
F any `json:"fields,omitempty"`
//FieldsAsRaw []string // Fields as received from the dnsconfig.js file, converted to strings.
//FieldsAsUnicode []string // fields with IDN fields converted to Unicode for display purposes.

View file

@ -621,7 +621,7 @@ func Test_diffTargets(t *testing.T) {
Key: models.RecordKey{NameFQDN: "laba.f.com", Type: "A"},
New: models.Records{testDataAA5678ttl700, testDataAA1234ttl700},
Msgs: []string{
"± MODIFY-TTL laba.f.com A 5.6.7.8 ttl=(300->700)",
"± MODIFY-TTL laba.f.com A ttl=(300->700) 5.6.7.8",
"+ CREATE laba.f.com A 1.2.3.4 ttl=700",
},
},
@ -836,7 +836,7 @@ func Test_splitTTLOnly(t *testing.T) {
},
wantExistDiff: nil,
wantDesireDiff: nil,
wantChanges: "ChangeList: len=1\n00: Change: verb=CHANGE\n key={laba.f.com A}\n Hints=OnlyTTL\n{laba.f.com A} old=[1.2.3.4]\n new=[1.2.3.4]\n msg=[\"± MODIFY-TTL laba.f.com A 1.2.3.4 ttl=(300->700)\"]\n",
wantChanges: "ChangeList: len=1\n00: Change: verb=CHANGE\n key={laba.f.com A}\n Hints=OnlyTTL\n{laba.f.com A} old=[1.2.3.4]\n new=[1.2.3.4]\n msg=[\"± MODIFY-TTL laba.f.com A ttl=(300->700) 1.2.3.4\"]\n",
},
{

View file

@ -2436,9 +2436,19 @@ function rawrecordBuilder(type) {
rawArgs.push(arguments[i]);
}
// Record which line called this record type.
// NB(tlim): Hopefully we can find a better way to do this in the
// future. Right now we're faking that there was an error just to parse
// out the line number. That's inefficient but I can't find anything better.
// This will certainly break if we change to a different Javascript interpreter.
// Hopefully any other interpreter will have a better way to do this.
var positionLines = new Error().stack.split('\n');
var position = positionLines[positionLines.length - 2];
return function (d) {
var record = {
type: type,
filepos: position,
};
// Process the args: Functions are executed, objects are assumed to

View file

@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"unicode"
@ -131,8 +132,8 @@ func TestParsedFiles(t *testing.T) {
}
actualZone := buf.String()
es := string(expectedZone)
as := actualZone
es := strings.TrimSpace(string(expectedZone))
as := strings.TrimSpace(actualZone)
if es != as {
// On failure, leave behind the .ACTUAL file.
if err := os.WriteFile(zoneFile+".ACTUAL", []byte(actualZone), 0o644); err != nil {

View file

@ -16,11 +16,8 @@
"name": "foo.com",
"records": [
{
"fields": null,
"filepos": "[line:5:5]",
"name": "@",
"name_raw": "",
"name_unicode": "",
"target": "1.2.3.4",
"ttl": 300,
"type": "A"

View file

@ -16,11 +16,8 @@
"name": "foo.com",
"records": [
{
"fields": null,
"filepos": "[line:5:5]",
"name": "@",
"name_raw": "",
"name_unicode": "",
"target": "1.2.3.4",
"ttl": 42,
"type": "A"

View file

@ -9,14 +9,11 @@
"name": "foo.com",
"records": [
{
"fields": null,
"filepos": "[line:4:5]",
"meta": {
"cloudflare_proxy": "ON"
},
"name": "@",
"name_raw": "",
"name_unicode": "",
"target": "1.2.3.4",
"ttl": 300,
"type": "A"

View file

@ -16,31 +16,22 @@
"name": "foo.com",
"records": [
{
"fields": null,
"filepos": "[line:7:5]",
"name": "@",
"name_raw": "",
"name_unicode": "",
"target": "1.2.3.4",
"ttl": 300,
"type": "A"
},
{
"fields": null,
"filepos": "[line:8:5]",
"name": "p1",
"name_raw": "",
"name_unicode": "",
"target": "1.2.3.5",
"ttl": 300,
"type": "A"
},
{
"fields": null,
"filepos": "[line:9:5]",
"name": "p255",
"name_raw": "",
"name_unicode": "",
"target": "1.2.4.3",
"ttl": 300,
"type": "A"

View file

@ -16,40 +16,31 @@
"name": "foo.com",
"records": [
{
"fields": null,
"filepos": "[line:18:5]",
"meta": {
"transform": "0.0.0.0 ~ 1.1.1.0 ~ 2.2.2.2 ~ ; 1.1.1.1 ~ 2.2.2.2 ~ ~ 3.3.3.3,4.4.4.4,5.5.5.5"
},
"name": "@",
"name_raw": "",
"name_unicode": "",
"target": "3.3.3.3",
"ttl": 300,
"type": "A"
},
{
"fields": null,
"filepos": "[line:18:5]",
"meta": {
"transform": "0.0.0.0 ~ 1.1.1.0 ~ 2.2.2.2 ~ ; 1.1.1.1 ~ 2.2.2.2 ~ ~ 3.3.3.3,4.4.4.4,5.5.5.5"
},
"name": "@",
"name_raw": "",
"name_unicode": "",
"target": "4.4.4.4",
"ttl": 300,
"type": "A"
},
{
"fields": null,
"filepos": "[line:18:5]",
"meta": {
"transform": "0.0.0.0 ~ 1.1.1.0 ~ 2.2.2.2 ~ ; 1.1.1.1 ~ 2.2.2.2 ~ ~ 3.3.3.3,4.4.4.4,5.5.5.5"
},
"name": "@",
"name_raw": "",
"name_unicode": "",
"target": "5.5.5.5",
"ttl": 300,
"type": "A"

View file

@ -9,21 +9,15 @@
"name": "foo1.com",
"records": [
{
"fields": null,
"filepos": "[line:2:5]",
"name": "bar",
"name_raw": "",
"name_unicode": "",
"target": "1.1.1.1",
"ttl": 300,
"type": "A"
},
{
"fields": null,
"filepos": "[line:3:5]",
"name": "foo",
"name_raw": "",
"name_unicode": "",
"target": "5.5.5.5",
"ttl": 300,
"type": "A"
@ -39,21 +33,15 @@
"name": "inny",
"records": [
{
"fields": null,
"filepos": "[line:2:5]",
"name": "bar.foo1.com",
"name_raw": "",
"name_unicode": "",
"target": "4.4.4.101",
"ttl": 60,
"type": "A"
},
{
"fields": null,
"filepos": "[line:3:5]",
"name": "foo.foo1.com",
"name_raw": "",
"name_unicode": "",
"target": "6.6.6.3",
"ttl": 60,
"type": "A"
@ -69,21 +57,15 @@
"name": "com.inny",
"records": [
{
"fields": null,
"filepos": "[line:2:5]",
"name": "bar.foo1",
"name_raw": "",
"name_unicode": "",
"target": "1.1.1.1",
"ttl": 99,
"type": "A"
},
{
"fields": null,
"filepos": "[line:3:5]",
"name": "foo.foo1",
"name_raw": "",
"name_unicode": "",
"target": "7.7.7.7",
"ttl": 99,
"type": "A"

View file

@ -9,11 +9,8 @@
"name": "foo.com",
"records": [
{
"fields": null,
"filepos": "[line:1:1]",
"name": "@",
"name_raw": "",
"name_unicode": "",
"target": "1.2.3.4",
"ttl": 300,
"type": "A"

View file

@ -9,11 +9,8 @@
"name": "foo.com",
"records": [
{
"fields": null,
"filepos": "[line:2:5]",
"name": "@",
"name_raw": "",
"name_unicode": "",
"target": "foo.com.",
"ttl": 300,
"type": "ALIAS"

View file

@ -1,4 +1,4 @@
D("foo.com", "none",
CF_REDIRECT("test.foo.com", "https://goo.com/$1"),
CF_TEMP_REDIRECT("test.foo.com", "https://goo.com/$1"),
CF_REDIRECT("test1.foo.com", "https://goo.com/$1"),
CF_TEMP_REDIRECT("test2.foo.com", "https://goo.com/$1"),
);

View file

@ -9,24 +9,36 @@
"name": "foo.com",
"records": [
{
"filepos": "[line:2:5]",
"meta": {
"orig_custom_type": "CF_REDIRECT"
"fields": {
"code": 301,
"sr_display": "name=(001,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
"sr_name": "001,301,test1.foo.com,https://goo.com/$1",
"sr_then": "concat(\"https://goo.com\", http.request.uri.path)",
"sr_when": "http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\""
},
"filepos": "[line:2:5]",
"name": "@",
"target": "test.foo.com,https://goo.com/$1",
"ttl": 300,
"type": "CF_REDIRECT"
"name_raw": "@",
"name_unicode": "@",
"target": "test1.foo.com,https://goo.com/$1",
"ttl": 1,
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"filepos": "[line:3:5]",
"meta": {
"orig_custom_type": "CF_TEMP_REDIRECT"
"fields": {
"code": 302,
"sr_display": "name=(002,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
"sr_name": "002,302,test2.foo.com,https://goo.com/$1",
"sr_then": "concat(\"https://goo.com\", http.request.uri.path)",
"sr_when": "http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\""
},
"filepos": "[line:3:5]",
"name": "@",
"target": "test.foo.com,https://goo.com/$1",
"ttl": 300,
"type": "CF_TEMP_REDIRECT"
"name_raw": "@",
"name_unicode": "@",
"target": "test2.foo.com,https://goo.com/$1",
"ttl": 1,
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
}
],
"registrar": "none"

View file

@ -1,3 +1,3 @@
$TTL 300
;@ IN CF_REDIRECT test.foo.com,https://goo.com/$1
;@ IN CF_TEMP_REDIRECT test.foo.com,https://goo.com/$1
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT test1.foo.com,https://goo.com/$1
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT test2.foo.com,https://goo.com/$1

View file

@ -15,26 +15,6 @@
},
"name": "foo.com",
"records": [
{
"filepos": "[line:9:5]",
"meta": {
"orig_custom_type": "CF_REDIRECT"
},
"name": "@",
"target": "test1.foo.com,https://goo.com/$1",
"ttl": 300,
"type": "CF_REDIRECT"
},
{
"filepos": "[line:10:5]",
"meta": {
"orig_custom_type": "CF_TEMP_REDIRECT"
},
"name": "@",
"target": "test2.foo.com,https://goo.com/$1",
"ttl": 300,
"type": "CF_TEMP_REDIRECT"
},
{
"filepos": "[line:11:5]",
"meta": {
@ -45,6 +25,38 @@
"ttl": 300,
"type": "CF_WORKER_ROUTE"
},
{
"fields": {
"code": 301,
"sr_display": "name=(003,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
"sr_name": "003,301,test1.foo.com,https://goo.com/$1",
"sr_then": "concat(\"https://goo.com\", http.request.uri.path)",
"sr_when": "http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\""
},
"filepos": "[line:9:5]",
"name": "@",
"name_raw": "@",
"name_unicode": "@",
"target": "test1.foo.com,https://goo.com/$1",
"ttl": 1,
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"fields": {
"code": 302,
"sr_display": "name=(004,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
"sr_name": "004,302,test2.foo.com,https://goo.com/$1",
"sr_then": "concat(\"https://goo.com\", http.request.uri.path)",
"sr_when": "http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\""
},
"filepos": "[line:10:5]",
"name": "@",
"name_raw": "@",
"name_unicode": "@",
"target": "test2.foo.com,https://goo.com/$1",
"ttl": 1,
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"filepos": "[line:6:5]",
"name": "test1.foo.com.sub",

View file

@ -1,7 +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
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT test1.foo.com,https://goo.com/$1
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT test2.foo.com,https://goo.com/$1
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
test3.foo.com.sub IN A 10.2.3.3

View file

@ -7,63 +7,87 @@
"dnscontrol_uniquename": "foo.com"
},
"name": "foo.com",
"rawrecords": [
{
"args": [
"name1",
301,
"when1",
"then1"
],
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"args": [
"name2",
302,
"when2",
"then2"
],
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"args": [
"name3",
"301",
"when3",
"then3"
],
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"args": [
"namettl",
302,
"whenttl",
"thenttl"
],
"ttl": 999,
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"args": [
"namemeta",
302,
"whenmeta",
"thenmeta"
],
"metas": [
{
"metastr": "stringy"
},
{
"metanum": 22
}
],
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
}
],
"records": [
{
"fields": {
"code": 301,
"sr_display": "name=(name1) code=(301) when=(when1) then=(then1)",
"sr_name": "name1",
"sr_then": "then1",
"sr_when": "when1"
},
"filepos": "[line:5:5]",
"name": "@",
"name_raw": "@",
"name_unicode": "@",
"target": "name1",
"ttl": 1,
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"fields": {
"code": 302,
"sr_display": "name=(name2) code=(302) when=(when2) then=(then2)",
"sr_name": "name2",
"sr_then": "then2",
"sr_when": "when2"
},
"filepos": "[line:6:5]",
"name": "@",
"name_raw": "@",
"name_unicode": "@",
"target": "name2",
"ttl": 1,
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"fields": {
"code": 301,
"sr_display": "name=(name3) code=(301) when=(when3) then=(then3)",
"sr_name": "name3",
"sr_then": "then3",
"sr_when": "when3"
},
"filepos": "[line:7:5]",
"name": "@",
"name_raw": "@",
"name_unicode": "@",
"target": "name3",
"ttl": 1,
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"fields": {
"code": 302,
"sr_display": "name=(namemeta) code=(302) when=(whenmeta) then=(thenmeta)",
"sr_name": "namemeta",
"sr_then": "thenmeta",
"sr_when": "whenmeta"
},
"filepos": "[line:9:5]",
"name": "@",
"name_raw": "@",
"name_unicode": "@",
"target": "namemeta",
"ttl": 1,
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"fields": {
"code": 302,
"sr_display": "name=(namettl) code=(302) when=(whenttl) then=(thenttl)",
"sr_name": "namettl",
"sr_then": "thenttl",
"sr_when": "whenttl"
},
"filepos": "[line:8:5]",
"name": "@",
"name_raw": "@",
"name_unicode": "@",
"target": "namettl",
"ttl": 1,
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
},
{
"filepos": "[line:2:5]",
"meta": {

View file

@ -55,6 +55,11 @@ func checkTarget(target string) error {
// validateRecordTypes list of valid rec.Type values. Returns true if this is a real DNS record type, false means it is a pseudo-type used internally.
func validateRecordTypes(rec *models.RecordConfig, domain string, pTypes []string) error {
if rec.IsModernType() {
// Modern types do their own validation.
return nil
}
// #rtype_variations
validTypes := map[string]bool{
"A": true,
@ -175,6 +180,11 @@ func checkSoa(expire uint32, minttl uint32, refresh uint32, retry uint32, mbox s
// checkTargets returns true if rec.Target is valid for the rec.Type.
func checkTargets(rec *models.RecordConfig, domain string) (errs []error) {
if rec.IsModernType() {
// Modern types do their own validation.
return nil
}
label := rec.GetLabel()
target := rec.GetTargetField()
check := func(e error) {

View file

@ -15,10 +15,9 @@ func ImportRawRecords(domains []*models.DomainConfig) error {
for _, rawRec := range dc.RawRecords {
rec, err := NewRecordConfigFromRaw(rawRec.Type, rawRec.Args, dc)
rec.FilePos = models.FixPosition(rawRec.FilePos)
if err != nil {
return fmt.Errorf("%s: %w", nil, err)
// TODO(tlim): Fix FilePos
//return fmt.Errorf("%s: %w", rawRec.FilePos, err)
return fmt.Errorf("%s: %w", rec.FilePos, err)
}
// Free memeory:
@ -44,7 +43,6 @@ func NewRecordConfigFromRaw(t string, args []any, dc *models.DomainConfig) (*mod
Type: t,
Name: args[0].(string), // May be fixed later.
Metadata: map[string]string{},
//FilePos: models.FixPosition(filePos),
}
setRecordNames(rec, dc, args[0].(string))

View file

@ -363,9 +363,6 @@ func (c *cloudflareProvider) mkDeleteCorrection(recType string, origRec *models.
idTxt = origRec.Original.(cloudflare.WorkerRoute).ID
case "CLOUDFLAREAPI_SINGLE_REDIRECT":
idTxt = origRec.Original.(cloudflare.RulesetRule).ID
// case "":
// fmt.Printf("DEBUG: %q origRec.Original type is %T\nrec=%+v\n\n", recType, origRec.Original, *origRec)
// idTxt = origRec.Original.(cloudflare.RulesetRule).ID
default:
//fmt.Printf("DEBUG: %q rec=%+v origRec.Original type is %T\n", recType, *origRec, origRec.Original)
fmt.Printf("SHOULD NOT HAPPEN: %q origRec.Original type is %T\n", recType, origRec.Original)

View file

@ -32,20 +32,20 @@ func (handle *CfTempRedirect) Name() string {
return "CF_TEMP_REDIRECT"
}
var services = map[string]int{}
var serviceMutex = sync.RWMutex{}
var redirCount = map[string]int{}
var redirCountMutex = sync.RWMutex{}
func inc(name string) {
serviceMutex.Lock()
defer serviceMutex.Unlock()
func incRedirCount(name string) {
redirCountMutex.Lock()
defer redirCountMutex.Unlock()
services[name]++
redirCount[name]++
}
func get(name string) int {
serviceMutex.Lock()
defer serviceMutex.Unlock()
return services[name]
func getRedirCount(name string) int {
redirCountMutex.Lock()
defer redirCountMutex.Unlock()
return redirCount[name]
}
func (handle *CfTempRedirect) FromArgs(dc *models.DomainConfig, rec *models.RecordConfig, args []any) error {
@ -68,10 +68,16 @@ func FromArgs_helper(dc *models.DomainConfig, rec *models.RecordConfig, args []a
return err
}
inc(dc.UniqueName)
name := fmt.Sprintf("%03d,%03d,%s,%s", get(dc.UniqueName), code, prWhen, prThen)
incRedirCount(dc.UniqueName)
name := fmt.Sprintf("%03d,%03d,%s,%s", getRedirCount(dc.UniqueName), code, prWhen, prThen)
target := fmt.Sprintf("%s,%s", prWhen, prThen)
sr := SingleRedirectConfig{}
rec.Type = sr.Name() // This record is now a CLOUDFLAREAPI_SINGLE_REDIRECT
return sr.FromArgs(dc, rec, []any{name, code, srWhen, srThen})
err = sr.FromArgs(dc, rec, []any{name, code, srWhen, srThen})
if err != nil {
return err
}
rec.SetTarget(target) // Overwrite target to old-style for compatibility
return nil
}

View file

@ -15,11 +15,6 @@ func init() {
type SingleRedirectConfig struct {
//
Code uint16 `json:"code,omitempty"` // 301 or 302
// PR == PageRule
PRWhen string `json:"pr_when,omitempty"`
PRThen string `json:"pr_then,omitempty"`
PRPriority int `json:"pr_priority,omitempty"` // Really an identifier for the rule.
PRDisplay string `json:"pr_display,omitempty"` // How is this displayed to the user (SetTarget) for CF_REDIRECT/CF_TEMP_REDIRECT
//
// SR == SingleRedirect
SRName string `json:"sr_name,omitempty"` // How is this displayed to the user
@ -53,18 +48,11 @@ func (handle *SingleRedirectConfig) FromArgs(dc *models.DomainConfig, rec *model
}
when = args[2].(string)
then = args[3].(string)
//fmt.Printf("\n\nDEBUG: targetFromRaw(name=%q code=%03d when=%q then=%q)\n", name, code, when, then)
display := targetFromRaw(name, code, when, then)
//fmt.Printf("DEBUG: targetFromRaw(name=%q code=%03d when=%q then=%q) display=%q\n\n\n", name, code, when, then, display)
rec.F = &SingleRedirectConfig{
Code: code,
//
PRWhen: "UNKNOWABLE",
PRThen: "UNKNOWABLE",
PRPriority: 0,
PRDisplay: "UNKNOWABLE",
//
SRName: name,
SRWhen: when,
SRThen: then,
@ -82,7 +70,7 @@ func (handle *SingleRedirectConfig) FromArgs(dc *models.DomainConfig, rec *model
rec.Comparable = display
rec.ZonefilePartial = display
_ = rec.SetTarget(display)
_ = rec.SetTarget(name)
return nil
}

View file

@ -7,31 +7,6 @@ import (
"strings"
)
// // TranscodePRtoSR takes a PAGE_RULE record, stores transcoded versions of the fields, and makes the record a CLOUDFLAREAPI_SINGLE_REDDIRECT.
// func TranscodePRtoSR(rec *models.RecordConfig) error {
// //rec.Type = SINGLEREDIRECT // This record is now a CLOUDFLAREAPI_SINGLE_REDIRECT
// // Extract the fields we're reading from:
// sr := rec.CloudflareRedirect
// code := sr.Code
// prWhen := sr.PRWhen
// prThen := sr.PRThen
// srName := sr.PRDisplay
// // Convert old-style patterns to new-style rules:
// srWhen, srThen, err := makeRuleFromPattern(prWhen, prThen)
// if err != nil {
// return err
// }
// // Fix the RecordConfig
// return makeSingleRedirectFromConvert(rec,
// sr.PRPriority,
// prWhen, prThen,
// code,
// srName, srWhen, srThen)
// }
// makeRuleFromPattern compile old-style patterns and replacements into new-style rules and expressions.
func makeRuleFromPattern(pattern, replacement string) (string, string, error) {
var srWhen, srThen string