Maint: decouple OpenVPN config writer from loop
This commit is contained in:
@@ -5,8 +5,12 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (l *Loop) writeOpenvpnConf(lines []string) error {
|
||||
file, err := os.OpenFile(l.targetConfPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
||||
type ConfigWriter interface {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -34,11 +34,10 @@ type Loop struct {
|
||||
username string
|
||||
puid int
|
||||
pgid int
|
||||
targetConfPath string
|
||||
buildInfo models.BuildInformation
|
||||
versionInfo bool
|
||||
// Configurators
|
||||
conf StarterAuthWriter
|
||||
conf Configurator
|
||||
fw firewallConfigurer
|
||||
routing routing.VPNGetter
|
||||
portForward portforward.StartStopper
|
||||
@@ -90,7 +89,6 @@ func NewLoop(openVPNSettings configuration.OpenVPN,
|
||||
username: username,
|
||||
puid: puid,
|
||||
pgid: pgid,
|
||||
targetConfPath: constants.OpenVPNConf,
|
||||
buildInfo: buildInfo,
|
||||
versionInfo: versionInfo,
|
||||
conf: conf,
|
||||
|
||||
@@ -12,16 +12,13 @@ type Configurator interface {
|
||||
VersionGetter
|
||||
AuthWriter
|
||||
Starter
|
||||
}
|
||||
|
||||
type StarterAuthWriter interface {
|
||||
Starter
|
||||
AuthWriter
|
||||
ConfigWriter
|
||||
}
|
||||
|
||||
type configurator struct {
|
||||
logger logging.Logger
|
||||
cmder command.RunStarter
|
||||
configPath string
|
||||
authFilePath string
|
||||
}
|
||||
|
||||
@@ -30,6 +27,7 @@ func NewConfigurator(logger logging.Logger,
|
||||
return &configurator{
|
||||
logger: logger,
|
||||
cmder: cmder,
|
||||
configPath: constants.OpenVPNConf,
|
||||
authFilePath: constants.OpenVPNAuthConf,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := l.writeOpenvpnConf(lines); err != nil {
|
||||
if err := l.conf.WriteConfig(lines); err != nil {
|
||||
l.signalOrSetStatus(constants.Crashed)
|
||||
l.logAndWait(ctx, err)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user