mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-12-09 13:46:07 +08:00
cleanups
This commit is contained in:
parent
f8334c2e86
commit
14c98cdda1
11 changed files with 11 additions and 201 deletions
|
|
@ -303,51 +303,3 @@ func (args *FilterArgs) flags() []cli.Flag {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
// // domainInList takes a domain and a list of domains and returns true if the
|
||||
// // domain is in the list, accounting for wildcards and tags.
|
||||
// func domainInList(domain string, list []string) bool {
|
||||
// for _, item := range list {
|
||||
// if downgradeIDNA(item) == downgradeIDNA(domain) {
|
||||
// return true
|
||||
// }
|
||||
// if strings.HasPrefix(item, "*") && strings.HasSuffix(domain, item[1:]) {
|
||||
// return true
|
||||
// }
|
||||
// filterDom, filterTag, isFilterTagged := strings.Cut(item, "!")
|
||||
// splitDom, domainTag, isDomainTagged := strings.Cut(domain, "!")
|
||||
|
||||
// splitDom = downgradeIDNA(splitDom)
|
||||
// filterDom = downgradeIDNA(filterDom)
|
||||
|
||||
// if splitDom == filterDom {
|
||||
// if isDomainTagged {
|
||||
// if filterTag == "*" {
|
||||
// return true
|
||||
// }
|
||||
// if domainTag == "" && !isFilterTagged {
|
||||
// // domain example.com! == filter example.com
|
||||
// return true
|
||||
// }
|
||||
// if isFilterTagged && domainTag == filterTag {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// if isFilterTagged {
|
||||
// if filterTag == "" && !isDomainTagged {
|
||||
// // filter example.com! == domain example.com
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
|
||||
// func downgradeIDNA(s string) string {
|
||||
// u, err := idna.ToASCII(s)
|
||||
// if err != nil {
|
||||
// return s // There was a problem. Abort and return the original.
|
||||
// }
|
||||
// return u
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -201,7 +201,6 @@ func GetZone(args GetZoneArgs) error {
|
|||
zoneRecs := make([]models.Records, len(zones))
|
||||
for i, zone := range zones {
|
||||
recs, err := provider.GetZoneRecords(zone, nil)
|
||||
fmt.Printf("DEBUG: 1 len(recs)=%d\n", len(recs))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed GetZone gzr: %w", err)
|
||||
}
|
||||
|
|
@ -284,7 +283,6 @@ func GetZone(args GetZoneArgs) error {
|
|||
}
|
||||
|
||||
case "tsv":
|
||||
fmt.Printf("DEBUG: len(recs)=%d\n", len(recs))
|
||||
for _, rec := range recs {
|
||||
cfproxy := ""
|
||||
if cp, ok := rec.Metadata["cloudflare_proxy"]; ok {
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ func TestFormatTypes(t *testing.T) {
|
|||
test_data/$DOMAIN.zone zone test_data/$DOMAIN.zone.zone
|
||||
*/
|
||||
|
||||
// for _, domain := range []string{"simple.com", "example.org", "apex.com", "ds.com"} {
|
||||
for _, domain := range []string{"simple.com"} {
|
||||
for _, domain := range []string{"simple.com", "example.org", "apex.com", "ds.com"} {
|
||||
t.Run(domain+"/js", func(t *testing.T) { testFormat(t, domain, "js") })
|
||||
t.Run(domain+"/djs", func(t *testing.T) { testFormat(t, domain, "djs") })
|
||||
t.Run(domain+"/tsv", func(t *testing.T) { testFormat(t, domain, "tsv") })
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/nozzle/throttler"
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/exp/slices"
|
||||
"golang.org/x/net/idna"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v4/models"
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/bindserial"
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/credsfile"
|
||||
|
|
@ -23,10 +28,6 @@ import (
|
|||
"github.com/StackExchange/dnscontrol/v4/pkg/rfc4183"
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/zonerecs"
|
||||
"github.com/StackExchange/dnscontrol/v4/providers"
|
||||
"github.com/nozzle/throttler"
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/exp/slices"
|
||||
"golang.org/x/net/idna"
|
||||
)
|
||||
|
||||
type cmdZoneCache struct {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ func Test_whichZonesToProcess(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, dc := range allDC {
|
||||
//dc.UpdateSplitHorizonNames()
|
||||
dc.PostProcess()
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +158,6 @@ func Test_whichZonesToProcess(t *testing.T) {
|
|||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Logf("whichZonesToProcess() %s filter=%v", tt.name, tt.args.filter)
|
||||
got := whichZonesToProcess(tt.args.dc, tt.args.filter)
|
||||
if len(got) != len(tt.want) {
|
||||
t.Errorf("whichZonesToProcess() %s: %s", tt.name, tt.why)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ func getDomainConfigWithNameservers(t *testing.T, prv providers.DNSServiceProvid
|
|||
dc := &models.DomainConfig{
|
||||
Name: domainName,
|
||||
}
|
||||
//dc.UpdateSplitHorizonNames()
|
||||
|
||||
// fix up nameservers
|
||||
ns, err := prv.GetNameservers(domainName)
|
||||
|
|
|
|||
|
|
@ -83,64 +83,11 @@ func (dc *DomainConfig) GetSplitHorizonNames() (name, uniquename, tag string) {
|
|||
}
|
||||
|
||||
// GetUniqueName returns the domain's uniquename.
|
||||
// Deprecated: dc.UniqueName directly instead.
|
||||
func (dc *DomainConfig) GetUniqueName() (uniquename string) {
|
||||
return dc.UniqueName
|
||||
}
|
||||
|
||||
// // UpdateSplitHorizonNames updates the split horizon fields
|
||||
// // (uniquename and tag) based on name.
|
||||
// func (dc *DomainConfig) UpdateSplitHorizonNames() {
|
||||
|
||||
// // Convert all domain names to punycode.
|
||||
// for _, domain := range config.Domains {
|
||||
|
||||
// // Create the .NameRaw field.
|
||||
// domain.NameRaw = domain.Name
|
||||
// idn, err := idna.ToASCII(domain.Name)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("can not convert domain %q to IDN: %w", domain.Name, err)
|
||||
// }
|
||||
// if idn != domain.NameRaw {
|
||||
// domain.Name = idn
|
||||
// }
|
||||
|
||||
// // Create the .NameUnicode field.
|
||||
// domain.NameUnicode = domain.Name
|
||||
// uni, err := idna.ToUnicode(domain.Name)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("can not convert domain %q to Unicode: %w", domain.Name, err)
|
||||
// }
|
||||
// if uni != domain.NameUnicode {
|
||||
// domain.NameUnicode = idn
|
||||
// }
|
||||
// }
|
||||
|
||||
// name, unique, tag := dc.GetSplitHorizonNames()
|
||||
|
||||
// if unique == "" {
|
||||
// unique = name
|
||||
// }
|
||||
|
||||
// if tag == "" {
|
||||
// l := strings.SplitN(name, "!", 2)
|
||||
// if len(l) == 2 {
|
||||
// name = l[0]
|
||||
// tag = l[1]
|
||||
// }
|
||||
// if tag == "" {
|
||||
// // ensure empty tagged domain is treated as untagged
|
||||
// unique = name
|
||||
// }
|
||||
// }
|
||||
|
||||
// dc.Name = name
|
||||
// if dc.Metadata == nil {
|
||||
// dc.Metadata = map[string]string{}
|
||||
// }
|
||||
// dc.Metadata[DomainUniqueName] = unique
|
||||
// dc.Metadata[DomainTag] = tag
|
||||
// }
|
||||
|
||||
// Copy returns a deep copy of the DomainConfig.
|
||||
func (dc *DomainConfig) Copy() (*DomainConfig, error) {
|
||||
newDc := &DomainConfig{}
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
package models
|
||||
|
||||
// func Test_UpdateSplitHorizonNames(t *testing.T) {
|
||||
// tests := []struct {
|
||||
// name string
|
||||
// dc *DomainConfig
|
||||
// expected *DomainConfig
|
||||
// }{
|
||||
// {
|
||||
// name: "testNoTag",
|
||||
// dc: &DomainConfig{
|
||||
// Name: "example.com",
|
||||
// },
|
||||
// expected: &DomainConfig{
|
||||
// Name: "example.com",
|
||||
// Metadata: map[string]string{
|
||||
// DomainUniqueName: "example.com",
|
||||
// DomainTag: "",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: "testEmptyTag",
|
||||
// dc: &DomainConfig{
|
||||
// Name: "example.com!",
|
||||
// },
|
||||
// expected: &DomainConfig{
|
||||
// Name: "example.com",
|
||||
// Metadata: map[string]string{
|
||||
// DomainUniqueName: "example.com",
|
||||
// DomainTag: "",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: "testWithTag",
|
||||
// dc: &DomainConfig{
|
||||
// Name: "example.com!john",
|
||||
// },
|
||||
// expected: &DomainConfig{
|
||||
// Name: "example.com",
|
||||
// Metadata: map[string]string{
|
||||
// DomainUniqueName: "example.com!john",
|
||||
// DomainTag: "john",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
|
||||
// for _, tt := range tests {
|
||||
// t.Run(tt.name, func(t *testing.T) {
|
||||
// //tt.dc.UpdateSplitHorizonNames()
|
||||
// if tt.dc.Name != tt.expected.Name {
|
||||
// t.Errorf("expected name %s, got %s", tt.expected.Name, tt.dc.Name)
|
||||
// }
|
||||
// if tt.dc.Metadata[DomainUniqueName] != tt.expected.Metadata[DomainUniqueName] {
|
||||
// t.Errorf("expected unique name %s, got %s", tt.expected.Metadata[DomainUniqueName], tt.dc.Metadata[DomainUniqueName])
|
||||
// }
|
||||
// if tt.dc.Metadata[DomainTag] != tt.expected.Metadata[DomainTag] {
|
||||
// t.Errorf("expected tag %s, got %s", tt.expected.Metadata[DomainTag], tt.dc.Metadata[DomainTag])
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
|
@ -12,11 +12,8 @@ type PermitList struct {
|
|||
|
||||
// CompilePermitList compiles a list of domain strings into a PermitList structure. The
|
||||
func CompilePermitList(s string) PermitList {
|
||||
//fmt.Printf("DEBUG: CompilePermitList(%q)\n", s)
|
||||
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" || s == "*" || strings.ToLower(s) == "all" {
|
||||
//fmt.Printf("DEBUG: CompilePermitList: ALL\n")
|
||||
return PermitList{all: true}
|
||||
}
|
||||
|
||||
|
|
@ -33,51 +30,45 @@ func CompilePermitList(s string) PermitList {
|
|||
sl.items = append(sl.items, ff)
|
||||
}
|
||||
|
||||
//fmt.Printf("DEBUG: CompilePermitList: RETURN %+v\n", sl)
|
||||
return sl
|
||||
}
|
||||
|
||||
func (pl *PermitList) Permitted(domToCheck string) bool {
|
||||
//fmt.Printf("DEBUG: Permitted(%q)\n", domToCheck)
|
||||
|
||||
// If the permit list is "all", everything is permitted.
|
||||
if pl.all {
|
||||
//fmt.Printf("DEBUG: Permitted RETURN true\n")
|
||||
return true
|
||||
}
|
||||
|
||||
domToCheckFF := MakeDomainFixForms(domToCheck)
|
||||
// fmt.Printf("DEBUG: input: %+v\n", domToCheckFF)
|
||||
|
||||
for _, filterItem := range pl.items {
|
||||
// fmt.Printf("DEBUG: Checking item %+v\n", filterItem)
|
||||
|
||||
// Special case: filter=example.com!* does not match example.com (no tag)
|
||||
if filterItem.Tag == "*" && !domToCheckFF.HasBang {
|
||||
// fmt.Printf("DEBUG: Skipping due to no tag present\n")
|
||||
continue
|
||||
}
|
||||
// Special case: filter=example.com!* does not match example.com! (empty tag)
|
||||
if filterItem.Tag == "*" && domToCheckFF.HasBang && domToCheckFF.Tag == "" {
|
||||
// fmt.Printf("DEBUG: Skipping due to empty tag present\n")
|
||||
continue
|
||||
}
|
||||
// Special case: filter=example.com! does not match example.com!tag
|
||||
if filterItem.HasBang && filterItem.Tag == "" && domToCheckFF.HasBang && domToCheckFF.Tag != "" {
|
||||
// fmt.Printf("DEBUG: Skipping due to non-empty tag present\n")
|
||||
continue
|
||||
}
|
||||
|
||||
// Skip if the tag doesn't match
|
||||
// Skip if tags don't match
|
||||
if (filterItem.Tag != "*") && (domToCheckFF.Tag != filterItem.Tag) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Now that we know the tag matches, we can focus on the name.
|
||||
|
||||
// `*!tag` or `*` matches everything.
|
||||
if filterItem.NameIDN == "*" {
|
||||
// `*!tag` or `*` matches everything.
|
||||
return true
|
||||
}
|
||||
|
||||
// If the name starts with "*." then match the suffix.
|
||||
if strings.HasPrefix(filterItem.NameIDN, "*.") {
|
||||
// example.com matches *.example.com
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import (
|
|||
|
||||
const (
|
||||
testDir = "pkg/js/parse_tests"
|
||||
//errorDir = "pkg/js/error_tests"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -49,9 +48,6 @@ func TestParsedFiles(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// for _, dc := range conf.Domains {
|
||||
// dc.UpdateSplitHorizonNames()
|
||||
// }
|
||||
|
||||
errs := normalize.ValidateAndNormalizeConfig(conf)
|
||||
if len(errs) != 0 {
|
||||
|
|
@ -115,7 +111,6 @@ func TestParsedFiles(t *testing.T) {
|
|||
var dCount int
|
||||
for _, dc := range conf.Domains {
|
||||
var zoneFile string
|
||||
// dc.UpdateSplitHorizonNames()
|
||||
if dc.Tag != "" {
|
||||
zoneFile = filepath.Join(testDir, testName, dc.GetUniqueName()+".zone")
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -353,7 +353,6 @@ type Warning struct {
|
|||
|
||||
// ValidateAndNormalizeConfig performs and normalization and/or validation of the IR.
|
||||
func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
|
||||
|
||||
err := processSplitHorizonDomains(config)
|
||||
if err != nil {
|
||||
return []error{err}
|
||||
|
|
@ -586,11 +585,6 @@ func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
|
|||
// processSplitHorizonDomains finds "domain.tld!tag" domains and pre-processes them.
|
||||
func processSplitHorizonDomains(config *models.DNSConfig) error {
|
||||
|
||||
// // Parse out names and tags.
|
||||
// for _, d := range config.Domains {
|
||||
// d.UpdateSplitHorizonNames()
|
||||
// }
|
||||
|
||||
// Verify uniquenames are unique
|
||||
seen := map[string]bool{}
|
||||
for _, d := range config.Domains {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue