Skip to content

Commit

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

// ClientLookupConfig configuration for the client lookup
type ClientLookupConfig struct {
// ClientLookup configuration for the client lookup
type ClientLookup struct {
ClientnameIPMapping map[string][]net.IP `yaml:"clients"`
Upstream Upstream `yaml:"upstream"`
SingleNameOrder []uint `yaml:"singleNameOrder"`
}

// IsEnabled implements `config.Configurable`.
func (c *ClientLookupConfig) IsEnabled() bool {
func (c *ClientLookup) IsEnabled() bool {
return !c.Upstream.IsDefault() || len(c.ClientnameIPMapping) != 0
}

// LogConfig implements `config.Configurable`.
func (c *ClientLookupConfig) LogConfig(logger *logrus.Entry) {
func (c *ClientLookup) LogConfig(logger *logrus.Entry) {
if !c.Upstream.IsDefault() {
logger.Infof("upstream = %s", c.Upstream)
}
Expand Down
10 changes: 5 additions & 5 deletions config/client_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
)

var _ = Describe("ClientLookupConfig", func() {
var cfg ClientLookupConfig
var cfg ClientLookup

suiteBeforeEach()

BeforeEach(func() {
cfg = ClientLookupConfig{
cfg = ClientLookup{
Upstream: Upstream{Net: NetProtocolTcpUdp, Host: "host"},
SingleNameOrder: []uint{1, 2},
ClientnameIPMapping: map[string][]net.IP{
Expand All @@ -25,7 +25,7 @@ var _ = Describe("ClientLookupConfig", func() {

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

Expect(cfg.IsEnabled()).Should(BeFalse())
Expand All @@ -34,7 +34,7 @@ var _ = Describe("ClientLookupConfig", func() {
When("enabled", func() {
It("should be true", func() {
By("upstream", func() {
cfg := ClientLookupConfig{
cfg := ClientLookup{
Upstream: Upstream{Net: NetProtocolTcpUdp, Host: "host"},
ClientnameIPMapping: nil,
}
Expand All @@ -43,7 +43,7 @@ var _ = Describe("ClientLookupConfig", func() {
})

By("mapping", func() {
cfg := ClientLookupConfig{
cfg := ClientLookup{
ClientnameIPMapping: map[string][]net.IP{
"client8": {net.ParseIP("1.2.3.5")},
},
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ type Config struct {
CustomDNS CustomDNS `yaml:"customDNS"`
Conditional ConditionalUpstream `yaml:"conditional"`
Blocking Blocking `yaml:"blocking"`
ClientLookup ClientLookupConfig `yaml:"clientLookup"`
ClientLookup ClientLookup `yaml:"clientLookup"`
Caching CachingConfig `yaml:"caching"`
QueryLog QueryLogConfig `yaml:"queryLog"`
Prometheus MetricsConfig `yaml:"prometheus"`
Expand Down
4 changes: 2 additions & 2 deletions resolver/client_names_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// ClientNamesResolver tries to determine client name by asking responsible DNS server via rDNS (reverse lookup)
type ClientNamesResolver struct {
configurable[*config.ClientLookupConfig]
configurable[*config.ClientLookup]
NextResolver
typed

Expand All @@ -28,7 +28,7 @@ type ClientNamesResolver struct {

// NewClientNamesResolver creates new resolver instance
func NewClientNamesResolver(ctx context.Context,
cfg config.ClientLookupConfig, bootstrap *Bootstrap, shouldVerifyUpstreams bool,
cfg config.ClientLookup, bootstrap *Bootstrap, shouldVerifyUpstreams bool,
) (cr *ClientNamesResolver, err error) {
var r Resolver
if !cfg.Upstream.IsDefault() {
Expand Down
22 changes: 11 additions & 11 deletions resolver/client_names_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {
var (
sut *ClientNamesResolver
sutConfig config.ClientLookupConfig
sutConfig config.ClientLookup
m *mockResolver

ctx context.Context
Expand Down Expand Up @@ -64,7 +64,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {

Describe("Resolve client name from request clientID", func() {
BeforeEach(func() {
sutConfig = config.ClientLookupConfig{}
sutConfig = config.ClientLookup{}
})
AfterEach(func() {
// next resolver will be called
Expand Down Expand Up @@ -96,7 +96,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {
})
Describe("Resolve client name with custom name mapping", Label("XXX"), func() {
BeforeEach(func() {
sutConfig = config.ClientLookupConfig{
sutConfig = config.ClientLookup{
ClientnameIPMapping: map[string][]net.IP{
"client7": {
net.ParseIP("1.2.3.4"), net.ParseIP("1.2.3.5"), net.ParseIP("2a02:590:505:4700:2e4f:1503:ce74:df78"),
Expand Down Expand Up @@ -162,7 +162,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {
testUpstream = NewMockUDPUpstreamServer().
WithAnswerRR("25.178.168.192.in-addr.arpa. 600 IN PTR host1")
DeferCleanup(testUpstream.Close)
sutConfig = config.ClientLookupConfig{
sutConfig = config.ClientLookup{
Upstream: testUpstream.Start(),
}
})
Expand Down Expand Up @@ -218,7 +218,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {
testUpstream = NewMockUDPUpstreamServer().
WithAnswerRR("25.178.168.192.in-addr.arpa. 600 IN PTR myhost1", "25.178.168.192.in-addr.arpa. 600 IN PTR myhost2")
DeferCleanup(testUpstream.Close)
sutConfig = config.ClientLookupConfig{
sutConfig = config.ClientLookup{
Upstream: testUpstream.Start(),
}
})
Expand All @@ -239,7 +239,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {
})
Context("with order", func() {
BeforeEach(func() {
sutConfig = config.ClientLookupConfig{
sutConfig = config.ClientLookup{
SingleNameOrder: []uint{2, 1},
}
})
Expand Down Expand Up @@ -293,7 +293,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {
testUpstream = NewMockUDPUpstreamServer().
WithAnswerError(dns.RcodeNameError)
DeferCleanup(testUpstream.Close)
sutConfig = config.ClientLookupConfig{
sutConfig = config.ClientLookup{
Upstream: testUpstream.Start(),
}
})
Expand All @@ -313,7 +313,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {
})
When("Upstream produces error", func() {
JustBeforeEach(func() {
sutConfig = config.ClientLookupConfig{}
sutConfig = config.ClientLookup{}
clientMockResolver := &mockResolver{}
clientMockResolver.On("Resolve", mock.Anything).Return(nil, errors.New("error"))
sut.externalResolver = clientMockResolver
Expand All @@ -333,7 +333,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {

When("Client has no IP", func() {
BeforeEach(func() {
sutConfig = config.ClientLookupConfig{}
sutConfig = config.ClientLookup{}
})
It("should resolve no names", func() {
request := newRequestWithClient("google.de.", dns.Type(dns.TypeA), "")
Expand All @@ -349,7 +349,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {

When("No upstream is defined", func() {
BeforeEach(func() {
sutConfig = config.ClientLookupConfig{}
sutConfig = config.ClientLookup{}
})
It("should use fallback for client name", func() {
request := newRequestWithClient("google.de.", dns.Type(dns.TypeA), "192.168.178.25")
Expand All @@ -370,7 +370,7 @@ var _ = Describe("ClientResolver", Label("clientNamesResolver"), func() {
It("errors during construction", func() {
b := newTestBootstrap(ctx, &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeServerFailure}})

r, err := NewClientNamesResolver(ctx, config.ClientLookupConfig{
r, err := NewClientNamesResolver(ctx, config.ClientLookup{
Upstream: config.Upstream{Host: "example.com"},
}, b, true)

Expand Down
2 changes: 1 addition & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ var _ = BeforeSuite(func() {
Timeout: config.Duration(250 * time.Millisecond),
Groups: map[string][]config.Upstream{"default": {upstreamGoogle}},
},
ClientLookup: config.ClientLookupConfig{
ClientLookup: config.ClientLookup{
Upstream: upstreamClient,
},

Expand Down

0 comments on commit e30e852

Please sign in to comment.