Maint: rework OpenVPN custom configuration code

- Refactor code and errors returned
- Add unit tests
- Make custom config code independent from loop
This commit is contained in:
Quentin McGaw (desktop)
2021-08-18 20:12:26 +00:00
parent c515603d2f
commit f17a4eae3e
4 changed files with 546 additions and 91 deletions

View File

@@ -26,3 +26,19 @@ func (o OpenVPNConnection) RemoteLine() (line string) {
func (o OpenVPNConnection) ProtoLine() (line string) {
return "proto " + o.Protocol
}
// UpdateEmptyWith updates each field of the connection where the value is not set.
func (o *OpenVPNConnection) UpdateEmptyWith(connection OpenVPNConnection) {
if o.IP == nil {
o.IP = connection.IP
}
if o.Port == 0 {
o.Port = connection.Port
}
if o.Protocol == "" {
o.Protocol = connection.Protocol
}
if o.Hostname == "" {
o.Hostname = connection.Hostname
}
}