Cyberghost: read client key as file, see #179

This commit is contained in:
Quentin McGaw
2020-07-14 00:17:31 +00:00
parent e3a677c22b
commit 7e7312459d
5 changed files with 46 additions and 23 deletions

View File

@@ -1,6 +1,8 @@
package params
import (
"strings"
libparams "github.com/qdm12/golibs/params"
"github.com/qdm12/private-internet-access-docker/internal/constants"
)
@@ -22,5 +24,18 @@ func (p *reader) GetCyberghostRegion() (region string, err error) {
// GetCyberghostClientKey obtains the one line client key to use for openvpn from the
// environment variable CLIENT_KEY
func (p *reader) GetCyberghostClientKey() (clientKey string, err error) {
return p.envParams.GetEnv("CLIENT_KEY", libparams.Compulsory(), libparams.CaseSensitiveValue())
clientKey, err = p.envParams.GetEnv("CLIENT_KEY", libparams.CaseSensitiveValue())
if err != nil {
return "", err
} else if len(clientKey) > 0 {
return clientKey, nil
}
content, err := p.fileManager.ReadFile("/files/client.key")
if err != nil {
return "", err
}
s := string(content)
s = strings.ReplaceAll(s, "\n", "")
s = strings.ReplaceAll(s, "\r", "")
return s, nil
}