chore(settings): refactor settings processing (#756)

- Better settings tree structure logged using `qdm12/gotree`
- Read settings from environment variables, then files, then secret files
- Settings methods to default them, merge them and override them
- `DNS_PLAINTEXT_ADDRESS` default changed to `127.0.0.1` to use DoT. Warning added if set to something else.
- `HTTPPROXY_LISTENING_ADDRESS` instead of `HTTPPROXY_PORT` (with retro-compatibility)
This commit is contained in:
Quentin McGaw
2022-01-06 06:40:23 -05:00
committed by GitHub
parent 46738b2934
commit 7d824a5179
275 changed files with 7167 additions and 6328 deletions

View File

@@ -4,7 +4,7 @@ import (
"errors"
"fmt"
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/openvpn/extract"
@@ -17,7 +17,7 @@ var (
)
// GetConnection gets the connection from the OpenVPN configuration file.
func (p *Provider) GetConnection(selection configuration.ServerSelection) (
func (p *Provider) GetConnection(selection settings.ServerSelection) (
connection models.Connection, err error) {
switch selection.VPN {
case constants.OpenVPN:
@@ -30,9 +30,9 @@ func (p *Provider) GetConnection(selection configuration.ServerSelection) (
}
func getOpenVPNConnection(extractor extract.Interface,
selection configuration.ServerSelection) (
selection settings.ServerSelection) (
connection models.Connection, err error) {
_, connection, err = extractor.Data(selection.OpenVPN.ConfFile)
_, connection, err = extractor.Data(*selection.OpenVPN.ConfFile)
if err != nil {
return connection, fmt.Errorf("%w: %s", ErrExtractConnection, err)
}
@@ -41,9 +41,9 @@ func getOpenVPNConnection(extractor extract.Interface,
return connection, nil
}
func getWireguardConnection(selection configuration.ServerSelection) (
func getWireguardConnection(selection settings.ServerSelection) (
connection models.Connection) {
port := getPort(selection.Wireguard.EndpointPort, selection)
port := getPort(*selection.Wireguard.EndpointPort, selection)
return models.Connection{
Type: constants.Wireguard,
IP: selection.Wireguard.EndpointIP,
@@ -54,6 +54,6 @@ func getWireguardConnection(selection configuration.ServerSelection) (
}
// Port found is overridden by custom port set with `PORT` or `WIREGUARD_ENDPOINT_PORT`.
func getPort(foundPort uint16, selection configuration.ServerSelection) (port uint16) {
func getPort(foundPort uint16, selection settings.ServerSelection) (port uint16) {
return utils.GetPort(selection, foundPort, foundPort, foundPort)
}