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:
40
internal/configuration/sources/env/provider.go
vendored
Normal file
40
internal/configuration/sources/env/provider.go
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
func (r *Reader) readProvider(vpnType string) (provider settings.Provider, err error) {
|
||||
provider.Name = readVPNServiceProvider(vpnType)
|
||||
|
||||
provider.ServerSelection, err = r.readServerSelection(*provider.Name, vpnType)
|
||||
if err != nil {
|
||||
return provider, fmt.Errorf("cannot read server selection settings: %w", err)
|
||||
}
|
||||
|
||||
provider.PortForwarding, err = readPortForward()
|
||||
if err != nil {
|
||||
return provider, fmt.Errorf("cannot read port forwarding settings: %w", err)
|
||||
}
|
||||
|
||||
return provider, nil
|
||||
}
|
||||
|
||||
func readVPNServiceProvider(vpnType string) (vpnProviderPtr *string) {
|
||||
s := strings.ToLower(os.Getenv("VPNSP"))
|
||||
switch {
|
||||
case vpnType == constants.OpenVPN &&
|
||||
os.Getenv("OPENVPN_CUSTOM_CONFIG") != "": // retro compatibility
|
||||
return stringPtr(constants.Custom)
|
||||
case s == "":
|
||||
return nil
|
||||
case s == "pia": // retro compatibility
|
||||
return stringPtr(constants.PrivateInternetAccess)
|
||||
}
|
||||
return stringPtr(s)
|
||||
}
|
||||
Reference in New Issue
Block a user