2021-09-13 11:30:14 -04:00
|
|
|
package extract
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
ErrRead = errors.New("cannot read file")
|
|
|
|
|
ErrExtractConnection = errors.New("cannot extract connection from file")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Data extracts the lines and connection from the OpenVPN configuration file.
|
|
|
|
|
func (e *Extractor) Data(filepath string) (lines []string,
|
|
|
|
|
connection models.Connection, err error) {
|
|
|
|
|
lines, err = readCustomConfigLines(filepath)
|
|
|
|
|
if err != nil {
|
2022-02-20 02:58:16 +00:00
|
|
|
return nil, connection, fmt.Errorf("cannot read configuration file: %w", err)
|
2021-09-13 11:30:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection, err = extractDataFromLines(lines)
|
|
|
|
|
if err != nil {
|
2022-02-20 02:58:16 +00:00
|
|
|
return nil, connection, fmt.Errorf("cannot extract connection from file: %w", err)
|
2021-09-13 11:30:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lines, connection, nil
|
|
|
|
|
}
|