Allow empty string for CSV variables with golibs

This commit is contained in:
Quentin McGaw
2020-10-24 19:09:54 +00:00
parent f92489f99b
commit 716eb14da1
11 changed files with 18 additions and 32 deletions

2
go.mod
View File

@@ -6,7 +6,7 @@ require (
github.com/fatih/color v1.9.0 github.com/fatih/color v1.9.0
github.com/golang/mock v1.4.4 github.com/golang/mock v1.4.4
github.com/kyokomi/emoji v2.2.4+incompatible 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/qdm12/ss-server v0.0.0-20200819124651-6428e626ee83
github.com/stretchr/testify v1.6.1 github.com/stretchr/testify v1.6.1
github.com/vishvananda/netlink v1.1.0 github.com/vishvananda/netlink v1.1.0

4
go.sum
View File

@@ -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/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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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-20201024185935-092412448c2c h1:9EQyDXbeapnPeMeO8Yq7PE6zqYPGkHp/qijNBBTU74c=
github.com/qdm12/golibs v0.0.0-20201018204514-1d5986880422/go.mod h1:pikkTN7g7zRuuAnERwqW1yAFq6pYmxrxpjiwGvb0Ysc= 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 h1:b7sNsgsKxH0mbl9L1hdUp5KSDkZ/1kOQ+iHiBVgFElM=
github.com/qdm12/ss-server v0.0.0-20200819124651-6428e626ee83/go.mod h1:ABVUkxubboL3vqBkOwDV9glX1/x7SnYrckBe5d+M/zw= 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= github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg=

View File

@@ -18,8 +18,7 @@ func (p *reader) GetCyberghostGroup() (group string, err error) {
// GetCyberghostRegions obtains the country names for the Cyberghost servers from the // GetCyberghostRegions obtains the country names for the Cyberghost servers from the
// environment variable REGION. // environment variable REGION.
func (p *reader) GetCyberghostRegions() (regions []string, err error) { func (p *reader) GetCyberghostRegions() (regions []string, err error) {
choices := append(constants.CyberghostRegionChoices(), "") return p.envParams.GetCSVInPossibilities("REGION", constants.CyberghostRegionChoices())
return p.envParams.GetCSVInPossibilities("REGION", choices)
} }
// GetCyberghostClientKey obtains the one line client key to use for openvpn from the // GetCyberghostClientKey obtains the one line client key to use for openvpn from the

View File

@@ -8,22 +8,19 @@ import (
// GetMullvadCountries obtains the countries for the Mullvad servers from the // GetMullvadCountries obtains the countries for the Mullvad servers from the
// environment variable COUNTRY. // environment variable COUNTRY.
func (r *reader) GetMullvadCountries() (countries []string, err error) { func (r *reader) GetMullvadCountries() (countries []string, err error) {
choices := append(constants.MullvadCountryChoices(), "") return r.envParams.GetCSVInPossibilities("COUNTRY", constants.MullvadCountryChoices())
return r.envParams.GetCSVInPossibilities("COUNTRY", choices)
} }
// GetMullvadCity obtains the cities for the Mullvad servers from the // GetMullvadCity obtains the cities for the Mullvad servers from the
// environment variable CITY. // environment variable CITY.
func (r *reader) GetMullvadCities() (cities []string, err error) { func (r *reader) GetMullvadCities() (cities []string, err error) {
choices := append(constants.MullvadCityChoices(), "") return r.envParams.GetCSVInPossibilities("CITY", constants.MullvadCityChoices())
return r.envParams.GetCSVInPossibilities("CITY", choices)
} }
// GetMullvadISPs obtains the ISPs for the Mullvad servers from the // GetMullvadISPs obtains the ISPs for the Mullvad servers from the
// environment variable ISP. // environment variable ISP.
func (r *reader) GetMullvadISPs() (isps []string, err error) { func (r *reader) GetMullvadISPs() (isps []string, err error) {
choices := append(constants.MullvadISPChoices(), "") return r.envParams.GetCSVInPossibilities("ISP", constants.MullvadISPChoices())
return r.envParams.GetCSVInPossibilities("ISP", choices)
} }
// GetMullvadPort obtains the port to reach the Mullvad server on from the // GetMullvadPort obtains the port to reach the Mullvad server on from the

View File

@@ -10,8 +10,7 @@ import (
// GetNordvpnRegions obtains the regions (countries) for the NordVPN server from the // GetNordvpnRegions obtains the regions (countries) for the NordVPN server from the
// environment variable REGION. // environment variable REGION.
func (r *reader) GetNordvpnRegions() (regions []string, err error) { func (r *reader) GetNordvpnRegions() (regions []string, err error) {
choices := append(constants.NordvpnRegionChoices(), "") return r.envParams.GetCSVInPossibilities("REGION", constants.NordvpnRegionChoices())
return r.envParams.GetCSVInPossibilities("REGION", choices)
} }
// GetNordvpnRegion obtains the server numbers (optional) for the NordVPN servers from the // GetNordvpnRegion obtains the server numbers (optional) for the NordVPN servers from the

View File

@@ -149,7 +149,7 @@ func (r *reader) GetVPNSP() (vpnServiceProvider models.VPNProvider, err error) {
"pia", "private internet access", "private internet access old", "pia", "private internet access", "private internet access old",
"mullvad", "windscribe", "surfshark", "cyberghost", "mullvad", "windscribe", "surfshark", "cyberghost",
"vyprvpn", "nordvpn", "purevpn", "vyprvpn", "nordvpn", "purevpn",
}) }, libparams.Default("private internet access"))
if s == "pia" { if s == "pia" {
s = "private internet access" s = "private internet access"
} }

View File

@@ -42,8 +42,7 @@ func (r *reader) GetPIAEncryptionPreset() (preset string, err error) {
// Retro-compatibility // Retro-compatibility
s, err := r.envParams.GetValueIfInside("ENCRYPTION", []string{ s, err := r.envParams.GetValueIfInside("ENCRYPTION", []string{
constants.PIAEncryptionPresetNormal, constants.PIAEncryptionPresetNormal,
constants.PIAEncryptionPresetStrong, constants.PIAEncryptionPresetStrong})
""})
if err != nil { if err != nil {
return "", err return "", err
} else if len(s) != 0 { } 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 // GetPIARegions obtains the regions for the PIA servers from the
// environment variable REGION. // environment variable REGION.
func (r *reader) GetPIARegions() (regions []string, err error) { func (r *reader) GetPIARegions() (regions []string, err error) {
choices := append(constants.PIAGeoChoices(), "") return r.envParams.GetCSVInPossibilities("REGION", constants.PIAGeoChoices())
return r.envParams.GetCSVInPossibilities("REGION", choices)
} }
// GetPIAOldRegions obtains the regions for the PIA servers from the // GetPIAOldRegions obtains the regions for the PIA servers from the
// environment variable REGION. // environment variable REGION.
func (r *reader) GetPIAOldRegions() (regions []string, err error) { func (r *reader) GetPIAOldRegions() (regions []string, err error) {
choices := append(constants.PIAOldGeoChoices(), "") return r.envParams.GetCSVInPossibilities("REGION", constants.PIAOldGeoChoices())
return r.envParams.GetCSVInPossibilities("REGION", choices)
} }

View File

@@ -7,20 +7,17 @@ import (
// GetPurevpnRegions obtains the regions (continents) for the PureVPN servers from the // GetPurevpnRegions obtains the regions (continents) for the PureVPN servers from the
// environment variable REGION. // environment variable REGION.
func (r *reader) GetPurevpnRegions() (regions []string, err error) { func (r *reader) GetPurevpnRegions() (regions []string, err error) {
choices := append(constants.PurevpnRegionChoices(), "") return r.envParams.GetCSVInPossibilities("REGION", constants.PurevpnRegionChoices())
return r.envParams.GetCSVInPossibilities("REGION", choices)
} }
// GetPurevpnCountries obtains the countries for the PureVPN servers from the // GetPurevpnCountries obtains the countries for the PureVPN servers from the
// environment variable COUNTRY. // environment variable COUNTRY.
func (r *reader) GetPurevpnCountries() (countries []string, err error) { func (r *reader) GetPurevpnCountries() (countries []string, err error) {
choices := append(constants.PurevpnCountryChoices(), "") return r.envParams.GetCSVInPossibilities("COUNTRY", constants.PurevpnCountryChoices())
return r.envParams.GetCSVInPossibilities("COUNTRY", choices)
} }
// GetPurevpnCities obtains the cities for the PureVPN servers from the // GetPurevpnCities obtains the cities for the PureVPN servers from the
// environment variable CITY. // environment variable CITY.
func (r *reader) GetPurevpnCities() (cities []string, err error) { func (r *reader) GetPurevpnCities() (cities []string, err error) {
choices := append(constants.PurevpnCityChoices(), "") return r.envParams.GetCSVInPossibilities("CITY", constants.PurevpnCityChoices())
return r.envParams.GetCSVInPossibilities("CITY", choices)
} }

View File

@@ -7,6 +7,5 @@ import (
// GetSurfsharkRegions obtains the regions for the Surfshark servers from the // GetSurfsharkRegions obtains the regions for the Surfshark servers from the
// environment variable REGION. // environment variable REGION.
func (r *reader) GetSurfsharkRegions() (regions []string, err error) { func (r *reader) GetSurfsharkRegions() (regions []string, err error) {
choices := append(constants.SurfsharkRegionChoices(), "") return r.envParams.GetCSVInPossibilities("REGION", constants.SurfsharkRegionChoices())
return r.envParams.GetCSVInPossibilities("REGION", choices)
} }

View File

@@ -7,6 +7,5 @@ import (
// GetVyprvpnRegions obtains the regions for the Vyprvpn servers from the // GetVyprvpnRegions obtains the regions for the Vyprvpn servers from the
// environment variable REGION. // environment variable REGION.
func (r *reader) GetVyprvpnRegions() (regions []string, err error) { func (r *reader) GetVyprvpnRegions() (regions []string, err error) {
choices := append(constants.VyprvpnRegionChoices(), "") return r.envParams.GetCSVInPossibilities("REGION", constants.VyprvpnRegionChoices())
return r.envParams.GetCSVInPossibilities("REGION", choices)
} }

View File

@@ -11,8 +11,7 @@ import (
// GetWindscribeRegions obtains the regions for the Windscribe servers from the // GetWindscribeRegions obtains the regions for the Windscribe servers from the
// environment variable REGION. // environment variable REGION.
func (r *reader) GetWindscribeRegions() (regions []string, err error) { func (r *reader) GetWindscribeRegions() (regions []string, err error) {
choices := append(constants.WindscribeRegionChoices(), "") return r.envParams.GetCSVInPossibilities("REGION", constants.WindscribeRegionChoices())
return r.envParams.GetCSVInPossibilities("REGION", choices)
} }
// GetMullvadPort obtains the port to reach the Mullvad server on from the // GetMullvadPort obtains the port to reach the Mullvad server on from the