Maintenance: remove some type aliases
This commit is contained in:
@@ -65,7 +65,7 @@ func (settings *Provider) readCyberghost(r reader) (err error) {
|
||||
}
|
||||
|
||||
func readCyberghostClientKey(r reader) (clientKey string, err error) {
|
||||
b, err := r.getFromFileOrSecretFile("OPENVPN_CLIENTKEY", string(constants.ClientKey))
|
||||
b, err := r.getFromFileOrSecretFile("OPENVPN_CLIENTKEY", constants.ClientKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func extractClientKey(b []byte) (key string, err error) {
|
||||
}
|
||||
|
||||
func readCyberghostClientCertificate(r reader) (clientCertificate string, err error) {
|
||||
b, err := r.getFromFileOrSecretFile("OPENVPN_CLIENTCRT", string(constants.ClientCertificate))
|
||||
b, err := r.getFromFileOrSecretFile("OPENVPN_CLIENTCRT", constants.ClientCertificate)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/golibs/params"
|
||||
)
|
||||
|
||||
@@ -67,7 +66,7 @@ func (settings *OpenVPN) read(r reader) (err error) {
|
||||
vpnsp = "private internet access"
|
||||
}
|
||||
|
||||
settings.Provider.Name = models.VPNProvider(vpnsp)
|
||||
settings.Provider.Name = vpnsp
|
||||
|
||||
settings.User, err = r.getFromEnvOrSecretFile("OPENVPN_USER", true, []string{"USER"})
|
||||
if err != nil {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/golibs/params"
|
||||
)
|
||||
|
||||
@@ -67,12 +66,11 @@ func (settings *Provider) readPrivateInternetAccess(r reader) (err error) {
|
||||
}
|
||||
|
||||
if settings.PortForwarding.Enabled {
|
||||
filepathStr, err := r.env.Path("PORT_FORWARDING_STATUS_FILE",
|
||||
settings.PortForwarding.Filepath, err = r.env.Path("PORT_FORWARDING_STATUS_FILE",
|
||||
params.Default("/tmp/gluetun/forwarded_port"), params.CaseSensitiveValue())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settings.PortForwarding.Filepath = models.Filepath(filepathStr)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -7,29 +7,28 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/golibs/params"
|
||||
)
|
||||
|
||||
// Provider contains settings specific to a VPN provider.
|
||||
type Provider struct {
|
||||
Name models.VPNProvider `json:"name"`
|
||||
Name string `json:"name"`
|
||||
ServerSelection ServerSelection `json:"server_selection"`
|
||||
ExtraConfigOptions ExtraConfigOptions `json:"extra_config"`
|
||||
PortForwarding PortForwarding `json:"port_forwarding"`
|
||||
}
|
||||
|
||||
func (settings *Provider) lines() (lines []string) {
|
||||
lines = append(lines, lastIndent+strings.Title(string(settings.Name))+" settings:")
|
||||
lines = append(lines, lastIndent+strings.Title(settings.Name)+" settings:")
|
||||
|
||||
lines = append(lines, indent+lastIndent+"Network protocol: "+string(settings.ServerSelection.Protocol))
|
||||
lines = append(lines, indent+lastIndent+"Network protocol: "+settings.ServerSelection.Protocol)
|
||||
|
||||
if settings.ServerSelection.TargetIP != nil {
|
||||
lines = append(lines, indent+lastIndent+"Target IP address: "+settings.ServerSelection.TargetIP.String())
|
||||
}
|
||||
|
||||
var providerLines []string
|
||||
switch strings.ToLower(string(settings.Name)) {
|
||||
switch strings.ToLower(settings.Name) {
|
||||
case "cyberghost":
|
||||
providerLines = settings.cyberghostLines()
|
||||
case "mullvad":
|
||||
@@ -64,14 +63,8 @@ func commaJoin(slice []string) string {
|
||||
return strings.Join(slice, ", ")
|
||||
}
|
||||
|
||||
func readProtocol(env params.Env) (protocol models.NetworkProtocol, err error) {
|
||||
s, err := env.Inside("PROTOCOL",
|
||||
[]string{string(constants.TCP), string(constants.UDP)},
|
||||
params.Default(string(constants.UDP)))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return models.NetworkProtocol(s), nil
|
||||
func readProtocol(env params.Env) (protocol string, err error) {
|
||||
return env.Inside("PROTOCOL", []string{constants.TCP, constants.UDP}, params.Default(constants.UDP))
|
||||
}
|
||||
|
||||
func readTargetIP(env params.Env) (targetIP net.IP, err error) {
|
||||
@@ -82,7 +75,7 @@ var (
|
||||
ErrInvalidProtocol = errors.New("invalid network protocol")
|
||||
)
|
||||
|
||||
func readCustomPort(env params.Env, protocol models.NetworkProtocol,
|
||||
func readCustomPort(env params.Env, protocol string,
|
||||
allowedTCP, allowedUDP []uint16) (port uint16, err error) {
|
||||
port, err = readPortOrZero(env, "PORT")
|
||||
if err != nil {
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/golibs/params/mock_params"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -108,7 +107,7 @@ func Test_Provider_lines(t *testing.T) {
|
||||
},
|
||||
PortForwarding: PortForwarding{
|
||||
Enabled: true,
|
||||
Filepath: models.Filepath("/here"),
|
||||
Filepath: string("/here"),
|
||||
},
|
||||
},
|
||||
lines: []string{
|
||||
@@ -207,7 +206,7 @@ func Test_readProtocol(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
mockStr string
|
||||
mockErr error
|
||||
protocol models.NetworkProtocol
|
||||
protocol string
|
||||
err error
|
||||
}{
|
||||
"error": {
|
||||
|
||||
@@ -4,13 +4,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/golibs/params"
|
||||
)
|
||||
|
||||
type PublicIP struct {
|
||||
Period time.Duration `json:"period"`
|
||||
IPFilepath models.Filepath `json:"ip_filepath"`
|
||||
Period time.Duration `json:"period"`
|
||||
IPFilepath string `json:"ip_filepath"`
|
||||
}
|
||||
|
||||
func (settings *PublicIP) String() string {
|
||||
@@ -25,7 +24,7 @@ func (settings *PublicIP) lines() (lines []string) {
|
||||
|
||||
lines = append(lines, lastIndent+"Public IP getter:")
|
||||
lines = append(lines, indent+lastIndent+"Fetch period: "+settings.Period.String())
|
||||
lines = append(lines, indent+lastIndent+"IP file: "+string(settings.IPFilepath))
|
||||
lines = append(lines, indent+lastIndent+"IP file: "+settings.IPFilepath)
|
||||
|
||||
return lines
|
||||
}
|
||||
@@ -36,13 +35,12 @@ func (settings *PublicIP) read(r reader) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
filepathStr, err := r.env.Path("PUBLICIP_FILE", params.CaseSensitiveValue(),
|
||||
settings.IPFilepath, err = r.env.Path("PUBLICIP_FILE", params.CaseSensitiveValue(),
|
||||
params.Default("/tmp/gluetun/ip"),
|
||||
params.RetroKeys([]string{"IP_STATUS_FILE"}, r.onRetroActive))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
settings.IPFilepath = models.Filepath(filepathStr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,14 +2,12 @@ package configuration
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type ServerSelection struct {
|
||||
// Common
|
||||
Protocol models.NetworkProtocol `json:"network_protocol"`
|
||||
TargetIP net.IP `json:"target_ip,omitempty"`
|
||||
Protocol string `json:"network_protocol"`
|
||||
TargetIP net.IP `json:"target_ip,omitempty"`
|
||||
|
||||
// Cyberghost, PIA, Surfshark, Windscribe, Vyprvpn, NordVPN
|
||||
Regions []string `json:"regions"`
|
||||
@@ -44,12 +42,12 @@ type ExtraConfigOptions struct {
|
||||
|
||||
// PortForwarding contains settings for port forwarding.
|
||||
type PortForwarding struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Filepath models.Filepath `json:"filepath"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Filepath string `json:"filepath"`
|
||||
}
|
||||
|
||||
func (p *PortForwarding) lines() (lines []string) {
|
||||
return []string{
|
||||
lastIndent + "File path: " + string(p.Filepath),
|
||||
lastIndent + "File path: " + p.Filepath,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user