Added Mullvad environment variables and getters
This commit is contained in:
40
internal/params/mullvad.go
Normal file
40
internal/params/mullvad.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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 (p *paramsReader) GetMullvadCountry() (country models.MullvadCountry, err error) {
|
||||
choices := append(constants.MullvadCityChoices(), "")
|
||||
s, err := p.envParams.GetValueIfInside("COUNTRY", choices)
|
||||
return models.MullvadCountry(strings.ToLower(s)), err
|
||||
}
|
||||
|
||||
// GetMullvadCity obtains the city for the Mullvad server from the
|
||||
// environment variable CITY
|
||||
func (p *paramsReader) GetMullvadCity() (country models.MullvadCity, err error) {
|
||||
choices := append(constants.MullvadCityChoices(), "")
|
||||
s, err := p.envParams.GetValueIfInside("CITY", choices)
|
||||
return models.MullvadCity(strings.ToLower(s)), err
|
||||
}
|
||||
|
||||
// GetMullvadISP obtains the ISP for the Mullvad server from the
|
||||
// environment variable ISP
|
||||
func (p *paramsReader) GetMullvadISP() (country models.MullvadProvider, err error) {
|
||||
choices := append(constants.MullvadProviderChoices(), "")
|
||||
s, err := p.envParams.GetValueIfInside("ISP", choices)
|
||||
return models.MullvadProvider(strings.ToLower(s)), err
|
||||
}
|
||||
|
||||
// GetMullvadPort obtains the port to reach the Mullvad server on from the
|
||||
// environment variable PORT
|
||||
func (p *paramsReader) GetMullvadPort() (port uint16, err error) {
|
||||
n, err := p.envParams.GetEnvIntRange("PORT", 0, 65535, libparams.Default("0"))
|
||||
return uint16(n), err
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
|
||||
// ParamsReader contains methods to obtain parameters
|
||||
type ParamsReader interface {
|
||||
GetVPNSP() (country models.MullvadCountry, err error)
|
||||
|
||||
// DNS over TLS getters
|
||||
GetDNSOverTLS() (DNSOverTLS bool, err error)
|
||||
GetDNSOverTLSProviders() (providers []models.DNSProvider, err error)
|
||||
@@ -39,6 +41,12 @@ type ParamsReader interface {
|
||||
GetPIAEncryption() (models.PIAEncryption, error)
|
||||
GetPIARegion() (models.PIARegion, error)
|
||||
|
||||
// Mullvad getters
|
||||
GetMullvadCountry() (country models.MullvadCountry, err error)
|
||||
GetMullvadCity() (country models.MullvadCity, err error)
|
||||
GetMullvadISP() (country models.MullvadProvider, err error)
|
||||
GetMullvadPort() (port uint16, err error)
|
||||
|
||||
// Shadowsocks getters
|
||||
GetShadowSocks() (activated bool, err error)
|
||||
GetShadowSocksLog() (activated bool, err error)
|
||||
@@ -75,3 +83,9 @@ func NewParamsReader(logger logging.Logger) ParamsReader {
|
||||
unsetEnv: os.Unsetenv,
|
||||
}
|
||||
}
|
||||
|
||||
// GetVPNSP obtains the VPN service provider to use from the environment variable VPNSP
|
||||
func (p *paramsReader) GetVPNSP() (country models.MullvadCountry, err error) {
|
||||
s, err := p.envParams.GetValueIfInside("VPNSP", []string{"pia", "mullvad"})
|
||||
return models.MullvadCountry(s), err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user