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:
54
internal/configuration/sources/env/shadowsocks.go
vendored
Normal file
54
internal/configuration/sources/env/shadowsocks.go
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
)
|
||||
|
||||
func (r *Reader) readShadowsocks() (shadowsocks settings.Shadowsocks, err error) {
|
||||
shadowsocks.Enabled, err = envToBoolPtr("SHADOWSOCKS")
|
||||
if err != nil {
|
||||
return shadowsocks, fmt.Errorf("environment variable SHADOWSOCKS: %w", err)
|
||||
}
|
||||
|
||||
shadowsocks.Address = r.readShadowsocksAddress()
|
||||
shadowsocks.LogAddresses, err = envToBoolPtr("SHADOWSOCKS_LOG")
|
||||
if err != nil {
|
||||
return shadowsocks, fmt.Errorf("environment variable SHADOWSOCKS_LOG: %w", err)
|
||||
}
|
||||
shadowsocks.CipherName = r.readShadowsocksCipher()
|
||||
shadowsocks.Password = envToStringPtr("SHADOWSOCKS_PASSWORD")
|
||||
|
||||
return shadowsocks, nil
|
||||
}
|
||||
|
||||
func (r *Reader) readShadowsocksAddress() (address string) {
|
||||
address = os.Getenv("SHADOWSOCKS_LISTENING_ADDRESS")
|
||||
if address != "" {
|
||||
return address
|
||||
}
|
||||
|
||||
// Retro-compatibility
|
||||
portString := os.Getenv("SHADOWSOCKS_PORT")
|
||||
if portString != "" {
|
||||
r.onRetroActive("SHADOWSOCKS_PORT", "SHADOWSOCKS_LISTENING_ADDRESS")
|
||||
return ":" + portString
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (r *Reader) readShadowsocksCipher() (cipher string) {
|
||||
cipher = os.Getenv("SHADOWSOCKS_CIPHER")
|
||||
if cipher != "" {
|
||||
return cipher
|
||||
}
|
||||
// Retro-compatibility
|
||||
cipher = os.Getenv("SHADOWSOCKS_METHOD")
|
||||
if cipher != "" {
|
||||
r.onRetroActive("SHADOWSOCKS_METHOD", "SHADOWSOCKS_CIPHER")
|
||||
}
|
||||
return cipher
|
||||
}
|
||||
Reference in New Issue
Block a user