Maint: minor changes to openvpn/config package

- Constructor returns concrete struct instead of interface
- Rename conf to openvpnConf in openvpn loop
This commit is contained in:
Quentin McGaw (desktop)
2021-08-18 20:28:42 +00:00
parent ecdf9396a5
commit d9fbecaa01
7 changed files with 18 additions and 18 deletions

View File

@@ -11,7 +11,7 @@ type AuthWriter interface {
}
// WriteAuthFile writes the OpenVPN auth file to disk with the right permissions.
func (c *configurator) WriteAuthFile(user, password string) error {
func (c *Configurator) WriteAuthFile(user, password string) error {
file, err := os.Open(c.authFilePath)
if err != nil && !os.IsNotExist(err) {

View File

@@ -23,7 +23,7 @@ type Starter interface {
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) {
var bin string
switch version {
@@ -50,17 +50,17 @@ type VersionGetter interface {
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)
}
func (c *configurator) Version25(ctx context.Context) (version string, err error) {
func (c *Configurator) Version25(ctx context.Context) (version string, err error) {
return c.version(ctx, binOpenvpn25)
}
var ErrVersionTooShort = errors.New("version output is too short")
func (c *configurator) version(ctx context.Context, binName string) (version string, err error) {
func (c *Configurator) version(ctx context.Context, binName string) (version string, err error) {
cmd := exec.CommandContext(ctx, binName, "--version")
output, err := c.cmder.Run(cmd)
if err != nil && err.Error() != "exit status 1" {

View File

@@ -9,7 +9,7 @@ type Writer interface {
WriteConfig(lines []string) error
}
func (c *configurator) WriteConfig(lines []string) error {
func (c *Configurator) WriteConfig(lines []string) error {
file, err := os.OpenFile(c.configPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
if err != nil {
return err

View File

@@ -6,14 +6,14 @@ import (
"github.com/qdm12/golibs/logging"
)
type Configurator interface {
type Interface interface {
VersionGetter
AuthWriter
Starter
Writer
}
type configurator struct {
type Configurator struct {
logger logging.Logger
cmder command.RunStarter
configPath string
@@ -21,9 +21,9 @@ type configurator struct {
puid, pgid int
}
func NewConfigurator(logger logging.Logger,
cmder command.RunStarter, puid, pgid int) Configurator {
return &configurator{
func New(logger logging.Logger,
cmder command.RunStarter, puid, pgid int) *Configurator {
return &Configurator{
logger: logger,
cmder: cmder,
configPath: constants.OpenVPNConf,