HostsFileConfig -> HostsFile

This commit is contained in:
Kwitsch 2023-12-20 17:37:02 +00:00
parent e3fcf79aa2
commit f38f59cca6
5 changed files with 15 additions and 15 deletions

View File

@ -228,7 +228,7 @@ type Config struct {
CertFile string `yaml:"certFile"`
KeyFile string `yaml:"keyFile"`
BootstrapDNS BootstrapDNSConfig `yaml:"bootstrapDns"`
HostsFile HostsFileConfig `yaml:"hostsFile"`
HostsFile HostsFile `yaml:"hostsFile"`
FQDNOnly FQDNOnly `yaml:"fqdnOnly"`
Filtering Filtering `yaml:"filtering"`
EDE EDE `yaml:"ede"`

View File

@ -6,7 +6,7 @@ import (
"github.com/sirupsen/logrus"
)
type HostsFileConfig struct {
type HostsFile struct {
Sources []BytesSource `yaml:"sources"`
HostsTTL Duration `yaml:"hostsTTL" default:"1h"`
FilterLoopback bool `yaml:"filterLoopback"`
@ -19,7 +19,7 @@ type HostsFileConfig struct {
} `yaml:",inline"`
}
func (c *HostsFileConfig) migrate(logger *logrus.Entry) bool {
func (c *HostsFile) migrate(logger *logrus.Entry) bool {
return Migrate(logger, "hostsFile", c.Deprecated, map[string]Migrator{
"refreshPeriod": Move(To("loading.refreshPeriod", &c.Loading)),
"filePath": Apply(To("sources", c), func(value BytesSource) {
@ -29,12 +29,12 @@ func (c *HostsFileConfig) migrate(logger *logrus.Entry) bool {
}
// IsEnabled implements `config.Configurable`.
func (c *HostsFileConfig) IsEnabled() bool {
func (c *HostsFile) IsEnabled() bool {
return len(c.Sources) != 0
}
// LogConfig implements `config.Configurable`.
func (c *HostsFileConfig) LogConfig(logger *logrus.Entry) {
func (c *HostsFile) LogConfig(logger *logrus.Entry) {
logger.Infof("TTL: %s", c.HostsTTL)
logger.Infof("filter loopback addresses: %t", c.FilterLoopback)

View File

@ -9,12 +9,12 @@ import (
)
var _ = Describe("HostsFileConfig", func() {
var cfg HostsFileConfig
var cfg HostsFile
suiteBeforeEach()
BeforeEach(func() {
cfg = HostsFileConfig{
cfg = HostsFile{
Sources: append(
NewBytesSources("/a/file/path"),
TextBytesSource("127.0.0.1 localhost"),
@ -27,7 +27,7 @@ var _ = Describe("HostsFileConfig", func() {
Describe("IsEnabled", func() {
It("should be false by default", func() {
cfg := HostsFileConfig{}
cfg := HostsFile{}
Expect(defaults.Set(&cfg)).Should(Succeed())
Expect(cfg.IsEnabled()).Should(BeFalse())
@ -41,7 +41,7 @@ var _ = Describe("HostsFileConfig", func() {
When("disabled", func() {
It("should be false", func() {
cfg := HostsFileConfig{}
cfg := HostsFile{}
Expect(cfg.IsEnabled()).Should(BeFalse())
})
@ -62,7 +62,7 @@ var _ = Describe("HostsFileConfig", func() {
Describe("migrate", func() {
It("should", func() {
cfg, err := WithDefaults[HostsFileConfig]()
cfg, err := WithDefaults[HostsFile]()
Expect(err).Should(Succeed())
cfg.Deprecated.Filepath = ptrOf(newBytesSource("/a/file/path"))

View File

@ -26,7 +26,7 @@ const (
type HostsFileEntry = parsers.HostsFileEntry
type HostsFileResolver struct {
configurable[*config.HostsFileConfig]
configurable[*config.HostsFile]
NextResolver
typed
@ -35,7 +35,7 @@ type HostsFileResolver struct {
}
func NewHostsFileResolver(ctx context.Context,
cfg config.HostsFileConfig,
cfg config.HostsFile,
bootstrap *Bootstrap,
) (*HostsFileResolver, error) {
r := HostsFileResolver{

View File

@ -19,7 +19,7 @@ var _ = Describe("HostsFileResolver", func() {
TTL = uint32(time.Now().Second())
sut *HostsFileResolver
sutConfig config.HostsFileConfig
sutConfig config.HostsFile
m *mockResolver
tmpDir *TmpFolder
tmpFile *TmpFile
@ -43,7 +43,7 @@ var _ = Describe("HostsFileResolver", func() {
tmpDir = NewTmpFolder("HostsFileResolver")
tmpFile = writeHostFile(tmpDir)
sutConfig = config.HostsFileConfig{
sutConfig = config.HostsFile{
Sources: config.NewBytesSources(tmpFile.Path),
HostsTTL: config.Duration(time.Duration(TTL) * time.Second),
FilterLoopback: true,
@ -82,7 +82,7 @@ var _ = Describe("HostsFileResolver", func() {
Describe("Using hosts file", func() {
When("Hosts file cannot be located", func() {
BeforeEach(func() {
sutConfig = config.HostsFileConfig{
sutConfig = config.HostsFile{
Sources: config.NewBytesSources("/this/file/does/not/exist"),
HostsTTL: config.Duration(time.Duration(TTL) * time.Second),
}