chore(constants): remove and move constant paths
- Remove unused paths - Move paths to inline constants if used only once
This commit is contained in:
@@ -302,9 +302,10 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tun.Check(constants.TunnelDevice); err != nil {
|
||||
const tunDevice = "/dev/net/tun"
|
||||
if err := tun.Check(tunDevice); err != nil {
|
||||
logger.Info(err.Error() + "; creating it...")
|
||||
err = tun.Create(constants.TunnelDevice)
|
||||
err = tun.Create(tunDevice)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/configuration/sources/files"
|
||||
)
|
||||
|
||||
type ClientKeyFormatter interface {
|
||||
@@ -16,7 +16,7 @@ type ClientKeyFormatter interface {
|
||||
|
||||
func (c *CLI) ClientKey(args []string) error {
|
||||
flagSet := flag.NewFlagSet("clientkey", flag.ExitOnError)
|
||||
filepath := flagSet.String("path", constants.ClientKey, "file path to the client.key file")
|
||||
filepath := flagSet.String("path", files.OpenVPNClientKeyPath, "file path to the client.key file")
|
||||
if err := flagSet.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,16 +4,22 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
)
|
||||
|
||||
const (
|
||||
// OpenVPNClientKeyPath is the OpenVPN client key filepath.
|
||||
OpenVPNClientKeyPath = "/gluetun/client.key"
|
||||
// OpenVPNClientCertificatePath is the OpenVPN client certificate filepath.
|
||||
OpenVPNClientCertificatePath = "/gluetun/client.crt"
|
||||
)
|
||||
|
||||
func (r *Reader) readOpenVPN() (settings settings.OpenVPN, err error) {
|
||||
settings.ClientKey, err = ReadFromFile(constants.ClientKey)
|
||||
settings.ClientKey, err = ReadFromFile(OpenVPNClientKeyPath)
|
||||
if err != nil {
|
||||
return settings, fmt.Errorf("cannot read client key: %w", err)
|
||||
}
|
||||
|
||||
settings.ClientCrt, err = ReadFromFile(constants.ClientCertificate)
|
||||
settings.ClientCrt, err = ReadFromFile(OpenVPNClientCertificatePath)
|
||||
if err != nil {
|
||||
return settings, fmt.Errorf("cannot read client certificate: %w", err)
|
||||
}
|
||||
|
||||
@@ -1,30 +1,8 @@
|
||||
package constants
|
||||
|
||||
const (
|
||||
// UnboundConf is the file path to the Unbound configuration file.
|
||||
UnboundConf string = "/etc/unbound/unbound.conf"
|
||||
// ResolvConf is the file path to the system resolv.conf file.
|
||||
ResolvConf string = "/etc/resolv.conf"
|
||||
// CACertificates is the file path to the CA certificates file.
|
||||
CACertificates string = "/etc/ssl/certs/ca-certificates.crt"
|
||||
// OpenVPNAuthConf is the file path to the OpenVPN auth file.
|
||||
OpenVPNAuthConf string = "/etc/openvpn/auth.conf"
|
||||
// OpenVPNConf is the file path to the OpenVPN client configuration file.
|
||||
OpenVPNConf string = "/etc/openvpn/target.ovpn"
|
||||
// PIAPortForward is the file path to the port forwarding JSON information for PIA servers.
|
||||
PIAPortForward string = "/gluetun/piaportforward.json"
|
||||
// TunnelDevice is the file path to tun device.
|
||||
TunnelDevice string = "/dev/net/tun"
|
||||
// NetRoute is the path to the file containing information on the network route.
|
||||
NetRoute string = "/proc/net/route"
|
||||
// RootHints is the filepath to the root.hints file used by Unbound.
|
||||
RootHints string = "/etc/unbound/root.hints"
|
||||
// RootKey is the filepath to the root.key file used by Unbound.
|
||||
RootKey string = "/etc/unbound/root.key"
|
||||
// ClientKey is the client key filepath.
|
||||
ClientKey string = "/gluetun/client.key"
|
||||
// ClientCertificate is the client certificate filepath.
|
||||
ClientCertificate string = "/gluetun/client.crt"
|
||||
OpenVPNAuthConf = "/etc/openvpn/auth.conf"
|
||||
// ServersData is the server information filepath.
|
||||
ServersData = "/gluetun/servers.json"
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ func New(logger Infoer, cmder command.RunStarter,
|
||||
return &Configurator{
|
||||
logger: logger,
|
||||
cmder: cmder,
|
||||
configPath: constants.OpenVPNConf,
|
||||
configPath: configPath,
|
||||
authFilePath: constants.OpenVPNAuthConf,
|
||||
puid: puid,
|
||||
pgid: pgid,
|
||||
|
||||
3
internal/openvpn/paths.go
Normal file
3
internal/openvpn/paths.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package openvpn
|
||||
|
||||
const configPath = "/etc/openvpn/target.ovpn"
|
||||
@@ -30,7 +30,7 @@ func start(ctx context.Context, starter command.Starter, version string, flags [
|
||||
return nil, nil, nil, fmt.Errorf("%w: %s", ErrVersionUnknown, version)
|
||||
}
|
||||
|
||||
args := []string{"--config", constants.OpenVPNConf}
|
||||
args := []string{"--config", configPath}
|
||||
args = append(args, flags...)
|
||||
cmd := exec.CommandContext(ctx, bin, args...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
|
||||
@@ -19,11 +19,12 @@ type PIA struct {
|
||||
|
||||
func New(servers []models.PIAServer, randSource rand.Source,
|
||||
timeNow func() time.Time) *PIA {
|
||||
const jsonPortForwardPath = "/gluetun/piaportforward.json"
|
||||
return &PIA{
|
||||
servers: servers,
|
||||
timeNow: timeNow,
|
||||
randSource: randSource,
|
||||
portForwardPath: constants.PIAPortForward,
|
||||
portForwardPath: jsonPortForwardPath,
|
||||
authFilePath: constants.OpenVPNAuthConf,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user