chore(settings): updater DNS address as string
This commit is contained in:
@@ -380,7 +380,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
updaterLogger := logger.New(log.SetComponent("updater"))
|
||||
|
||||
unzipper := unzip.New(httpClient)
|
||||
parallelResolver := resolver.NewParallelResolver(allSettings.Updater.DNSAddress.String())
|
||||
parallelResolver := resolver.NewParallelResolver(allSettings.Updater.DNSAddress)
|
||||
providers := provider.NewProviders(storage, time.Now,
|
||||
updaterLogger, httpClient, unzipper, parallelResolver)
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -22,7 +21,6 @@ import (
|
||||
|
||||
var (
|
||||
ErrModeUnspecified = errors.New("at least one of -enduser or -maintainer must be specified")
|
||||
ErrDNSAddress = errors.New("DNS address is not valid")
|
||||
ErrNoProviderSpecified = errors.New("no provider was specified")
|
||||
)
|
||||
|
||||
@@ -35,12 +33,12 @@ type UpdaterLogger interface {
|
||||
func (c *CLI) Update(ctx context.Context, args []string, logger UpdaterLogger) error {
|
||||
options := settings.Updater{}
|
||||
var endUserMode, maintainerMode, updateAll bool
|
||||
var dnsAddress, csvProviders string
|
||||
var csvProviders string
|
||||
flagSet := flag.NewFlagSet("update", flag.ExitOnError)
|
||||
flagSet.BoolVar(&endUserMode, "enduser", false, "Write results to /gluetun/servers.json (for end users)")
|
||||
flagSet.BoolVar(&maintainerMode, "maintainer", false,
|
||||
"Write results to ./internal/storage/servers.json to modify the program (for maintainers)")
|
||||
flagSet.StringVar(&dnsAddress, "dns", "8.8.8.8", "DNS resolver address to use")
|
||||
flagSet.StringVar(&options.DNSAddress, "dns", "8.8.8.8", "DNS resolver address to use")
|
||||
flagSet.BoolVar(&updateAll, "all", false, "Update servers for all VPN providers")
|
||||
flagSet.StringVar(&csvProviders, "providers", "", "CSV string of VPN providers to update server data for")
|
||||
if err := flagSet.Parse(args); err != nil {
|
||||
@@ -51,11 +49,6 @@ func (c *CLI) Update(ctx context.Context, args []string, logger UpdaterLogger) e
|
||||
return ErrModeUnspecified
|
||||
}
|
||||
|
||||
options.DNSAddress = net.ParseIP(dnsAddress)
|
||||
if options.DNSAddress == nil {
|
||||
return fmt.Errorf("%w: %s", ErrDNSAddress, dnsAddress)
|
||||
}
|
||||
|
||||
if updateAll {
|
||||
options.Providers = providers.All()
|
||||
} else {
|
||||
@@ -80,7 +73,7 @@ func (c *CLI) Update(ctx context.Context, args []string, logger UpdaterLogger) e
|
||||
const clientTimeout = 10 * time.Second
|
||||
httpClient := &http.Client{Timeout: clientTimeout}
|
||||
unzipper := unzip.New(httpClient)
|
||||
parallelResolver := resolver.NewParallelResolver(options.DNSAddress.String())
|
||||
parallelResolver := resolver.NewParallelResolver(options.DNSAddress)
|
||||
|
||||
providers := provider.NewProviders(storage, time.Now, logger, httpClient, unzipper, parallelResolver)
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package settings
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -21,8 +20,8 @@ type Updater struct {
|
||||
Period *time.Duration
|
||||
// DNSAddress is the DNS server address to use
|
||||
// to resolve VPN server hostnames to IP addresses.
|
||||
// It cannot be nil in the internal state.
|
||||
DNSAddress net.IP
|
||||
// It cannot be the empty string in the internal state.
|
||||
DNSAddress string
|
||||
// Providers is the list of VPN service providers
|
||||
// to update server information for.
|
||||
Providers []string
|
||||
@@ -56,7 +55,7 @@ func (u Updater) Validate() (err error) {
|
||||
func (u *Updater) copy() (copied Updater) {
|
||||
return Updater{
|
||||
Period: helpers.CopyDurationPtr(u.Period),
|
||||
DNSAddress: helpers.CopyIP(u.DNSAddress),
|
||||
DNSAddress: u.DNSAddress,
|
||||
Providers: helpers.CopyStringSlice(u.Providers),
|
||||
}
|
||||
}
|
||||
@@ -65,7 +64,7 @@ func (u *Updater) copy() (copied Updater) {
|
||||
// unset field of the receiver settings object.
|
||||
func (u *Updater) mergeWith(other Updater) {
|
||||
u.Period = helpers.MergeWithDuration(u.Period, other.Period)
|
||||
u.DNSAddress = helpers.MergeWithIP(u.DNSAddress, other.DNSAddress)
|
||||
u.DNSAddress = helpers.MergeWithString(u.DNSAddress, other.DNSAddress)
|
||||
u.Providers = helpers.MergeStringSlices(u.Providers, other.Providers)
|
||||
}
|
||||
|
||||
@@ -74,13 +73,13 @@ func (u *Updater) mergeWith(other Updater) {
|
||||
// settings.
|
||||
func (u *Updater) overrideWith(other Updater) {
|
||||
u.Period = helpers.OverrideWithDuration(u.Period, other.Period)
|
||||
u.DNSAddress = helpers.OverrideWithIP(u.DNSAddress, other.DNSAddress)
|
||||
u.DNSAddress = helpers.OverrideWithString(u.DNSAddress, other.DNSAddress)
|
||||
u.Providers = helpers.OverrideWithStringSlice(u.Providers, other.Providers)
|
||||
}
|
||||
|
||||
func (u *Updater) SetDefaults(vpnProvider string) {
|
||||
u.Period = helpers.DefaultDuration(u.Period, 0)
|
||||
u.DNSAddress = helpers.DefaultIP(u.DNSAddress, net.IPv4(1, 1, 1, 1))
|
||||
u.DNSAddress = helpers.DefaultString(u.DNSAddress, "1.1.1.1:53")
|
||||
if len(u.Providers) == 0 && vpnProvider != providers.Custom {
|
||||
u.Providers = []string{vpnProvider}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
@@ -37,11 +36,11 @@ func readUpdaterPeriod() (period *time.Duration, err error) {
|
||||
return period, nil
|
||||
}
|
||||
|
||||
func readUpdaterDNSAddress() (ip net.IP, err error) {
|
||||
func readUpdaterDNSAddress() (address string, err error) {
|
||||
// TODO this is currently using Cloudflare in
|
||||
// plaintext to not be blocked by DNS over TLS by default.
|
||||
// If a plaintext address is set in the DNS settings, this one will be used.
|
||||
// use custom future encrypted DNS written in Go without blocking
|
||||
// as it's too much trouble to start another parallel unbound instance for now.
|
||||
return nil, nil
|
||||
return "", nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user