outpost: fix crash when common keys are not defined in config

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-09-14 17:40:31 +02:00
parent 923fbac5b0
commit 198e5ce642
1 changed files with 22 additions and 15 deletions

View File

@ -4,7 +4,6 @@ import (
"net/http" "net/http"
"os" "os"
"strings" "strings"
"time"
"github.com/getsentry/sentry-go" "github.com/getsentry/sentry-go"
httptransport "github.com/go-openapi/runtime/client" httptransport "github.com/go-openapi/runtime/client"
@ -35,23 +34,31 @@ func doGlobalSetup(config map[string]interface{}) {
} }
log.WithField("buildHash", constants.BUILD()).WithField("version", constants.VERSION).Info("Starting authentik outpost") log.WithField("buildHash", constants.BUILD()).WithField("version", constants.VERSION).Info("Starting authentik outpost")
env := config[ConfigErrorReportingEnvironment].(string) sentryEnv := "customer-outpost"
var dsn string sentryEnable := true
if config[ConfigErrorReportingEnabled].(bool) { if cSentryEnv, ok := config[ConfigErrorReportingEnvironment]; ok {
dsn = "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8" if ccSentryEnv, ok := cSentryEnv.(string); ok {
log.WithField("env", env).Debug("Error reporting enabled") sentryEnv = ccSentryEnv
} }
}
var dsn string
if cSentryEnable, ok := config[ConfigErrorReportingEnabled]; ok {
if ccSentryEnable, ok := cSentryEnable.(bool); ok {
sentryEnable = ccSentryEnable
}
}
if sentryEnable {
dsn = "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8"
log.WithField("env", sentryEnv).Debug("Error reporting enabled")
err := sentry.Init(sentry.ClientOptions{ err := sentry.Init(sentry.ClientOptions{
Dsn: dsn, Dsn: dsn,
Environment: env, Environment: sentryEnv,
TracesSampleRate: 1, TracesSampleRate: 1,
}) })
if err != nil { if err != nil {
log.Fatalf("sentry.Init: %s", err) log.Fatalf("sentry.Init: %s", err)
} }
}
defer sentry.Flush(2 * time.Second)
} }
// GetTLSTransport Get a TLS transport instance, that skips verification if configured via environment variables. // GetTLSTransport Get a TLS transport instance, that skips verification if configured via environment variables.