ConditionalUpstreamConfig -> ConditionalUpstream

This commit is contained in:
Kwitsch 2023-11-21 21:25:01 +00:00 committed by ThinkChaos
parent 26d5f6215f
commit 00d4341271
6 changed files with 37 additions and 37 deletions

View File

@ -7,8 +7,8 @@ import (
"github.com/sirupsen/logrus"
)
// ConditionalUpstreamConfig conditional upstream configuration
type ConditionalUpstreamConfig struct {
// ConditionalUpstream conditional upstream configuration
type ConditionalUpstream struct {
RewriterConfig `yaml:",inline"`
Mapping ConditionalUpstreamMapping `yaml:"mapping"`
}
@ -19,12 +19,12 @@ type ConditionalUpstreamMapping struct {
}
// IsEnabled implements `config.Configurable`.
func (c *ConditionalUpstreamConfig) IsEnabled() bool {
func (c *ConditionalUpstream) IsEnabled() bool {
return len(c.Mapping.Upstreams) != 0
}
// LogConfig implements `config.Configurable`.
func (c *ConditionalUpstreamConfig) LogConfig(logger *logrus.Entry) {
func (c *ConditionalUpstream) LogConfig(logger *logrus.Entry) {
for key, val := range c.Mapping.Upstreams {
logger.Infof("%s = %v", key, val)
}

View File

@ -9,12 +9,12 @@ import (
)
var _ = Describe("ConditionalUpstreamConfig", func() {
var cfg ConditionalUpstreamConfig
var cfg ConditionalUpstream
suiteBeforeEach()
BeforeEach(func() {
cfg = ConditionalUpstreamConfig{
cfg = ConditionalUpstream{
Mapping: ConditionalUpstreamMapping{
Upstreams: map[string][]Upstream{
"fritz.box": {Upstream{Net: NetProtocolTcpUdp, Host: "fbTest"}},
@ -27,7 +27,7 @@ var _ = Describe("ConditionalUpstreamConfig", func() {
Describe("IsEnabled", func() {
It("should be false by default", func() {
cfg := ConditionalUpstreamConfig{}
cfg := ConditionalUpstream{}
Expect(defaults.Set(&cfg)).Should(Succeed())
Expect(cfg.IsEnabled()).Should(BeFalse())
@ -41,7 +41,7 @@ var _ = Describe("ConditionalUpstreamConfig", func() {
When("disabled", func() {
It("should be false", func() {
cfg := ConditionalUpstreamConfig{
cfg := ConditionalUpstream{
Mapping: ConditionalUpstreamMapping{Upstreams: map[string][]Upstream{}},
}

View File

@ -189,30 +189,30 @@ func (b *BootstrappedUpstreamConfig) UnmarshalYAML(unmarshal func(interface{}) e
//
//nolint:maligned
type Config struct {
Upstreams Upstreams `yaml:"upstreams"`
ConnectIPVersion IPVersion `yaml:"connectIPVersion"`
CustomDNS CustomDNS `yaml:"customDNS"`
Conditional ConditionalUpstreamConfig `yaml:"conditional"`
Blocking BlockingConfig `yaml:"blocking"`
ClientLookup ClientLookupConfig `yaml:"clientLookup"`
Caching CachingConfig `yaml:"caching"`
QueryLog QueryLogConfig `yaml:"queryLog"`
Prometheus MetricsConfig `yaml:"prometheus"`
Redis RedisConfig `yaml:"redis"`
Log log.Config `yaml:"log"`
Ports PortsConfig `yaml:"ports"`
DoHUserAgent string `yaml:"dohUserAgent"`
MinTLSServeVer string `yaml:"minTlsServeVersion" default:"1.2"`
StartVerifyUpstream bool `yaml:"startVerifyUpstream" default:"false"`
CertFile string `yaml:"certFile"`
KeyFile string `yaml:"keyFile"`
BootstrapDNS BootstrapDNSConfig `yaml:"bootstrapDns"`
HostsFile HostsFileConfig `yaml:"hostsFile"`
FQDNOnly FQDNOnly `yaml:"fqdnOnly"`
Filtering FilteringConfig `yaml:"filtering"`
EDE EDE `yaml:"ede"`
ECS ECS `yaml:"ecs"`
SUDN SUDN `yaml:"specialUseDomains"`
Upstreams Upstreams `yaml:"upstreams"`
ConnectIPVersion IPVersion `yaml:"connectIPVersion"`
CustomDNS CustomDNS `yaml:"customDNS"`
Conditional ConditionalUpstream `yaml:"conditional"`
Blocking BlockingConfig `yaml:"blocking"`
ClientLookup ClientLookupConfig `yaml:"clientLookup"`
Caching CachingConfig `yaml:"caching"`
QueryLog QueryLogConfig `yaml:"queryLog"`
Prometheus MetricsConfig `yaml:"prometheus"`
Redis RedisConfig `yaml:"redis"`
Log log.Config `yaml:"log"`
Ports PortsConfig `yaml:"ports"`
DoHUserAgent string `yaml:"dohUserAgent"`
MinTLSServeVer string `yaml:"minTlsServeVersion" default:"1.2"`
StartVerifyUpstream bool `yaml:"startVerifyUpstream" default:"false"`
CertFile string `yaml:"certFile"`
KeyFile string `yaml:"keyFile"`
BootstrapDNS BootstrapDNSConfig `yaml:"bootstrapDns"`
HostsFile HostsFileConfig `yaml:"hostsFile"`
FQDNOnly FQDNOnly `yaml:"fqdnOnly"`
Filtering FilteringConfig `yaml:"filtering"`
EDE EDE `yaml:"ede"`
ECS ECS `yaml:"ecs"`
SUDN SUDN `yaml:"specialUseDomains"`
// Deprecated options
Deprecated struct {

View File

@ -15,7 +15,7 @@ import (
// ConditionalUpstreamResolver delegates DNS question to other DNS resolver dependent on domain name in question
type ConditionalUpstreamResolver struct {
configurable[*config.ConditionalUpstreamConfig]
configurable[*config.ConditionalUpstream]
NextResolver
typed
@ -24,7 +24,7 @@ type ConditionalUpstreamResolver struct {
// NewConditionalUpstreamResolver returns new resolver instance
func NewConditionalUpstreamResolver(
ctx context.Context, cfg config.ConditionalUpstreamConfig, bootstrap *Bootstrap, shouldVerifyUpstreams bool,
ctx context.Context, cfg config.ConditionalUpstream, bootstrap *Bootstrap, shouldVerifyUpstreams bool,
) (*ConditionalUpstreamResolver, error) {
m := make(map[string]Resolver, len(cfg.Mapping.Upstreams))

View File

@ -65,7 +65,7 @@ var _ = Describe("ConditionalUpstreamResolver", Label("conditionalResolver"), fu
})
DeferCleanup(refuseTestUpstream.Close)
sut, _ = NewConditionalUpstreamResolver(ctx, config.ConditionalUpstreamConfig{
sut, _ = NewConditionalUpstreamResolver(ctx, config.ConditionalUpstream{
Mapping: config.ConditionalUpstreamMapping{
Upstreams: map[string][]config.Upstream{
"fritz.box": {fbTestUpstream.Start()},
@ -194,7 +194,7 @@ var _ = Describe("ConditionalUpstreamResolver", Label("conditionalResolver"), fu
It("errors during construction", func() {
b := newTestBootstrap(ctx, &dns.Msg{MsgHdr: dns.MsgHdr{Rcode: dns.RcodeServerFailure}})
r, err := NewConditionalUpstreamResolver(ctx, config.ConditionalUpstreamConfig{
r, err := NewConditionalUpstreamResolver(ctx, config.ConditionalUpstream{
Mapping: config.ConditionalUpstreamMapping{
Upstreams: map[string][]config.Upstream{
".": {config.Upstream{Host: "example.com"}},

View File

@ -127,7 +127,7 @@ var _ = BeforeSuite(func() {
},
},
},
Conditional: config.ConditionalUpstreamConfig{
Conditional: config.ConditionalUpstream{
Mapping: config.ConditionalUpstreamMapping{
Upstreams: map[string][]config.Upstream{
"net.cn": {upstreamClient},