summaryrefslogtreecommitdiff
path: root/pkg/config
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/config')
-rw-r--r--pkg/config/config.go (renamed from pkg/config/main.go)42
1 files changed, 31 insertions, 11 deletions
diff --git a/pkg/config/main.go b/pkg/config/config.go
index 1ce00aa..76b4e4e 100644
--- a/pkg/config/main.go
+++ b/pkg/config/config.go
@@ -24,14 +24,23 @@ import (
const DefaultAuthenticationModule string = "anon"
type Opts struct {
- Tls bool
- CaCrt string
- CaKey string
- TlsCrt string
- TlsKey string
- Port string
- Auth string
- AuthSecret string
+ Tls bool
+ CaCrt string
+ CaKey string
+ TlsCrt string
+ TlsKey string
+ Port string
+ Auth string
+ AuthSecret string
+ ApiPath string
+ ProviderCaPath string
+}
+
+func checkPathExists(path string) bool {
+ if _, err := os.Stat(path); os.IsNotExist(err) {
+ return false
+ }
+ return true
}
func FallbackToEnv(variable *string, envVar, defaultVar string) {
@@ -72,14 +81,16 @@ func NewOpts() *Opts {
}
func initializeFlags(opts *Opts) {
- flag.StringVar(&opts.CaCrt, "caCrt", "", "Path to the CA public key used for VPN certificates")
- flag.StringVar(&opts.CaKey, "caKey", "", "Path to the CA private key used for VPN certificates")
+ flag.StringVar(&opts.CaCrt, "vpnCaCrt", "", "Path to the CA public key used for VPN certificates")
+ flag.StringVar(&opts.CaKey, "vpnCaKey", "", "Path to the CA private key used for VPN certificates")
flag.BoolVar(&opts.Tls, "tls", false, "Enable TLS on the service")
flag.StringVar(&opts.TlsCrt, "tlsCrt", "", "Path to the cert file for TLS")
flag.StringVar(&opts.TlsKey, "tlsKey", "", "Path to the key file for TLS")
flag.StringVar(&opts.Port, "port", "", "Port where the server will listen (default: 8000)")
- flag.StringVar(&opts.Auth, "auth", "", "Authentication module (anonymous, sip)")
+ flag.StringVar(&opts.Auth, "auth", "", "Authentication module (ano, sip2)")
flag.StringVar(&opts.AuthSecret, "authSecret", "", "Authentication secret (optional)")
+ flag.StringVar(&opts.ApiPath, "apiPath", "", "Path to the API public files")
+ flag.StringVar(&opts.ProviderCaPath, "providerCaCrt", "", "Path to the provider CA certificate")
flag.Parse()
FallbackToEnv(&opts.CaCrt, "VPNWEB_CACRT", "")
@@ -89,6 +100,8 @@ func initializeFlags(opts *Opts) {
FallbackToEnv(&opts.Port, "VPNWEB_PORT", "8000")
FallbackToEnv(&opts.Auth, "VPNWEB_AUTH", DefaultAuthenticationModule)
FallbackToEnv(&opts.AuthSecret, "VPNWEB_AUTH_SECRET", "")
+ FallbackToEnv(&opts.ApiPath, "VPNWEB_API_PATH", "/etc/leap/config/vpn")
+ FallbackToEnv(&opts.ProviderCaPath, "VPNWEB_PROVIDER_CA", "/etc/leap/ca/ca.crt")
}
func checkConfigurationOptions(opts *Opts) {
@@ -113,5 +126,12 @@ func checkConfigurationOptions(opts *Opts) {
doTlsFilesSanityCheck(opts.TlsCrt, opts.TlsKey)
}
+ if !checkPathExists(opts.ApiPath) {
+ log.Fatal("Configured API path does not exist: ", opts.ApiPath)
+ }
+ if !checkPathExists(opts.ProviderCaPath) {
+ log.Fatal("Configured provider CA path does not exist: ", opts.ProviderCaPath)
+ }
+
log.Println("Authentication module:", opts.Auth)
}