ClientLookupConfig -> ClientLookup

This commit is contained in:
Kwitsch 2023-11-21 22:19:19 +00:00 committed by ThinkChaos
parent 9a77dcdccc
commit e30e852c86
6 changed files with 24 additions and 24 deletions

View File

@ -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)
}

View File

@ -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{
@ -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())
@ -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,
}
@ -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")},
},

View File

@ -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"`

View File

@ -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
@ -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() {

View File

@ -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
@ -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
@ -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"),
@ -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(),
}
})
@ -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(),
}
})
@ -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},
}
})
@ -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(),
}
})
@ -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
@ -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), "")
@ -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")
@ -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)

View File

@ -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,
},