Simplified provider object creation

This commit is contained in:
Quentin McGaw
2020-07-13 23:34:03 +00:00
parent 618441b008
commit 2f955e0190
8 changed files with 65 additions and 90 deletions

View File

@@ -5,18 +5,15 @@ import (
"net"
"strings"
"github.com/qdm12/golibs/files"
"github.com/qdm12/golibs/network"
"github.com/qdm12/private-internet-access-docker/internal/constants"
"github.com/qdm12/private-internet-access-docker/internal/models"
)
type vyprvpn struct {
fileManager files.FileManager
lookupIP func(host string) ([]net.IP, error)
}
type vyprvpn struct{}
func newVyprvpn(fileManager files.FileManager) *vyprvpn {
return &vyprvpn{fileManager, net.LookupIP}
func newVyprvpn() *vyprvpn {
return &vyprvpn{}
}
func (s *vyprvpn) GetOpenVPNConnections(selection models.ServerSelection) (connections []models.OpenVPNConnection, err error) {
@@ -57,14 +54,14 @@ func (s *vyprvpn) GetOpenVPNConnections(selection models.ServerSelection) (conne
return connections, nil
}
func (s *vyprvpn) BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string, extras models.ExtraConfigOptions) (err error) {
func (s *vyprvpn) BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string, extras models.ExtraConfigOptions) (lines []string) {
if len(cipher) == 0 {
cipher = aes256cbc
}
if len(auth) == 0 {
auth = "SHA256"
}
lines := []string{
lines = []string{
"client",
"dev tun",
"nobind",
@@ -105,9 +102,9 @@ func (s *vyprvpn) BuildConf(connections []models.OpenVPNConnection, verbosity, u
"-----END CERTIFICATE-----",
"</ca>",
}...)
return s.fileManager.WriteLinesToFile(string(constants.OpenVPNConf), lines, files.Ownership(uid, gid), files.Permissions(0400))
return lines
}
func (s *vyprvpn) GetPortForward() (port uint16, err error) {
func (s *vyprvpn) GetPortForward(client network.Client) (port uint16, err error) {
panic("port forwarding is not supported for vyprvpn")
}