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:
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func (l *Loop) removePortForwardedFile() {
|
||||
filepath := l.state.GetSettings().Filepath
|
||||
filepath := *l.state.GetSettings().Filepath
|
||||
l.logger.Info("removing port file " + filepath)
|
||||
if err := os.Remove(filepath); err != nil {
|
||||
l.logger.Error(err.Error())
|
||||
@@ -14,7 +14,7 @@ func (l *Loop) removePortForwardedFile() {
|
||||
}
|
||||
|
||||
func (l *Loop) writePortForwardedFile(port uint16) {
|
||||
filepath := l.state.GetSettings().Filepath
|
||||
filepath := *l.state.GetSettings().Filepath
|
||||
l.logger.Info("writing port file " + filepath)
|
||||
if err := writePortForwardedToFile(filepath, port); err != nil {
|
||||
l.logger.Error(err.Error())
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
"github.com/qdm12/gluetun/internal/loopstate"
|
||||
@@ -42,7 +42,7 @@ type Loop struct {
|
||||
|
||||
const defaultBackoffTime = 5 * time.Second
|
||||
|
||||
func NewLoop(settings configuration.PortForwarding,
|
||||
func NewLoop(settings settings.PortForwarding,
|
||||
client *http.Client, portAllower firewall.PortAllower,
|
||||
logger Logger) *Loop {
|
||||
start := make(chan struct{})
|
||||
|
||||
@@ -3,17 +3,17 @@ package portforward
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/portforward/state"
|
||||
)
|
||||
|
||||
type SettingsGetSetter = state.SettingsGetSetter
|
||||
|
||||
func (l *Loop) GetSettings() (settings configuration.PortForwarding) {
|
||||
func (l *Loop) GetSettings() (settings settings.PortForwarding) {
|
||||
return l.state.GetSettings()
|
||||
}
|
||||
|
||||
func (l *Loop) SetSettings(ctx context.Context, settings configuration.PortForwarding) (
|
||||
func (l *Loop) SetSettings(ctx context.Context, settings settings.PortForwarding) (
|
||||
outcome string) {
|
||||
return l.state.SetSettings(ctx, settings)
|
||||
}
|
||||
|
||||
@@ -5,23 +5,23 @@ import (
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
type SettingsGetSetter interface {
|
||||
GetSettings() (settings configuration.PortForwarding)
|
||||
GetSettings() (settings settings.PortForwarding)
|
||||
SetSettings(ctx context.Context,
|
||||
settings configuration.PortForwarding) (outcome string)
|
||||
settings settings.PortForwarding) (outcome string)
|
||||
}
|
||||
|
||||
func (s *State) GetSettings() (settings configuration.PortForwarding) {
|
||||
func (s *State) GetSettings() (settings settings.PortForwarding) {
|
||||
s.settingsMu.RLock()
|
||||
defer s.settingsMu.RUnlock()
|
||||
return s.settings
|
||||
}
|
||||
|
||||
func (s *State) SetSettings(ctx context.Context, settings configuration.PortForwarding) (
|
||||
func (s *State) SetSettings(ctx context.Context, settings settings.PortForwarding) (
|
||||
outcome string) {
|
||||
s.settingsMu.Lock()
|
||||
|
||||
@@ -32,11 +32,11 @@ func (s *State) SetSettings(ctx context.Context, settings configuration.PortForw
|
||||
}
|
||||
|
||||
if s.settings.Filepath != settings.Filepath {
|
||||
_ = os.Rename(s.settings.Filepath, settings.Filepath)
|
||||
_ = os.Rename(*s.settings.Filepath, *settings.Filepath)
|
||||
}
|
||||
|
||||
newEnabled := settings.Enabled
|
||||
previousEnabled := s.settings.Enabled
|
||||
newEnabled := *settings.Enabled
|
||||
previousEnabled := *s.settings.Enabled
|
||||
|
||||
s.settings = settings
|
||||
s.settingsMu.Unlock()
|
||||
|
||||
@@ -3,7 +3,7 @@ package state
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/loopstate"
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ type Manager interface {
|
||||
}
|
||||
|
||||
func New(statusApplier loopstate.Applier,
|
||||
settings configuration.PortForwarding) *State {
|
||||
settings settings.PortForwarding) *State {
|
||||
return &State{
|
||||
statusApplier: statusApplier,
|
||||
settings: settings,
|
||||
@@ -26,7 +26,7 @@ func New(statusApplier loopstate.Applier,
|
||||
type State struct {
|
||||
statusApplier loopstate.Applier
|
||||
|
||||
settings configuration.PortForwarding
|
||||
settings settings.PortForwarding
|
||||
settingsMu sync.RWMutex
|
||||
|
||||
portForwarded uint16
|
||||
|
||||
Reference in New Issue
Block a user