Skip to content

Commit

Permalink
CustomDNSConfig -> CustomDNS
Browse files Browse the repository at this point in the history
  • Loading branch information
kwitsch authored and ThinkChaos committed Nov 22, 2023
1 parent 72352a9 commit 26d5f62
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Expand Up @@ -191,7 +191,7 @@ func (b *BootstrappedUpstreamConfig) UnmarshalYAML(unmarshal func(interface{}) e
type Config struct {
Upstreams Upstreams `yaml:"upstreams"`
ConnectIPVersion IPVersion `yaml:"connectIPVersion"`
CustomDNS CustomDNSConfig `yaml:"customDNS"`
CustomDNS CustomDNS `yaml:"customDNS"`
Conditional ConditionalUpstreamConfig `yaml:"conditional"`
Blocking BlockingConfig `yaml:"blocking"`
ClientLookup ClientLookupConfig `yaml:"clientLookup"`
Expand Down
8 changes: 4 additions & 4 deletions config/custom_dns.go
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/sirupsen/logrus"
)

// CustomDNSConfig custom DNS configuration
type CustomDNSConfig struct {
// CustomDNS custom DNS configuration
type CustomDNS struct {
RewriterConfig `yaml:",inline"`
CustomTTL Duration `yaml:"customTTL" default:"1h"`
Mapping CustomDNSMapping `yaml:"mapping"`
Expand All @@ -22,12 +22,12 @@ type CustomDNSMapping struct {
}

// IsEnabled implements `config.Configurable`.
func (c *CustomDNSConfig) IsEnabled() bool {
func (c *CustomDNS) IsEnabled() bool {
return len(c.Mapping.HostIPs) != 0
}

// LogConfig implements `config.Configurable`.
func (c *CustomDNSConfig) LogConfig(logger *logrus.Entry) {
func (c *CustomDNS) LogConfig(logger *logrus.Entry) {
logger.Debugf("TTL = %s", c.CustomTTL)
logger.Debugf("filterUnmappedTypes = %t", c.FilterUnmappedTypes)

Expand Down
8 changes: 4 additions & 4 deletions config/custom_dns_test.go
Expand Up @@ -10,12 +10,12 @@ import (
)

var _ = Describe("CustomDNSConfig", func() {
var cfg CustomDNSConfig
var cfg CustomDNS

suiteBeforeEach()

BeforeEach(func() {
cfg = CustomDNSConfig{
cfg = CustomDNS{
Mapping: CustomDNSMapping{
HostIPs: map[string][]net.IP{
"custom.domain": {net.ParseIP("192.168.143.123")},
Expand All @@ -32,7 +32,7 @@ var _ = Describe("CustomDNSConfig", func() {

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

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

When("disabled", func() {
It("should be false", func() {
cfg := CustomDNSConfig{}
cfg := CustomDNS{}

Expect(cfg.IsEnabled()).Should(BeFalse())
})
Expand Down
4 changes: 2 additions & 2 deletions resolver/custom_dns_resolver.go
Expand Up @@ -16,7 +16,7 @@ import (

// CustomDNSResolver resolves passed domain name to ip address defined in domain-IP map
type CustomDNSResolver struct {
configurable[*config.CustomDNSConfig]
configurable[*config.CustomDNS]
NextResolver
typed

Expand All @@ -25,7 +25,7 @@ type CustomDNSResolver struct {
}

// NewCustomDNSResolver creates new resolver instance
func NewCustomDNSResolver(cfg config.CustomDNSConfig) *CustomDNSResolver {
func NewCustomDNSResolver(cfg config.CustomDNS) *CustomDNSResolver {
m := make(map[string][]net.IP, len(cfg.Mapping.HostIPs))
reverse := make(map[string][]string, len(cfg.Mapping.HostIPs))

Expand Down
4 changes: 2 additions & 2 deletions resolver/custom_dns_resolver_test.go
Expand Up @@ -21,7 +21,7 @@ var _ = Describe("CustomDNSResolver", func() {

sut *CustomDNSResolver
m *mockResolver
cfg config.CustomDNSConfig
cfg config.CustomDNS

ctx context.Context
cancelFn context.CancelFunc
Expand All @@ -37,7 +37,7 @@ var _ = Describe("CustomDNSResolver", func() {
ctx, cancelFn = context.WithCancel(context.Background())
DeferCleanup(cancelFn)

cfg = config.CustomDNSConfig{
cfg = config.CustomDNS{
Mapping: config.CustomDNSMapping{HostIPs: map[string][]net.IP{
"custom.domain": {net.ParseIP("192.168.143.123")},
"ip6.domain": {net.ParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334")},
Expand Down
6 changes: 3 additions & 3 deletions server/server_test.go
Expand Up @@ -118,7 +118,7 @@ var _ = BeforeSuite(func() {
Expect(youtubeFile.Error).Should(Succeed())

cfg := &config.Config{
CustomDNS: config.CustomDNSConfig{
CustomDNS: config.CustomDNS{
CustomTTL: config.Duration(3600 * time.Second),
Mapping: config.CustomDNSMapping{
HostIPs: map[string][]net.IP{
Expand Down Expand Up @@ -614,7 +614,7 @@ var _ = Describe("Running DNS server", func() {
"default": {config.Upstream{Net: config.NetProtocolTcpUdp, Host: "4.4.4.4", Port: 53}},
},
},
CustomDNS: config.CustomDNSConfig{
CustomDNS: config.CustomDNS{
Mapping: config.CustomDNSMapping{
HostIPs: map[string][]net.IP{
"custom.lan": {net.ParseIP("192.168.178.55")},
Expand Down Expand Up @@ -660,7 +660,7 @@ var _ = Describe("Running DNS server", func() {
"default": {config.Upstream{Net: config.NetProtocolTcpUdp, Host: "4.4.4.4", Port: 53}},
},
},
CustomDNS: config.CustomDNSConfig{
CustomDNS: config.CustomDNS{
Mapping: config.CustomDNSMapping{
HostIPs: map[string][]net.IP{
"custom.lan": {net.ParseIP("192.168.178.55")},
Expand Down

0 comments on commit 26d5f62

Please sign in to comment.