- Goal was to simplify main.go complexity
- Use common structures and interfaces for all vpn providers
- Moved files around
- Removed some alias models
This commit is contained in:
Quentin McGaw
2020-06-13 14:08:29 -04:00
committed by GitHub
parent 4f502abcf8
commit 7369808b84
47 changed files with 1530 additions and 1693 deletions

View File

@@ -0,0 +1,38 @@
package provider
import (
"context"
"github.com/qdm12/golibs/files"
"github.com/qdm12/golibs/logging"
"github.com/qdm12/golibs/network"
"github.com/qdm12/private-internet-access-docker/internal/constants"
"github.com/qdm12/private-internet-access-docker/internal/firewall"
"github.com/qdm12/private-internet-access-docker/internal/models"
)
// Provider contains methods to read and modify the openvpn configuration to connect as a client
type Provider interface {
GetOpenVPNConnections(selection models.ServerSelection) (connections []models.OpenVPNConnection, err error)
BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string, extras models.ExtraConfigOptions) (err error)
GetPortForward() (port uint16, err error)
WritePortForward(filepath models.Filepath, port uint16, uid, gid int) (err error)
AllowPortForwardFirewall(ctx context.Context, device models.VPNDevice, port uint16) (err error)
}
func New(provider models.VPNProvider, logger logging.Logger, client network.Client, fileManager files.FileManager, firewall firewall.Configurator) Provider {
switch provider {
case constants.PrivateInternetAccess:
return newPrivateInternetAccess(client, fileManager, firewall)
case constants.Mullvad:
return newMullvad(fileManager, logger)
case constants.Windscribe:
return newWindscribe(fileManager)
case constants.Surfshark:
return newSurfshark(fileManager)
case constants.Cyberghost:
return newCyberghost(fileManager)
default:
return nil // should never occur
}
}