Fix #90 add env variable OPENVPN_TARGET_IP

This commit is contained in:
Quentin McGaw
2020-03-18 23:49:40 +00:00
parent d2b361b998
commit 9435db8e1e
11 changed files with 67 additions and 8 deletions

View File

@@ -1,6 +1,9 @@
package params
import (
"fmt"
"net"
libparams "github.com/qdm12/golibs/params"
"github.com/qdm12/private-internet-access-docker/internal/models"
)
@@ -45,3 +48,18 @@ func (p *paramsReader) GetOpenVPNVerbosity() (verbosity int, err error) {
func (p *paramsReader) GetOpenVPNRoot() (root bool, err error) {
return p.envParams.GetYesNo("OPENVPN_ROOT", libparams.Default("no"))
}
// GetTargetIP obtains the IP address to choose from the list of IP addresses
// available for a particular region, from the environment variable
// OPENVPN_TARGET_IP
func (p *paramsReader) GetTargetIP() (ip net.IP, err error) {
s, err := p.envParams.GetEnv("OPENVPN_TARGET_IP")
if len(s) == 0 {
return nil, nil
}
ip = net.ParseIP(s)
if ip == nil {
return nil, fmt.Errorf("target IP address %q is not valid", s)
}
return ip, nil
}