chore(config): upgrade to gosettings v0.4.0
- drop qdm12/govalid dependency - upgrade qdm12/ss-server to v0.6.0 - do not unset sensitive config settings (makes no sense to me)
This commit is contained in:
@@ -9,47 +9,45 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||
)
|
||||
|
||||
// ReadFromFile reads the content of the file as a string.
|
||||
// It returns a nil string pointer if the file does not exist.
|
||||
func ReadFromFile(filepath string) (s *string, err error) {
|
||||
// ReadFromFile reads the content of the file as a string,
|
||||
// and returns if the file was present or not with isSet.
|
||||
func ReadFromFile(filepath string) (content string, isSet bool, err error) {
|
||||
file, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil //nolint:nilnil
|
||||
return "", false, nil
|
||||
}
|
||||
return nil, err
|
||||
return "", false, fmt.Errorf("opening file: %w", err)
|
||||
}
|
||||
|
||||
b, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
_ = file.Close()
|
||||
return nil, err
|
||||
return "", false, fmt.Errorf("reading file: %w", err)
|
||||
}
|
||||
|
||||
if err := file.Close(); err != nil {
|
||||
return nil, err
|
||||
return "", false, fmt.Errorf("closing file: %w", err)
|
||||
}
|
||||
|
||||
content := string(b)
|
||||
content = string(b)
|
||||
content = strings.TrimSuffix(content, "\r\n")
|
||||
content = strings.TrimSuffix(content, "\n")
|
||||
return &content, nil
|
||||
return content, true, nil
|
||||
}
|
||||
|
||||
func readPEMFile(filepath string) (base64Ptr *string, err error) {
|
||||
pemData, err := ReadFromFile(filepath)
|
||||
func ReadPEMFile(filepath string) (base64Str string, isSet bool, err error) {
|
||||
pemData, isSet, err := ReadFromFile(filepath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading file: %w", err)
|
||||
return "", false, fmt.Errorf("reading file: %w", err)
|
||||
} else if !isSet {
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
if pemData == nil {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
base64Data, err := extract.PEM([]byte(*pemData))
|
||||
base64Str, err = extract.PEM([]byte(pemData))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("extracting base64 encoded data from PEM content: %w", err)
|
||||
return "", false, fmt.Errorf("extracting base64 encoded data from PEM content: %w", err)
|
||||
}
|
||||
|
||||
return &base64Data, nil
|
||||
return base64Str, true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user