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
+8 -11
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 surfshark struct {
fileManager files.FileManager
lookupIP func(host string) ([]net.IP, error)
}
type surfshark struct{}
func newSurfshark(fileManager files.FileManager) *surfshark {
return &surfshark{fileManager, net.LookupIP}
func newSurfshark() *surfshark {
return &surfshark{}
}
func (s *surfshark) GetOpenVPNConnections(selection models.ServerSelection) (connections []models.OpenVPNConnection, err error) {
@@ -57,14 +54,14 @@ func (s *surfshark) GetOpenVPNConnections(selection models.ServerSelection) (con
return connections, nil
}
func (s *surfshark) BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string, extras models.ExtraConfigOptions) (err error) {
func (s *surfshark) 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 = "SHA512"
}
lines := []string{
lines = []string{
"client",
"dev tun",
"nobind",
@@ -119,9 +116,9 @@ func (s *surfshark) BuildConf(connections []models.OpenVPNConnection, verbosity,
"</tls-auth>",
"",
}...)
return s.fileManager.WriteLinesToFile(string(constants.OpenVPNConf), lines, files.Ownership(uid, gid), files.Permissions(0400))
return lines
}
func (s *surfshark) GetPortForward() (port uint16, err error) {
func (s *surfshark) GetPortForward(client network.Client) (port uint16, err error) {
panic("port forwarding is not supported for surfshark")
}