- Goal was to simplify main.go complexity
- Use common structures and interfaces for all vpn providers
- Moved files around
- Removed some alias models
This commit is contained in:
Quentin McGaw
2020-06-13 14:08:29 -04:00
committed by GitHub
parent 4f502abcf8
commit 7369808b84
47 changed files with 1530 additions and 1693 deletions

View File

@@ -1,25 +1,22 @@
package params
import (
"strings"
libparams "github.com/qdm12/golibs/params"
"github.com/qdm12/private-internet-access-docker/internal/constants"
"github.com/qdm12/private-internet-access-docker/internal/models"
)
// GetCyberghostGroup obtains the server group for the Cyberghost server from the
// environment variable CYBERGHOST_GROUP
func (p *reader) GetCyberghostGroup() (region models.CyberghostGroup, err error) {
func (p *reader) GetCyberghostGroup() (group string, err error) {
s, err := p.envParams.GetValueIfInside("CYBERGHOST_GROUP", constants.CyberghostGroupChoices())
return models.CyberghostGroup(strings.ToLower(s)), err
return s, err
}
// GetCyberghostRegion obtains the country name for the Cyberghost server from the
// environment variable REGION
func (p *reader) GetCyberghostRegion() (region models.CyberghostRegion, err error) {
func (p *reader) GetCyberghostRegion() (region string, err error) {
s, err := p.envParams.GetValueIfInside("REGION", constants.CyberghostRegionChoices())
return models.CyberghostRegion(strings.ToLower(s)), err
return s, err
}
// GetCyberghostClientKey obtains the one line client key to use for openvpn from the

View File

@@ -1,35 +1,29 @@
package params
import (
"strings"
libparams "github.com/qdm12/golibs/params"
"github.com/qdm12/private-internet-access-docker/internal/constants"
"github.com/qdm12/private-internet-access-docker/internal/models"
)
// GetMullvadCountry obtains the country for the Mullvad server from the
// environment variable COUNTRY
func (r *reader) GetMullvadCountry() (country models.MullvadCountry, err error) {
func (r *reader) GetMullvadCountry() (country string, err error) {
choices := append(constants.MullvadCountryChoices(), "")
s, err := r.envParams.GetValueIfInside("COUNTRY", choices)
return models.MullvadCountry(strings.ToLower(s)), err
return r.envParams.GetValueIfInside("COUNTRY", choices)
}
// GetMullvadCity obtains the city for the Mullvad server from the
// environment variable CITY
func (r *reader) GetMullvadCity() (country models.MullvadCity, err error) {
func (r *reader) GetMullvadCity() (country string, err error) {
choices := append(constants.MullvadCityChoices(), "")
s, err := r.envParams.GetValueIfInside("CITY", choices)
return models.MullvadCity(strings.ToLower(s)), err
return r.envParams.GetValueIfInside("CITY", choices)
}
// GetMullvadISP obtains the ISP for the Mullvad server from the
// environment variable ISP
func (r *reader) GetMullvadISP() (country models.MullvadProvider, err error) {
choices := append(constants.MullvadProviderChoices(), "")
s, err := r.envParams.GetValueIfInside("ISP", choices)
return models.MullvadProvider(strings.ToLower(s)), err
func (r *reader) GetMullvadISP() (isp string, err error) {
choices := append(constants.MullvadISPChoices(), "")
return r.envParams.GetValueIfInside("ISP", choices)
}
// GetMullvadPort obtains the port to reach the Mullvad server on from the

View File

@@ -3,7 +3,6 @@ package params
import (
"fmt"
"net"
"strings"
libparams "github.com/qdm12/golibs/params"
"github.com/qdm12/private-internet-access-docker/internal/models"
@@ -70,13 +69,11 @@ func (r *reader) GetTargetIP() (ip net.IP, err error) {
// GetOpenVPNCipher obtains a custom cipher to use with OpenVPN
// from the environment variable OPENVPN_CIPHER
func (r *reader) GetOpenVPNCipher() (cipher string, err error) {
cipher, err = r.envParams.GetEnv("OPENVPN_CIPHER")
return strings.ToLower(cipher), err
return r.envParams.GetEnv("OPENVPN_CIPHER")
}
// GetOpenVPNAuth obtains a custom auth algorithm to use with OpenVPN
// from the environment variable OPENVPN_AUTH
func (r *reader) GetOpenVPNAuth() (auth string, err error) {
auth, err = r.envParams.GetEnv("OPENVPN_AUTH")
return strings.ToLower(auth), err
return r.envParams.GetEnv("OPENVPN_AUTH")
}

View File

@@ -53,25 +53,25 @@ type Reader interface {
// PIA getters
GetPortForwarding() (activated bool, err error)
GetPortForwardingStatusFilepath() (filepath models.Filepath, err error)
GetPIAEncryption() (models.PIAEncryption, error)
GetPIARegion() (models.PIARegion, error)
GetPIAEncryptionPreset() (preset string, err error)
GetPIARegion() (region string, err error)
// Mullvad getters
GetMullvadCountry() (country models.MullvadCountry, err error)
GetMullvadCity() (country models.MullvadCity, err error)
GetMullvadISP() (country models.MullvadProvider, err error)
GetMullvadCountry() (country string, err error)
GetMullvadCity() (country string, err error)
GetMullvadISP() (country string, err error)
GetMullvadPort() (port uint16, err error)
// Windscribe getters
GetWindscribeRegion() (country models.WindscribeRegion, err error)
GetWindscribeRegion() (country string, err error)
GetWindscribePort(protocol models.NetworkProtocol) (port uint16, err error)
// Surfshark getters
GetSurfsharkRegion() (country models.SurfsharkRegion, err error)
GetSurfsharkRegion() (country string, err error)
// Cyberghost getters
GetCyberghostGroup() (region models.CyberghostGroup, err error)
GetCyberghostRegion() (region models.CyberghostRegion, err error)
GetCyberghostGroup() (group string, err error)
GetCyberghostRegion() (region string, err error)
GetCyberghostClientKey() (clientKey string, err error)
// Shadowsocks getters

View File

@@ -32,29 +32,37 @@ func (r *reader) GetPortForwardingStatusFilepath() (filepath models.Filepath, er
return models.Filepath(filepathStr), err
}
// GetPIAEncryption obtains the encryption level for the PIA connection
// GetPIAEncryptionPreset obtains the encryption level for the PIA connection
// from the environment variable PIA_ENCRYPTION, and using ENCRYPTION for
// retro compatibility
func (r *reader) GetPIAEncryption() (models.PIAEncryption, error) {
func (r *reader) GetPIAEncryptionPreset() (preset string, err error) {
// Retro-compatibility
s, err := r.envParams.GetValueIfInside("ENCRYPTION", []string{"normal", "strong", ""})
s, err := r.envParams.GetValueIfInside("ENCRYPTION", []string{
constants.PIAEncryptionPresetNormal,
constants.PIAEncryptionPresetStrong,
""})
if err != nil {
return "", err
} else if len(s) != 0 {
r.logger.Warn("You are using the old environment variable ENCRYPTION, please consider changing it to PIA_ENCRYPTION")
return models.PIAEncryption(s), nil
return s, nil
}
s, err = r.envParams.GetValueIfInside("PIA_ENCRYPTION", []string{"normal", "strong"}, libparams.Default("strong"))
return models.PIAEncryption(s), err
return r.envParams.GetValueIfInside(
"PIA_ENCRYPTION",
[]string{
constants.PIAEncryptionPresetNormal,
constants.PIAEncryptionPresetStrong,
},
libparams.Default(constants.PIAEncryptionPresetStrong))
}
// GetPIARegion obtains the region for the PIA server from the
// environment variable REGION
func (r *reader) GetPIARegion() (region models.PIARegion, err error) {
func (r *reader) GetPIARegion() (region string, err error) {
choices := append(constants.PIAGeoChoices(), "")
s, err := r.envParams.GetValueIfInside("REGION", choices)
if len(s) == 0 { // Suggestion by @rorph https://github.com/rorph
s = choices[rand.Int()%len(choices)] //nolint:gosec
}
return models.PIARegion(s), err
return s, err
}

View File

@@ -1,15 +1,12 @@
package params
import (
"strings"
"github.com/qdm12/private-internet-access-docker/internal/constants"
"github.com/qdm12/private-internet-access-docker/internal/models"
)
// GetSurfsharkRegion obtains the region for the Surfshark server from the
// environment variable REGION
func (r *reader) GetSurfsharkRegion() (region models.SurfsharkRegion, err error) {
func (r *reader) GetSurfsharkRegion() (region string, err error) {
s, err := r.envParams.GetValueIfInside("REGION", constants.SurfsharkRegionChoices())
return models.SurfsharkRegion(strings.ToLower(s)), err
return s, err
}

View File

@@ -2,7 +2,6 @@ package params
import (
"fmt"
"strings"
libparams "github.com/qdm12/golibs/params"
"github.com/qdm12/private-internet-access-docker/internal/constants"
@@ -11,9 +10,9 @@ import (
// GetWindscribeRegion obtains the region for the Windscribe server from the
// environment variable REGION
func (r *reader) GetWindscribeRegion() (region models.WindscribeRegion, err error) {
func (r *reader) GetWindscribeRegion() (region string, err error) {
s, err := r.envParams.GetValueIfInside("REGION", constants.WindscribeRegionChoices())
return models.WindscribeRegion(strings.ToLower(s)), err
return s, err
}
// GetMullvadPort obtains the port to reach the Mullvad server on from the