Maint: openvpn configurator interface composition
This commit is contained in:
@@ -6,6 +6,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type AuthWriter interface {
|
||||||
|
WriteAuthFile(user, password string, puid, pgid int) error
|
||||||
|
}
|
||||||
|
|
||||||
// WriteAuthFile writes the OpenVPN auth file to disk with the right permissions.
|
// WriteAuthFile writes the OpenVPN auth file to disk with the right permissions.
|
||||||
func (c *configurator) WriteAuthFile(user, password string, puid, pgid int) error {
|
func (c *configurator) WriteAuthFile(user, password string, puid, pgid int) error {
|
||||||
file, err := os.Open(c.authFilePath)
|
file, err := os.Open(c.authFilePath)
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ const (
|
|||||||
binOpenvpn25 = "openvpn"
|
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) (
|
func (c *configurator) Start(ctx context.Context, version string, flags []string) (
|
||||||
stdoutLines, stderrLines chan string, waitError chan error, err error) {
|
stdoutLines, stderrLines chan string, waitError chan error, err error) {
|
||||||
var bin string
|
var bin string
|
||||||
@@ -40,6 +45,11 @@ func (c *configurator) Start(ctx context.Context, version string, flags []string
|
|||||||
return c.cmder.Start(cmd)
|
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) {
|
func (c *configurator) Version24(ctx context.Context) (version string, err error) {
|
||||||
return c.version(ctx, binOpenvpn24)
|
return c.version(ctx, binOpenvpn24)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type Loop struct {
|
|||||||
pgid int
|
pgid int
|
||||||
targetConfPath string
|
targetConfPath string
|
||||||
// Configurators
|
// Configurators
|
||||||
conf Configurator
|
conf StarterAuthWriter
|
||||||
fw firewall.Configurator
|
fw firewall.Configurator
|
||||||
routing routing.Routing
|
routing routing.Routing
|
||||||
// Other objects
|
// Other objects
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
package openvpn
|
package openvpn
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/gluetun/internal/unix"
|
"github.com/qdm12/gluetun/internal/unix"
|
||||||
"github.com/qdm12/golibs/command"
|
"github.com/qdm12/golibs/command"
|
||||||
@@ -12,13 +10,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Configurator interface {
|
type Configurator interface {
|
||||||
Version24(ctx context.Context) (version string, err error)
|
VersionGetter
|
||||||
Version25(ctx context.Context) (version string, err error)
|
AuthWriter
|
||||||
WriteAuthFile(user, password string, puid, pgid int) error
|
TUNCheckCreater
|
||||||
CheckTUN() error
|
Starter
|
||||||
CreateTUN() error
|
}
|
||||||
Start(ctx context.Context, version string, flags []string) (
|
|
||||||
stdoutLines, stderrLines chan string, waitError chan error, err error)
|
type StarterAuthWriter interface {
|
||||||
|
Starter
|
||||||
|
AuthWriter
|
||||||
}
|
}
|
||||||
|
|
||||||
type configurator struct {
|
type configurator struct {
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/unix"
|
"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.
|
// CheckTUN checks the tunnel device is present and accessible.
|
||||||
func (c *configurator) CheckTUN() error {
|
func (c *configurator) CheckTUN() error {
|
||||||
c.logger.Info("checking for device " + c.tunDevPath)
|
c.logger.Info("checking for device " + c.tunDevPath)
|
||||||
@@ -21,6 +30,10 @@ func (c *configurator) CheckTUN() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TUNCreater interface {
|
||||||
|
CreateTUN() error
|
||||||
|
}
|
||||||
|
|
||||||
func (c *configurator) CreateTUN() error {
|
func (c *configurator) CreateTUN() error {
|
||||||
c.logger.Info("creating " + c.tunDevPath)
|
c.logger.Info("creating " + c.tunDevPath)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user