From 9a77dcdccc6ef5051776d76d4ad4e9707a8acfab Mon Sep 17 00:00:00 2001 From: Kwitsch Date: Tue, 21 Nov 2023 21:27:51 +0000 Subject: [PATCH] BlockingConfig -> Blocking --- config/blocking.go | 12 +++++----- config/blocking_test.go | 8 +++---- config/config.go | 2 +- resolver/blocking_resolver.go | 10 ++++---- resolver/blocking_resolver_test.go | 38 +++++++++++++++--------------- resolver/resolver_test.go | 4 ++-- server/server_test.go | 6 ++--- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/config/blocking.go b/config/blocking.go index 364d8dfc0..4d95402b8 100644 --- a/config/blocking.go +++ b/config/blocking.go @@ -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"` @@ -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)), @@ -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 { @@ -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) diff --git a/config/blocking_test.go b/config/blocking_test.go index 17b1a6ff1..9c84a9bf7 100644 --- a/config/blocking_test.go +++ b/config/blocking_test.go @@ -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{ @@ -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()) @@ -42,7 +42,7 @@ var _ = Describe("BlockingConfig", func() { When("disabled", func() { It("should be false", func() { - cfg := BlockingConfig{ + cfg := Blocking{ BlockTTL: Duration(-1), } diff --git a/config/config.go b/config/config.go index ba413f321..b162d59d5 100644 --- a/config/config.go +++ b/config/config.go @@ -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"` diff --git a/resolver/blocking_resolver.go b/resolver/blocking_resolver.go index cb1c1cc59..290a0cefc 100644 --- a/resolver/blocking_resolver.go +++ b/resolver/blocking_resolver.go @@ -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") { @@ -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 @@ -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 { @@ -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) { @@ -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 { diff --git a/resolver/blocking_resolver_test.go b/resolver/blocking_resolver_test.go index e55b7419e..6d40f7b1e 100644 --- a/resolver/blocking_resolver_test.go +++ b/resolver/blocking_resolver_test.go @@ -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 @@ -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), } @@ -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{ @@ -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{ @@ -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{ @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), }, @@ -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)}, @@ -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{ @@ -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)}, @@ -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)}, @@ -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), } @@ -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), @@ -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) @@ -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}, @@ -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), } diff --git a/resolver/resolver_test.go b/resolver/resolver_test.go index 5e703a665..840435a87 100644 --- a/resolver/resolver_test.go +++ b/resolver/resolver_test.go @@ -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) diff --git a/server/server_test.go b/server/server_test.go index 8481575cb..ac58b0e9e 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -135,7 +135,7 @@ var _ = BeforeSuite(func() { }, }, }, - Blocking: config.BlockingConfig{ + Blocking: config.Blocking{ BlackLists: map[string][]config.BytesSource{ "ads": config.NewBytesSources( doubleclickFile.Path, @@ -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)}, }, @@ -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)}, },