Skip to content

hosts-file-enabled cannot be set from config file #413

@linuxgemini

Description

@linuxgemini

Hello,

hosts-file-enabled uses cmd.decodableBool declared in internal/cmd/options.go:

// decodableBool is a boolean that can be unmarshaled from a flags.
//
// TODO(e.burkov): This is a workaround for go-flags, see
// https://github.com/AdguardTeam/dnsproxy/issues/182.
type decodableBool struct {
value bool
}
// type check
var _ goFlags.Unmarshaler = (*decodableBool)(nil)
// UnmarshalFlag implements the [goFlags.Unmarshaler] interface for
// *decodableBool.
func (b *decodableBool) UnmarshalFlag(text string) (err error) {
b.value, err = strconv.ParseBool(text)
return err
}

While the option works as intended as a launch flag --hosts-file-enabled=false, setting it inside a YAML config (hosts-file-enabled: false) will not work:

Aug 20 16:22:47 hostname dnsproxy[738715]: dnsproxy config path: /etc/dnsproxy/config.yaml
Aug 20 16:22:47 hostname dnsproxy[738715]: parsing config file /etc/dnsproxy/config.yaml: unmarshalling file: yaml: unmarshal errors:
Aug 20 16:22:47 hostname dnsproxy[738715]:   line 84: cannot unmarshal !!bool `false` into cmd.decodableBool

Setting it as a string (hosts-file-enabled: "false") also fails:

Aug 20 16:24:47 hostname dnsproxy[738747]: dnsproxy config path: /etc/dnsproxy/config.yaml
Aug 20 16:24:47 hostname dnsproxy[738747]: parsing config file /etc/dnsproxy/config.yaml: unmarshalling file: yaml: unmarshal errors:
Aug 20 16:24:47 hostname dnsproxy[738747]:   line 84: cannot unmarshal !!str `false` into cmd.decodableBool

I don't understand why exactly this occurs (I'm not really proficient in Go), one might omit the YAML flag (seen below) and use it as a command line argument:

// HostsFileEnabled controls whether hosts files are used for resolving or
// not.
HostsFileEnabled decodableBool `yaml:"hosts-file-enabled" long:"hosts-file-enabled" description:"If specified, use hosts files for resolving" default:"true"`

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions