chore(custom): validate Openvpn file earlier
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/constants/providers"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/parse"
|
||||
"github.com/qdm12/gotree"
|
||||
)
|
||||
@@ -147,6 +148,12 @@ func validateOpenVPNConfigFilepath(isCustom bool,
|
||||
return err
|
||||
}
|
||||
|
||||
extractor := extract.New()
|
||||
_, _, err = extractor.Data(confFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed extracting information from custom configuration file: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,10 @@ func (p *Provider) BuildConf(connection models.Connection,
|
||||
settings settings.OpenVPN) (lines []string, err error) {
|
||||
lines, _, err = p.extractor.Data(*settings.ConfFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed extracting information from custom configuration file: %w", err)
|
||||
// Configuration file is already validated in settings validation in
|
||||
// internal/configuration/settings/openvpn.go in `validateOpenVPNConfigFilepath`.
|
||||
// Therefore this error is the result of a programming error.
|
||||
panic(fmt.Sprintf("failed extracting information from custom configuration file: %s", err))
|
||||
}
|
||||
|
||||
lines = modifyConfig(lines, connection, settings)
|
||||
|
||||
Reference in New Issue
Block a user