mirror of https://github.com/0xERR0R/blocky.git
HostsFileConfig -> HostsFile
This commit is contained in:
parent
e3fcf79aa2
commit
f38f59cca6
|
@ -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"`
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue