diff --git a/internal/openvpn/auth.go b/internal/openvpn/auth.go index ebd46bce..54d57fda 100644 --- a/internal/openvpn/auth.go +++ b/internal/openvpn/auth.go @@ -6,6 +6,10 @@ import ( "strings" ) +type AuthWriter interface { + WriteAuthFile(user, password string, puid, pgid int) error +} + // WriteAuthFile writes the OpenVPN auth file to disk with the right permissions. func (c *configurator) WriteAuthFile(user, password string, puid, pgid int) error { file, err := os.Open(c.authFilePath) diff --git a/internal/openvpn/command.go b/internal/openvpn/command.go index b7397188..8c073640 100644 --- a/internal/openvpn/command.go +++ b/internal/openvpn/command.go @@ -18,6 +18,11 @@ const ( binOpenvpn25 = "openvpn" ) +type Starter interface { + Start(ctx context.Context, version string, flags []string) ( + stdoutLines, stderrLines chan string, waitError chan error, err error) +} + func (c *configurator) Start(ctx context.Context, version string, flags []string) ( stdoutLines, stderrLines chan string, waitError chan error, err error) { var bin string @@ -40,6 +45,11 @@ func (c *configurator) Start(ctx context.Context, version string, flags []string return c.cmder.Start(cmd) } +type VersionGetter interface { + Version24(ctx context.Context) (version string, err error) + Version25(ctx context.Context) (version string, err error) +} + func (c *configurator) Version24(ctx context.Context) (version string, err error) { return c.version(ctx, binOpenvpn24) } diff --git a/internal/openvpn/loop.go b/internal/openvpn/loop.go index dc9d7cbb..c2c7b2cb 100644 --- a/internal/openvpn/loop.go +++ b/internal/openvpn/loop.go @@ -36,7 +36,7 @@ type Loop struct { pgid int targetConfPath string // Configurators - conf Configurator + conf StarterAuthWriter fw firewall.Configurator routing routing.Routing // Other objects diff --git a/internal/openvpn/openvpn.go b/internal/openvpn/openvpn.go index c8bae346..6dbf70e6 100644 --- a/internal/openvpn/openvpn.go +++ b/internal/openvpn/openvpn.go @@ -3,8 +3,6 @@ package openvpn import ( - "context" - "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/unix" "github.com/qdm12/golibs/command" @@ -12,13 +10,15 @@ import ( ) type Configurator interface { - Version24(ctx context.Context) (version string, err error) - Version25(ctx context.Context) (version string, err error) - WriteAuthFile(user, password string, puid, pgid int) error - CheckTUN() error - CreateTUN() error - Start(ctx context.Context, version string, flags []string) ( - stdoutLines, stderrLines chan string, waitError chan error, err error) + VersionGetter + AuthWriter + TUNCheckCreater + Starter +} + +type StarterAuthWriter interface { + Starter + AuthWriter } type configurator struct { diff --git a/internal/openvpn/tun.go b/internal/openvpn/tun.go index 3c79185c..70543e46 100644 --- a/internal/openvpn/tun.go +++ b/internal/openvpn/tun.go @@ -8,6 +8,15 @@ import ( "github.com/qdm12/gluetun/internal/unix" ) +type TUNCheckCreater interface { + TUNChecker + TUNCreater +} + +type TUNChecker interface { + CheckTUN() error +} + // CheckTUN checks the tunnel device is present and accessible. func (c *configurator) CheckTUN() error { c.logger.Info("checking for device " + c.tunDevPath) @@ -21,6 +30,10 @@ func (c *configurator) CheckTUN() error { return nil } +type TUNCreater interface { + CreateTUN() error +} + func (c *configurator) CreateTUN() error { c.logger.Info("creating " + c.tunDevPath)