Skip to content

Commit

Permalink
fmtjson and sort records
Browse files Browse the repository at this point in the history
  • Loading branch information
tlimoncelli committed Dec 27, 2024
1 parent 6d5bfe9 commit 8dcd0ae
Show file tree
Hide file tree
Showing 49 changed files with 1,313 additions and 1,040 deletions.
10 changes: 10 additions & 0 deletions pkg/js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"unicode"

"github.com/StackExchange/dnscontrol/v4/models"
"github.com/StackExchange/dnscontrol/v4/pkg/normalize"
"github.com/StackExchange/dnscontrol/v4/pkg/prettyzone"
"github.com/StackExchange/dnscontrol/v4/providers"
Expand Down Expand Up @@ -49,6 +50,15 @@ func TestParsedFiles(t *testing.T) {
// normalize.UpdateNameSplitHorizon(dc)
// }

for _, dc := range conf.Domains {
//fmt.Printf("DEBUG: records = %d %v\n", len(dc.Records), dc.Records)
ps := prettyzone.PrettySort(dc.Records, dc.Name, 0, nil)
dc.Records = ps.Records
if len(dc.Records) == 0 {
dc.Records = models.Records{}
}
}

// Initialize any DNS providers mentioned.
for _, dProv := range conf.DNSProviders {
var pcfg = map[string]string{}
Expand Down
52 changes: 26 additions & 26 deletions pkg/js/parse_tests/001-basic.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"registrars": [
"dns_providers": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
],
"domains": [
{
"dnsProviders": {
"Cloudflare": -1
},
"name": "foo.com",
"records": [
{
"name": "Third-Party",
"type": "NONE"
"name": "@",
"target": "1.2.3.4",
"type": "A"
}
],
"dns_providers": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
],
"domains": [
{
"name": "foo.com",
"registrar": "Third-Party",
"dnsProviders": {
"Cloudflare": -1
},
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4"
}
]
}
]
],
"registrar": "Third-Party"
}
],
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
]
}
22 changes: 11 additions & 11 deletions pkg/js/parse_tests/002-ttl.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
],
"dns_providers": [
{
"name": "Cloudflare",
Expand All @@ -13,19 +7,25 @@
],
"domains": [
{
"name": "foo.com",
"registrar": "Third-Party",
"dnsProviders": {
"Cloudflare": -1
},
"name": "foo.com",
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4",
"ttl": 42
"ttl": 42,
"type": "A"
}
]
],
"registrar": "Third-Party"
}
],
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
]
}
26 changes: 13 additions & 13 deletions pkg/js/parse_tests/003-meta.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"registrars": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
],
"dns_providers": [],
"domains": [
{
"name": "foo.com",
"registrar": "Cloudflare",
"dnsProviders": {},
"name": "foo.com",
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4",
"meta": {
"cloudflare_proxy": "ON"
}
},
"name": "@",
"target": "1.2.3.4",
"type": "A"
}
]
],
"registrar": "Cloudflare"
}
],
"registrars": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
]
}
30 changes: 15 additions & 15 deletions pkg/js/parse_tests/004-ips.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
],
"dns_providers": [
{
"name": "Cloudflare",
Expand All @@ -13,28 +7,34 @@
],
"domains": [
{
"name": "foo.com",
"registrar": "Third-Party",
"dnsProviders": {
"Cloudflare": 0
},
"name": "foo.com",
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4"
"target": "1.2.3.4",
"type": "A"
},
{
"type": "A",
"name": "p1",
"target": "1.2.3.5"
"target": "1.2.3.5",
"type": "A"
},
{
"type": "A",
"name": "p255",
"target": "1.2.4.3"
"target": "1.2.4.3",
"type": "A"
}
]
],
"registrar": "Third-Party"
}
],
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
]
}
14 changes: 7 additions & 7 deletions pkg/js/parse_tests/005-ignored-records.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"registrars": [],
"dns_providers": [],
"domains": [
{
"name": "foo.com",
"registrar": "none",
"dnsProviders": {},
"name": "foo.com",
"records": [],
"registrar": "none",
"unmanaged": [
{
"label_pattern": "testignore",
Expand Down Expand Up @@ -51,10 +50,10 @@
]
},
{
"name": "diff2.com",
"registrar": "none",
"dnsProviders": {},
"name": "diff2.com",
"records": [],
"registrar": "none",
"unmanaged": [
{
"label_pattern": "mylabel",
Expand Down Expand Up @@ -101,5 +100,6 @@
}
]
}
]
}
],
"registrars": []
}
26 changes: 13 additions & 13 deletions pkg/js/parse_tests/006-transforms.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
],
"dns_providers": [
{
"name": "Cloudflare",
Expand All @@ -13,21 +7,27 @@
],
"domains": [
{
"name": "foo.com",
"registrar": "Third-Party",
"dnsProviders": {
"Cloudflare": -1
},
"name": "foo.com",
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4",
"meta": {
"transform": "0.0.0.0 ~ 1.1.1.1 ~ 2.2.2.2 ~ ; 1.1.1.1 ~ 2.2.2.2 ~ 3.3.3.3,4.4.4.4,5.5.5.5 ~ ; 1.1.1.1 ~ 2.2.2.2 ~ ~ 3.3.3.3,4.4.4.4,5.5.5.5"
}
},
"name": "@",
"target": "1.2.3.4",
"type": "A"
}
]
],
"registrar": "Third-Party"
}
],
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
]
}
40 changes: 20 additions & 20 deletions pkg/js/parse_tests/007-importTransformTTL.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
{
"registrars": [],
"dns_providers": [],
"domains": [
{
"name": "foo1.com",
"registrar": "reg",
"dnsProviders": {},
"records": []
"name": "foo1.com",
"records": [],
"registrar": "reg"
},
{
"name": "foo2.com",
"registrar": "reg",
"dnsProviders": {},
"name": "foo2.com",
"records": [
{
"type": "IMPORT_TRANSFORM",
"name": "@",
"ttl": 60,
"meta": {
"transform_table": "0.0.0.0 ~ 1.1.1.1 ~ 4.4.4.4 ~ ; 7.7.7.7 ~ 8.8.8.8 ~ 9.9.9.9 ~ "
},
"target": "foo1.com"
"name": "@",
"target": "foo1.com",
"ttl": 60,
"type": "IMPORT_TRANSFORM"
}
]
],
"registrar": "reg"
},
{
"name": "foo3.com",
"registrar": "reg",
"dnsProviders": {},
"name": "foo3.com",
"records": [
{
"type": "IMPORT_TRANSFORM",
"name": "@",
"ttl": 99,
"meta": {
"transform_suffixstrip": ".com",
"transform_table": "0.0.0.0 ~ 1.1.1.1 ~ ~ 2.2.2.2"
},
"target": "foo1.com"
"name": "@",
"target": "foo1.com",
"ttl": 99,
"type": "IMPORT_TRANSFORM"
}
]
],
"registrar": "reg"
}
]
}
],
"registrars": []
}
14 changes: 7 additions & 7 deletions pkg/js/parse_tests/008-import.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"registrars": [],
"dns_providers": [],
"domains": [
{
"name": "foo.com",
"registrar": "none",
"dnsProviders": {},
"name": "foo.com",
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4"
"target": "1.2.3.4",
"type": "A"
}
]
],
"registrar": "none"
}
]
],
"registrars": []
}
Loading

0 comments on commit 8dcd0ae

Please sign in to comment.