- Use filepaths with /tmp for tests instead - Only mock functions where filepath can't be specified such as user.Lookup
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
// Package openvpn defines interfaces to interact with openvpn
|
|
// and run it in a stateful loop.
|
|
package openvpn
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
|
"github.com/qdm12/gluetun/internal/unix"
|
|
"github.com/qdm12/golibs/command"
|
|
"github.com/qdm12/golibs/logging"
|
|
)
|
|
|
|
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)
|
|
}
|
|
|
|
type configurator struct {
|
|
logger logging.Logger
|
|
commander command.Commander
|
|
unix unix.Unix
|
|
authFilePath string
|
|
tunDevPath string
|
|
}
|
|
|
|
func NewConfigurator(logger logging.Logger, unix unix.Unix) Configurator {
|
|
return &configurator{
|
|
logger: logger,
|
|
commander: command.NewCommander(),
|
|
unix: unix,
|
|
authFilePath: constants.OpenVPNAuthConf,
|
|
tunDevPath: constants.TunnelDevice,
|
|
}
|
|
}
|