1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Domains flag should accept simple wildcards (#1983)

This commit is contained in:
Tom Limoncelli
2023-01-25 12:17:21 -05:00
committed by GitHub
parent cb88bdd068
commit 4c3583cd5a
3 changed files with 73 additions and 3 deletions

View File

@ -294,8 +294,15 @@ func (args *FilterArgs) shouldRunDomain(d string) bool {
if args.Domains == "" { if args.Domains == "" {
return true return true
} }
for _, dom := range strings.Split(args.Domains, ",") { return domainInList(d, strings.Split(args.Domains, ","))
if dom == d { }
func domainInList(domain string, list []string) bool {
for _, item := range list {
if strings.HasPrefix(item, "*") && strings.HasSuffix(domain, item[1:]) {
return true
}
if item == domain {
return true return true
} }
} }

63
commands/commands_test.go Normal file
View File

@ -0,0 +1,63 @@
package commands
import "testing"
func Test_domainInList(t *testing.T) {
type args struct {
domain string
list []string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "small",
args: args{
domain: "foo.com",
list: []string{"foo.com"},
},
want: true,
},
{
name: "big",
args: args{
domain: "foo.com",
list: []string{"example.com", "foo.com", "baz.com"},
},
want: true,
},
{
name: "missing",
args: args{
domain: "foo.com",
list: []string{"bar.com"},
},
want: false,
},
{
name: "wildcard",
args: args{
domain: "*.10.in-addr.arpa",
list: []string{"bar.com", "10.in-addr.arpa", "example.com"},
},
want: false,
},
{
name: "wildcardmissing",
args: args{
domain: "*.10.in-addr.arpa",
list: []string{"bar.com", "6.in-addr.arpa", "example.com"},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := domainInList(tt.args.domain, tt.args.list); got != tt.want {
t.Errorf("domainInList() = %v, want %v", got, tt.want)
}
})
}
}

View File

@ -85,7 +85,7 @@ and `domain.tld!external` you now require humans to remember that
may have noticed this mistake, but will your coworkers? Will you in may have noticed this mistake, but will your coworkers? Will you in
six months? You get the idea. six months? You get the idea.
DNSControl command line flag `--domains` is an exact match. If you DNSControl command line flag `--domains` matches the full name (with the "!"). If you
define domains `example.com!george` and `example.com!john` then: define domains `example.com!george` and `example.com!john` then:
* `--domains=example.com` will not match either domain. * `--domains=example.com` will not match either domain.