Skip to content

Commit

Permalink
BlockingConfig -> Blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
kwitsch authored and ThinkChaos committed Nov 22, 2023
1 parent 00d4341 commit 9a77dcd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions config/blocking.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/sirupsen/logrus"
)

// BlockingConfig configuration for query blocking
type BlockingConfig struct {
// Blocking configuration for query blocking
type Blocking struct {
BlackLists map[string][]BytesSource `yaml:"blackLists"`
WhiteLists map[string][]BytesSource `yaml:"whiteLists"`
ClientGroupsBlock map[string][]string `yaml:"clientGroupsBlock"`
Expand All @@ -28,7 +28,7 @@ type BlockingConfig struct {
} `yaml:",inline"`
}

func (c *BlockingConfig) migrate(logger *logrus.Entry) bool {
func (c *Blocking) migrate(logger *logrus.Entry) bool {
return Migrate(logger, "blocking", c.Deprecated, map[string]Migrator{
"downloadTimeout": Move(To("loading.downloads.timeout", &c.Loading.Downloads)),
"downloadAttempts": Move(To("loading.downloads.attempts", &c.Loading.Downloads)),
Expand All @@ -46,12 +46,12 @@ func (c *BlockingConfig) migrate(logger *logrus.Entry) bool {
}

// IsEnabled implements `config.Configurable`.
func (c *BlockingConfig) IsEnabled() bool {
func (c *Blocking) IsEnabled() bool {
return len(c.ClientGroupsBlock) != 0
}

// LogConfig implements `config.Configurable`.
func (c *BlockingConfig) LogConfig(logger *logrus.Entry) {
func (c *Blocking) LogConfig(logger *logrus.Entry) {
logger.Info("clientGroupsBlock:")

for key, val := range c.ClientGroupsBlock {
Expand All @@ -78,7 +78,7 @@ func (c *BlockingConfig) LogConfig(logger *logrus.Entry) {
})
}

func (c *BlockingConfig) logListGroups(logger *logrus.Entry, listGroups map[string][]BytesSource) {
func (c *Blocking) logListGroups(logger *logrus.Entry, listGroups map[string][]BytesSource) {
for group, sources := range listGroups {
logger.Infof("%s:", group)

Expand Down
8 changes: 4 additions & 4 deletions config/blocking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
)

var _ = Describe("BlockingConfig", func() {
var cfg BlockingConfig
var cfg Blocking

suiteBeforeEach()

BeforeEach(func() {
cfg = BlockingConfig{
cfg = Blocking{
BlockType: "ZEROIP",
BlockTTL: Duration(time.Minute),
BlackLists: map[string][]BytesSource{
Expand All @@ -28,7 +28,7 @@ var _ = Describe("BlockingConfig", func() {

Describe("IsEnabled", func() {
It("should be false by default", func() {
cfg := BlockingConfig{}
cfg := Blocking{}
Expect(defaults.Set(&cfg)).Should(Succeed())

Expect(cfg.IsEnabled()).Should(BeFalse())
Expand All @@ -42,7 +42,7 @@ var _ = Describe("BlockingConfig", func() {

When("disabled", func() {
It("should be false", func() {
cfg := BlockingConfig{
cfg := Blocking{
BlockTTL: Duration(-1),
}

Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ type Config struct {
ConnectIPVersion IPVersion `yaml:"connectIPVersion"`
CustomDNS CustomDNS `yaml:"customDNS"`
Conditional ConditionalUpstream `yaml:"conditional"`
Blocking BlockingConfig `yaml:"blocking"`
Blocking Blocking `yaml:"blocking"`
ClientLookup ClientLookupConfig `yaml:"clientLookup"`
Caching CachingConfig `yaml:"caching"`
QueryLog QueryLogConfig `yaml:"queryLog"`
Expand Down
10 changes: 5 additions & 5 deletions resolver/blocking_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

const defaultBlockingCleanUpInterval = 5 * time.Second

func createBlockHandler(cfg config.BlockingConfig) (blockHandler, error) {
func createBlockHandler(cfg config.Blocking) (blockHandler, error) {
cfgBlockType := cfg.BlockType

if strings.EqualFold(cfgBlockType, "NXDOMAIN") {
Expand Down Expand Up @@ -81,7 +81,7 @@ type status struct {

// BlockingResolver checks request's question (domain name) against black and white lists
type BlockingResolver struct {
configurable[*config.BlockingConfig]
configurable[*config.Blocking]
NextResolver
typed

Expand All @@ -95,7 +95,7 @@ type BlockingResolver struct {
fqdnIPCache expirationcache.ExpiringCache[[]net.IP]
}

func clientGroupsBlock(cfg config.BlockingConfig) map[string][]string {
func clientGroupsBlock(cfg config.Blocking) map[string][]string {
cgb := make(map[string][]string, len(cfg.ClientGroupsBlock))

for identifier, cfgGroups := range cfg.ClientGroupsBlock {
Expand All @@ -114,7 +114,7 @@ func clientGroupsBlock(cfg config.BlockingConfig) map[string][]string {

// NewBlockingResolver returns a new configured instance of the resolver
func NewBlockingResolver(ctx context.Context,
cfg config.BlockingConfig,
cfg config.Blocking,
redis *redis.Client,
bootstrap *Bootstrap,
) (r *BlockingResolver, err error) {
Expand Down Expand Up @@ -307,7 +307,7 @@ func (r *BlockingResolver) BlockingStatus() api.BlockingStatus {
}

// returns groups, which have only whitelist entries
func determineWhitelistOnlyGroups(cfg *config.BlockingConfig) (result map[string]bool) {
func determineWhitelistOnlyGroups(cfg *config.Blocking) (result map[string]bool) {
result = make(map[string]bool, len(cfg.WhiteLists))

for g, links := range cfg.WhiteLists {
Expand Down
38 changes: 19 additions & 19 deletions resolver/blocking_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var _ = BeforeSuite(func() {
var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
var (
sut *BlockingResolver
sutConfig config.BlockingConfig
sutConfig config.Blocking
m *mockResolver
mockAnswer *dns.Msg
ctx context.Context
Expand All @@ -65,7 +65,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
ctx, cancelFn = context.WithCancel(context.Background())
DeferCleanup(cancelFn)

sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "ZEROIP",
BlockTTL: config.Duration(time.Minute),
}
Expand Down Expand Up @@ -102,7 +102,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

Describe("Events", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "ZEROIP",
BlockTTL: config.Duration(time.Minute),
BlackLists: map[string][]config.BytesSource{
Expand Down Expand Up @@ -130,7 +130,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

Describe("Blocking with full-qualified client name", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "ZEROIP",
BlockTTL: config.Duration(time.Minute),
BlackLists: map[string][]config.BytesSource{
Expand Down Expand Up @@ -169,7 +169,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

Describe("Blocking with fast start strategy", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "ZEROIP",
BlockTTL: config.Duration(time.Minute),
BlackLists: map[string][]config.BytesSource{
Expand Down Expand Up @@ -200,7 +200,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

Describe("Blocking requests", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockTTL: config.Duration(6 * time.Hour),
BlackLists: map[string][]config.BytesSource{
"gr1": config.NewBytesSources(group1File.Path),
Expand Down Expand Up @@ -406,7 +406,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

When("BlockType is NxDomain", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockTTL: config.Duration(time.Minute),
BlackLists: map[string][]config.BytesSource{
"defaultGroup": config.NewBytesSources(defaultGroupFile.Path),
Expand All @@ -432,7 +432,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

When("BlockTTL is set", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "ZEROIP",
BlackLists: map[string][]config.BytesSource{
"defaultGroup": config.NewBytesSources(defaultGroupFile.Path),
Expand Down Expand Up @@ -477,7 +477,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

When("BlockType is custom IP", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockTTL: config.Duration(6 * time.Hour),
BlackLists: map[string][]config.BytesSource{
"defaultGroup": config.NewBytesSources(defaultGroupFile.Path),
Expand Down Expand Up @@ -516,7 +516,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

When("BlockType is custom IP only for ipv4", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlackLists: map[string][]config.BytesSource{
"defaultGroup": config.NewBytesSources(defaultGroupFile.Path),
},
Expand Down Expand Up @@ -607,7 +607,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
Describe("Whitelisting", func() {
When("Requested domain is on black and white list", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "ZEROIP",
BlockTTL: config.Duration(time.Minute),
BlackLists: map[string][]config.BytesSource{"gr1": config.NewBytesSources(group1File.Path)},
Expand All @@ -633,7 +633,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

When("Only whitelist is defined", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "zeroIP",
BlockTTL: config.Duration(60 * time.Second),
WhiteLists: map[string][]config.BytesSource{
Expand Down Expand Up @@ -734,7 +734,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

When("IP address is on black and white list", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "ZEROIP",
BlockTTL: config.Duration(time.Minute),
BlackLists: map[string][]config.BytesSource{"gr1": config.NewBytesSources(group1File.Path)},
Expand All @@ -761,7 +761,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

Describe("Delegate request to next resolver", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "ZEROIP",
BlockTTL: config.Duration(time.Minute),
BlackLists: map[string][]config.BytesSource{"gr1": config.NewBytesSources(group1File.Path)},
Expand All @@ -787,7 +787,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
})
When("no lists defined", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "ZEROIP",
BlockTTL: config.Duration(time.Minute),
}
Expand All @@ -806,7 +806,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

Describe("Control status via API", func() {
BeforeEach(func() {
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlackLists: map[string][]config.BytesSource{
"defaultGroup": config.NewBytesSources(defaultGroupFile.Path),
"group1": config.NewBytesSources(group1File.Path),
Expand Down Expand Up @@ -1119,7 +1119,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
Describe("Create resolver with wrong parameter", func() {
When("Wrong blockType is used", func() {
It("should return error", func() {
_, err := NewBlockingResolver(ctx, config.BlockingConfig{
_, err := NewBlockingResolver(ctx, config.Blocking{
BlockType: "wrong",
}, nil, systemResolverBootstrap)

Expand All @@ -1129,7 +1129,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {
})
When("strategy is failOnError", func() {
It("should fail if lists can't be downloaded", func() {
_, err := NewBlockingResolver(ctx, config.BlockingConfig{
_, err := NewBlockingResolver(ctx, config.Blocking{
BlackLists: map[string][]config.BytesSource{"gr1": config.NewBytesSources("wrongPath")},
WhiteLists: map[string][]config.BytesSource{"whitelist": config.NewBytesSources("wrongPath")},
Loading: config.SourceLoadingConfig{Strategy: config.StartStrategyTypeFailOnError},
Expand Down Expand Up @@ -1158,7 +1158,7 @@ var _ = Describe("BlockingResolver", Label("blockingResolver"), func() {

Expect(err).Should(Succeed())
Expect(redisClient).ShouldNot(BeNil())
sutConfig = config.BlockingConfig{
sutConfig = config.Blocking{
BlockType: "ZEROIP",
BlockTTL: config.Duration(time.Minute),
}
Expand Down
4 changes: 2 additions & 2 deletions resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ var _ = Describe("Resolver", func() {
})
When("'Name' is called", func() {
It("should return resolver name", func() {
br, _ := NewBlockingResolver(ctx, config.BlockingConfig{BlockType: "zeroIP"}, nil, systemResolverBootstrap)
br, _ := NewBlockingResolver(ctx, config.Blocking{BlockType: "zeroIP"}, nil, systemResolverBootstrap)
name := Name(br)
Expect(name).Should(Equal("blocking"))
})
})
When("'Name' is called on a NamedResolver", func() {
It("should return its custom name", func() {
br, _ := NewBlockingResolver(ctx, config.BlockingConfig{BlockType: "zeroIP"}, nil, systemResolverBootstrap)
br, _ := NewBlockingResolver(ctx, config.Blocking{BlockType: "zeroIP"}, nil, systemResolverBootstrap)

cfg := config.RewriterConfig{Rewrite: map[string]string{"not": "empty"}}
r := NewRewriterResolver(cfg, br)
Expand Down
6 changes: 3 additions & 3 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var _ = BeforeSuite(func() {
},
},
},
Blocking: config.BlockingConfig{
Blocking: config.Blocking{
BlackLists: map[string][]config.BytesSource{
"ads": config.NewBytesSources(
doubleclickFile.Path,
Expand Down Expand Up @@ -622,7 +622,7 @@ var _ = Describe("Running DNS server", func() {
},
},
},
Blocking: config.BlockingConfig{BlockType: "zeroIp"},
Blocking: config.Blocking{BlockType: "zeroIp"},
Ports: config.PortsConfig{
DNS: config.ListenConfig{"127.0.0.1:" + GetStringPort(dnsBasePort2)},
},
Expand Down Expand Up @@ -668,7 +668,7 @@ var _ = Describe("Running DNS server", func() {
},
},
},
Blocking: config.BlockingConfig{BlockType: "zeroIp"},
Blocking: config.Blocking{BlockType: "zeroIp"},
Ports: config.PortsConfig{
DNS: config.ListenConfig{"127.0.0.1:" + GetStringPort(dnsBasePort2)},
},
Expand Down

0 comments on commit 9a77dcd

Please sign in to comment.