Moved GetUser and GetPassword to openvpn params getters
This commit is contained in:
@@ -1,10 +1,46 @@
|
|||||||
package params
|
package params
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
libparams "github.com/qdm12/golibs/params"
|
libparams "github.com/qdm12/golibs/params"
|
||||||
"github.com/qdm12/private-internet-access-docker/internal/models"
|
"github.com/qdm12/private-internet-access-docker/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetUser obtains the user to use to connect to the VPN servers
|
||||||
|
func (p *paramsReader) GetUser() (s string, err error) {
|
||||||
|
defer func() {
|
||||||
|
unsetenvErr := p.unsetEnv("USER")
|
||||||
|
if err == nil {
|
||||||
|
err = unsetenvErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
s, err = p.envParams.GetEnv("USER")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
} else if len(s) == 0 {
|
||||||
|
return s, fmt.Errorf("USER environment variable cannot be empty")
|
||||||
|
}
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPassword obtains the password to use to connect to the VPN servers
|
||||||
|
func (p *paramsReader) GetPassword() (s string, err error) {
|
||||||
|
defer func() {
|
||||||
|
unsetenvErr := p.unsetEnv("PASSWORD")
|
||||||
|
if err == nil {
|
||||||
|
err = unsetenvErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
s, err = p.envParams.GetEnv("PASSWORD")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
} else if len(s) == 0 {
|
||||||
|
return s, fmt.Errorf("PASSWORD environment variable cannot be empty")
|
||||||
|
}
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetNetworkProtocol obtains the network protocol to use to connect to the
|
// GetNetworkProtocol obtains the network protocol to use to connect to the
|
||||||
// VPN servers from the environment variable PROTOCOL
|
// VPN servers from the environment variable PROTOCOL
|
||||||
func (p *paramsReader) GetNetworkProtocol() (protocol models.NetworkProtocol, err error) {
|
func (p *paramsReader) GetNetworkProtocol() (protocol models.NetworkProtocol, err error) {
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ type ParamsReader interface {
|
|||||||
GetExtraSubnets() (extraSubnets []net.IPNet, err error)
|
GetExtraSubnets() (extraSubnets []net.IPNet, err error)
|
||||||
|
|
||||||
// VPN getters
|
// VPN getters
|
||||||
|
GetUser() (s string, err error)
|
||||||
|
GetPassword() (s string, err error)
|
||||||
GetNetworkProtocol() (protocol models.NetworkProtocol, err error)
|
GetNetworkProtocol() (protocol models.NetworkProtocol, err error)
|
||||||
|
|
||||||
// PIA getters
|
// PIA getters
|
||||||
GetUser() (s string, err error)
|
|
||||||
GetPassword() (s string, err error)
|
|
||||||
GetPortForwarding() (activated bool, err error)
|
GetPortForwarding() (activated bool, err error)
|
||||||
GetPortForwardingStatusFilepath() (filepath models.Filepath, err error)
|
GetPortForwardingStatusFilepath() (filepath models.Filepath, err error)
|
||||||
GetPIAEncryption() (models.PIAEncryption, error)
|
GetPIAEncryption() (models.PIAEncryption, error)
|
||||||
|
|||||||
@@ -9,40 +9,6 @@ import (
|
|||||||
"github.com/qdm12/private-internet-access-docker/internal/models"
|
"github.com/qdm12/private-internet-access-docker/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetUser obtains the user to use to connect to the VPN servers
|
|
||||||
func (p *paramsReader) GetUser() (s string, err error) {
|
|
||||||
defer func() {
|
|
||||||
unsetenvErr := p.unsetEnv("USER")
|
|
||||||
if err == nil {
|
|
||||||
err = unsetenvErr
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
s, err = p.envParams.GetEnv("USER")
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
} else if len(s) == 0 {
|
|
||||||
return s, fmt.Errorf("USER environment variable cannot be empty")
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPassword obtains the password to use to connect to the VPN servers
|
|
||||||
func (p *paramsReader) GetPassword() (s string, err error) {
|
|
||||||
defer func() {
|
|
||||||
unsetenvErr := p.unsetEnv("PASSWORD")
|
|
||||||
if err == nil {
|
|
||||||
err = unsetenvErr
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
s, err = p.envParams.GetEnv("PASSWORD")
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
} else if len(s) == 0 {
|
|
||||||
return s, fmt.Errorf("PASSWORD environment variable cannot be empty")
|
|
||||||
}
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPortForwarding obtains if port forwarding on the VPN provider server
|
// GetPortForwarding obtains if port forwarding on the VPN provider server
|
||||||
// side is enabled or not from the environment variable PORT_FORWARDING
|
// side is enabled or not from the environment variable PORT_FORWARDING
|
||||||
func (p *paramsReader) GetPortForwarding() (activated bool, err error) {
|
func (p *paramsReader) GetPortForwarding() (activated bool, err error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user