Maint: openvpn configurator interface composition
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ type Loop struct {
|
||||
pgid int
|
||||
targetConfPath string
|
||||
// Configurators
|
||||
conf Configurator
|
||||
conf StarterAuthWriter
|
||||
fw firewall.Configurator
|
||||
routing routing.Routing
|
||||
// Other objects
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user