From 716eb14da1f74d8e13857d095c47e5b4dde9ca83 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sat, 24 Oct 2020 19:09:54 +0000 Subject: [PATCH] Allow empty string for CSV variables with golibs --- go.mod | 2 +- go.sum | 4 ++-- internal/params/cyberghost.go | 3 +-- internal/params/mullvad.go | 9 +++------ internal/params/nordvpn.go | 3 +-- internal/params/params.go | 2 +- internal/params/pia.go | 9 +++------ internal/params/purevpn.go | 9 +++------ internal/params/surfshark.go | 3 +-- internal/params/vypervpn.go | 3 +-- internal/params/windscribe.go | 3 +-- 11 files changed, 18 insertions(+), 32 deletions(-) diff --git a/go.mod b/go.mod index 92ad7b1d..aaf6c496 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/fatih/color v1.9.0 github.com/golang/mock v1.4.4 github.com/kyokomi/emoji v2.2.4+incompatible - github.com/qdm12/golibs v0.0.0-20201018204514-1d5986880422 + github.com/qdm12/golibs v0.0.0-20201024185935-092412448c2c github.com/qdm12/ss-server v0.0.0-20200819124651-6428e626ee83 github.com/stretchr/testify v1.6.1 github.com/vishvananda/netlink v1.1.0 diff --git a/go.sum b/go.sum index 3e344919..5585fe19 100644 --- a/go.sum +++ b/go.sum @@ -72,8 +72,8 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/qdm12/golibs v0.0.0-20201018204514-1d5986880422 h1:sk+ri/MsgwBqpN3MqOazV8itCid7F2wGS8PbG1kWg9o= -github.com/qdm12/golibs v0.0.0-20201018204514-1d5986880422/go.mod h1:pikkTN7g7zRuuAnERwqW1yAFq6pYmxrxpjiwGvb0Ysc= +github.com/qdm12/golibs v0.0.0-20201024185935-092412448c2c h1:9EQyDXbeapnPeMeO8Yq7PE6zqYPGkHp/qijNBBTU74c= +github.com/qdm12/golibs v0.0.0-20201024185935-092412448c2c/go.mod h1:pikkTN7g7zRuuAnERwqW1yAFq6pYmxrxpjiwGvb0Ysc= github.com/qdm12/ss-server v0.0.0-20200819124651-6428e626ee83 h1:b7sNsgsKxH0mbl9L1hdUp5KSDkZ/1kOQ+iHiBVgFElM= github.com/qdm12/ss-server v0.0.0-20200819124651-6428e626ee83/go.mod h1:ABVUkxubboL3vqBkOwDV9glX1/x7SnYrckBe5d+M/zw= github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg= diff --git a/internal/params/cyberghost.go b/internal/params/cyberghost.go index 0f1cf1b7..acaa9e34 100644 --- a/internal/params/cyberghost.go +++ b/internal/params/cyberghost.go @@ -18,8 +18,7 @@ func (p *reader) GetCyberghostGroup() (group string, err error) { // GetCyberghostRegions obtains the country names for the Cyberghost servers from the // environment variable REGION. func (p *reader) GetCyberghostRegions() (regions []string, err error) { - choices := append(constants.CyberghostRegionChoices(), "") - return p.envParams.GetCSVInPossibilities("REGION", choices) + return p.envParams.GetCSVInPossibilities("REGION", constants.CyberghostRegionChoices()) } // GetCyberghostClientKey obtains the one line client key to use for openvpn from the diff --git a/internal/params/mullvad.go b/internal/params/mullvad.go index d0838e47..c63d4c62 100644 --- a/internal/params/mullvad.go +++ b/internal/params/mullvad.go @@ -8,22 +8,19 @@ import ( // GetMullvadCountries obtains the countries for the Mullvad servers from the // environment variable COUNTRY. func (r *reader) GetMullvadCountries() (countries []string, err error) { - choices := append(constants.MullvadCountryChoices(), "") - return r.envParams.GetCSVInPossibilities("COUNTRY", choices) + return r.envParams.GetCSVInPossibilities("COUNTRY", constants.MullvadCountryChoices()) } // GetMullvadCity obtains the cities for the Mullvad servers from the // environment variable CITY. func (r *reader) GetMullvadCities() (cities []string, err error) { - choices := append(constants.MullvadCityChoices(), "") - return r.envParams.GetCSVInPossibilities("CITY", choices) + return r.envParams.GetCSVInPossibilities("CITY", constants.MullvadCityChoices()) } // GetMullvadISPs obtains the ISPs for the Mullvad servers from the // environment variable ISP. func (r *reader) GetMullvadISPs() (isps []string, err error) { - choices := append(constants.MullvadISPChoices(), "") - return r.envParams.GetCSVInPossibilities("ISP", choices) + return r.envParams.GetCSVInPossibilities("ISP", constants.MullvadISPChoices()) } // GetMullvadPort obtains the port to reach the Mullvad server on from the diff --git a/internal/params/nordvpn.go b/internal/params/nordvpn.go index 41848f74..1f17f9ff 100644 --- a/internal/params/nordvpn.go +++ b/internal/params/nordvpn.go @@ -10,8 +10,7 @@ import ( // GetNordvpnRegions obtains the regions (countries) for the NordVPN server from the // environment variable REGION. func (r *reader) GetNordvpnRegions() (regions []string, err error) { - choices := append(constants.NordvpnRegionChoices(), "") - return r.envParams.GetCSVInPossibilities("REGION", choices) + return r.envParams.GetCSVInPossibilities("REGION", constants.NordvpnRegionChoices()) } // GetNordvpnRegion obtains the server numbers (optional) for the NordVPN servers from the diff --git a/internal/params/params.go b/internal/params/params.go index 587dffc2..4b7d2b4a 100644 --- a/internal/params/params.go +++ b/internal/params/params.go @@ -149,7 +149,7 @@ func (r *reader) GetVPNSP() (vpnServiceProvider models.VPNProvider, err error) { "pia", "private internet access", "private internet access old", "mullvad", "windscribe", "surfshark", "cyberghost", "vyprvpn", "nordvpn", "purevpn", - }) + }, libparams.Default("private internet access")) if s == "pia" { s = "private internet access" } diff --git a/internal/params/pia.go b/internal/params/pia.go index c2603fbf..a72a2273 100644 --- a/internal/params/pia.go +++ b/internal/params/pia.go @@ -42,8 +42,7 @@ func (r *reader) GetPIAEncryptionPreset() (preset string, err error) { // Retro-compatibility s, err := r.envParams.GetValueIfInside("ENCRYPTION", []string{ constants.PIAEncryptionPresetNormal, - constants.PIAEncryptionPresetStrong, - ""}) + constants.PIAEncryptionPresetStrong}) if err != nil { return "", err } else if len(s) != 0 { @@ -62,13 +61,11 @@ func (r *reader) GetPIAEncryptionPreset() (preset string, err error) { // GetPIARegions obtains the regions for the PIA servers from the // environment variable REGION. func (r *reader) GetPIARegions() (regions []string, err error) { - choices := append(constants.PIAGeoChoices(), "") - return r.envParams.GetCSVInPossibilities("REGION", choices) + return r.envParams.GetCSVInPossibilities("REGION", constants.PIAGeoChoices()) } // GetPIAOldRegions obtains the regions for the PIA servers from the // environment variable REGION. func (r *reader) GetPIAOldRegions() (regions []string, err error) { - choices := append(constants.PIAOldGeoChoices(), "") - return r.envParams.GetCSVInPossibilities("REGION", choices) + return r.envParams.GetCSVInPossibilities("REGION", constants.PIAOldGeoChoices()) } diff --git a/internal/params/purevpn.go b/internal/params/purevpn.go index d404d4b0..c8fa00e8 100644 --- a/internal/params/purevpn.go +++ b/internal/params/purevpn.go @@ -7,20 +7,17 @@ import ( // GetPurevpnRegions obtains the regions (continents) for the PureVPN servers from the // environment variable REGION. func (r *reader) GetPurevpnRegions() (regions []string, err error) { - choices := append(constants.PurevpnRegionChoices(), "") - return r.envParams.GetCSVInPossibilities("REGION", choices) + return r.envParams.GetCSVInPossibilities("REGION", constants.PurevpnRegionChoices()) } // GetPurevpnCountries obtains the countries for the PureVPN servers from the // environment variable COUNTRY. func (r *reader) GetPurevpnCountries() (countries []string, err error) { - choices := append(constants.PurevpnCountryChoices(), "") - return r.envParams.GetCSVInPossibilities("COUNTRY", choices) + return r.envParams.GetCSVInPossibilities("COUNTRY", constants.PurevpnCountryChoices()) } // GetPurevpnCities obtains the cities for the PureVPN servers from the // environment variable CITY. func (r *reader) GetPurevpnCities() (cities []string, err error) { - choices := append(constants.PurevpnCityChoices(), "") - return r.envParams.GetCSVInPossibilities("CITY", choices) + return r.envParams.GetCSVInPossibilities("CITY", constants.PurevpnCityChoices()) } diff --git a/internal/params/surfshark.go b/internal/params/surfshark.go index 97503b38..86867c94 100644 --- a/internal/params/surfshark.go +++ b/internal/params/surfshark.go @@ -7,6 +7,5 @@ import ( // GetSurfsharkRegions obtains the regions for the Surfshark servers from the // environment variable REGION. func (r *reader) GetSurfsharkRegions() (regions []string, err error) { - choices := append(constants.SurfsharkRegionChoices(), "") - return r.envParams.GetCSVInPossibilities("REGION", choices) + return r.envParams.GetCSVInPossibilities("REGION", constants.SurfsharkRegionChoices()) } diff --git a/internal/params/vypervpn.go b/internal/params/vypervpn.go index fd1827aa..a9d94d9d 100644 --- a/internal/params/vypervpn.go +++ b/internal/params/vypervpn.go @@ -7,6 +7,5 @@ import ( // GetVyprvpnRegions obtains the regions for the Vyprvpn servers from the // environment variable REGION. func (r *reader) GetVyprvpnRegions() (regions []string, err error) { - choices := append(constants.VyprvpnRegionChoices(), "") - return r.envParams.GetCSVInPossibilities("REGION", choices) + return r.envParams.GetCSVInPossibilities("REGION", constants.VyprvpnRegionChoices()) } diff --git a/internal/params/windscribe.go b/internal/params/windscribe.go index 331e7139..5c072655 100644 --- a/internal/params/windscribe.go +++ b/internal/params/windscribe.go @@ -11,8 +11,7 @@ import ( // GetWindscribeRegions obtains the regions for the Windscribe servers from the // environment variable REGION. func (r *reader) GetWindscribeRegions() (regions []string, err error) { - choices := append(constants.WindscribeRegionChoices(), "") - return r.envParams.GetCSVInPossibilities("REGION", choices) + return r.envParams.GetCSVInPossibilities("REGION", constants.WindscribeRegionChoices()) } // GetMullvadPort obtains the port to reach the Mullvad server on from the