Pull request 2321: upd-go-deps
Merge in DNS/adguard-home from upd-go-deps to master Squashed commit of the following: commit 2c0b63da2ec8bbf19bc7dbb03c0166f6f9a5d822 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Dec 12 14:42:31 2024 +0300 all: upd go deps, tools
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package configmgr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
|
||||
"github.com/AdguardTeam/golibs/container"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/timeutil"
|
||||
"github.com/AdguardTeam/golibs/validate"
|
||||
)
|
||||
|
||||
// config is the top-level on-disk configuration structure.
|
||||
@@ -19,10 +19,10 @@ type config struct {
|
||||
}
|
||||
|
||||
// type check
|
||||
var _ validator = (*config)(nil)
|
||||
var _ validate.Interface = (*config)(nil)
|
||||
|
||||
// validate implements the [validator] interface for *config.
|
||||
func (c *config) validate() (err error) {
|
||||
// Validate implements the [validate.Interface] interface for *config.
|
||||
func (c *config) Validate() (err error) {
|
||||
if c == nil {
|
||||
return errors.ErrNoValue
|
||||
}
|
||||
@@ -30,7 +30,7 @@ func (c *config) validate() (err error) {
|
||||
// TODO(a.garipov): Add more validations.
|
||||
|
||||
// Keep this in the same order as the fields in the config.
|
||||
validators := container.KeyValues[string, validator]{{
|
||||
validators := container.KeyValues[string, validate.Interface]{{
|
||||
Key: "dns",
|
||||
Value: c.DNS,
|
||||
}, {
|
||||
@@ -41,14 +41,12 @@ func (c *config) validate() (err error) {
|
||||
Value: c.Log,
|
||||
}}
|
||||
|
||||
var errs []error
|
||||
for _, kv := range validators {
|
||||
err = kv.Value.validate()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", kv.Key, err)
|
||||
}
|
||||
errs = validate.Append(errs, kv.Key, kv.Value)
|
||||
}
|
||||
|
||||
return nil
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
// dnsConfig is the on-disk DNS configuration.
|
||||
@@ -63,21 +61,19 @@ type dnsConfig struct {
|
||||
}
|
||||
|
||||
// type check
|
||||
var _ validator = (*dnsConfig)(nil)
|
||||
var _ validate.Interface = (*dnsConfig)(nil)
|
||||
|
||||
// validate implements the [validator] interface for *dnsConfig.
|
||||
// Validate implements the [validate.Interface] interface for *dnsConfig.
|
||||
//
|
||||
// TODO(a.garipov): Add more validations.
|
||||
func (c *dnsConfig) validate() (err error) {
|
||||
// TODO(a.garipov): Add more validations.
|
||||
switch {
|
||||
case c == nil:
|
||||
func (c *dnsConfig) Validate() (err error) {
|
||||
if c == nil {
|
||||
return errors.ErrNoValue
|
||||
case c.UpstreamTimeout.Duration <= 0:
|
||||
return newErrNotPositive("upstream_timeout", c.UpstreamTimeout)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO(a.garipov): Add more validations.
|
||||
|
||||
return validate.Positive("upstream_timeout", c.UpstreamTimeout)
|
||||
}
|
||||
|
||||
// httpConfig is the on-disk web API configuration.
|
||||
@@ -92,20 +88,23 @@ type httpConfig struct {
|
||||
}
|
||||
|
||||
// type check
|
||||
var _ validator = (*httpConfig)(nil)
|
||||
var _ validate.Interface = (*httpConfig)(nil)
|
||||
|
||||
// validate implements the [validator] interface for *httpConfig.
|
||||
// Validate implements the [validate.Interface] interface for *httpConfig.
|
||||
//
|
||||
// TODO(a.garipov): Add more validations.
|
||||
func (c *httpConfig) validate() (err error) {
|
||||
switch {
|
||||
case c == nil:
|
||||
func (c *httpConfig) Validate() (err error) {
|
||||
if c == nil {
|
||||
return errors.ErrNoValue
|
||||
case c.Timeout.Duration <= 0:
|
||||
return newErrNotPositive("timeout", c.Timeout)
|
||||
default:
|
||||
return c.Pprof.validate()
|
||||
}
|
||||
|
||||
errs := []error{
|
||||
validate.Positive("timeout", c.Timeout),
|
||||
}
|
||||
|
||||
errs = validate.Append(errs, "pprof", c.Pprof)
|
||||
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
// httpPprofConfig is the on-disk pprof configuration.
|
||||
@@ -115,10 +114,10 @@ type httpPprofConfig struct {
|
||||
}
|
||||
|
||||
// type check
|
||||
var _ validator = (*httpPprofConfig)(nil)
|
||||
var _ validate.Interface = (*httpPprofConfig)(nil)
|
||||
|
||||
// validate implements the [validator] interface for *httpPprofConfig.
|
||||
func (c *httpPprofConfig) validate() (err error) {
|
||||
// Validate implements the [validate.Interface] interface for *httpPprofConfig.
|
||||
func (c *httpPprofConfig) Validate() (err error) {
|
||||
if c == nil {
|
||||
return errors.ErrNoValue
|
||||
}
|
||||
@@ -128,17 +127,17 @@ func (c *httpPprofConfig) validate() (err error) {
|
||||
|
||||
// logConfig is the on-disk web API configuration.
|
||||
type logConfig struct {
|
||||
// TODO(a.garipov): Use.
|
||||
// TODO(a.garipov): Use.
|
||||
Verbose bool `yaml:"verbose"`
|
||||
}
|
||||
|
||||
// type check
|
||||
var _ validator = (*logConfig)(nil)
|
||||
var _ validate.Interface = (*logConfig)(nil)
|
||||
|
||||
// validate implements the [validator] interface for *logConfig.
|
||||
// Validate implements the [validate.Interface] interface for *logConfig.
|
||||
//
|
||||
// TODO(a.garipov): Add more validations.
|
||||
func (c *logConfig) validate() (err error) {
|
||||
func (c *logConfig) Validate() (err error) {
|
||||
if c == nil {
|
||||
return errors.ErrNoValue
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func Validate(fileName string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
err = conf.validate()
|
||||
err = conf.Validate()
|
||||
if err != nil {
|
||||
return fmt.Errorf("validating config: %w", err)
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func New(ctx context.Context, c *Config) (m *Manager, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = conf.validate()
|
||||
err = conf.Validate()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("validating config: %w", err)
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func (m *Manager) assemble(
|
||||
BootstrapServers: conf.DNS.BootstrapDNS,
|
||||
UpstreamServers: conf.DNS.UpstreamDNS,
|
||||
DNS64Prefixes: conf.DNS.DNS64Prefixes,
|
||||
UpstreamTimeout: conf.DNS.UpstreamTimeout.Duration,
|
||||
UpstreamTimeout: time.Duration(conf.DNS.UpstreamTimeout),
|
||||
BootstrapPreferIPv6: conf.DNS.BootstrapPreferIPv6,
|
||||
UseDNS64: conf.DNS.UseDNS64,
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func (m *Manager) assemble(
|
||||
Addresses: conf.HTTP.Addresses,
|
||||
SecureAddresses: conf.HTTP.SecureAddresses,
|
||||
OverrideAddress: webAddr,
|
||||
Timeout: conf.HTTP.Timeout.Duration,
|
||||
Timeout: time.Duration(conf.HTTP.Timeout),
|
||||
ForceHTTPS: conf.HTTP.ForceHTTPS,
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ func (m *Manager) updateCurrentDNS(c *dnssvc.Config) {
|
||||
m.current.DNS.BootstrapDNS = slices.Clone(c.BootstrapServers)
|
||||
m.current.DNS.UpstreamDNS = slices.Clone(c.UpstreamServers)
|
||||
m.current.DNS.DNS64Prefixes = slices.Clone(c.DNS64Prefixes)
|
||||
m.current.DNS.UpstreamTimeout = timeutil.Duration{Duration: c.UpstreamTimeout}
|
||||
m.current.DNS.UpstreamTimeout = timeutil.Duration(c.UpstreamTimeout)
|
||||
m.current.DNS.BootstrapPreferIPv6 = c.BootstrapPreferIPv6
|
||||
m.current.DNS.UseDNS64 = c.UseDNS64
|
||||
}
|
||||
@@ -318,6 +318,6 @@ func (m *Manager) updateCurrentWeb(c *websvc.Config) {
|
||||
|
||||
m.current.HTTP.Addresses = slices.Clone(c.Addresses)
|
||||
m.current.HTTP.SecureAddresses = slices.Clone(c.SecureAddresses)
|
||||
m.current.HTTP.Timeout = timeutil.Duration{Duration: c.Timeout}
|
||||
m.current.HTTP.Timeout = timeutil.Duration(c.Timeout)
|
||||
m.current.HTTP.ForceHTTPS = c.ForceHTTPS
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package configmgr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/timeutil"
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
// validator is the interface for configuration entities that can validate
|
||||
// themselves.
|
||||
type validator interface {
|
||||
// validate returns an error if the entity isn't valid.
|
||||
validate() (err error)
|
||||
}
|
||||
|
||||
// numberOrDuration is the constraint for integer types along with
|
||||
// timeutil.Duration.
|
||||
type numberOrDuration interface {
|
||||
constraints.Integer | timeutil.Duration
|
||||
}
|
||||
|
||||
// newErrNotPositive returns an error about the value that must be positive but
|
||||
// isn't. prop is the name of the property to mention in the error message.
|
||||
//
|
||||
// TODO(a.garipov): Consider moving such helpers to golibs and use in AdGuardDNS
|
||||
// as well.
|
||||
func newErrNotPositive[T numberOrDuration](prop string, v T) (err error) {
|
||||
return fmt.Errorf("%s: %w, got %v", prop, errors.ErrNotPositive, v)
|
||||
}
|
||||
Reference in New Issue
Block a user