From 198e5ce6422dc4bd75e7ed1e3dd027657fd55695 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 14 Sep 2021 17:40:31 +0200 Subject: [PATCH] outpost: fix crash when common keys are not defined in config Signed-off-by: Jens Langhammer --- internal/outpost/ak/global.go | 37 +++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/internal/outpost/ak/global.go b/internal/outpost/ak/global.go index b3ec3ce22..6e98bc874 100644 --- a/internal/outpost/ak/global.go +++ b/internal/outpost/ak/global.go @@ -4,7 +4,6 @@ import ( "net/http" "os" "strings" - "time" "github.com/getsentry/sentry-go" 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") - env := config[ConfigErrorReportingEnvironment].(string) + sentryEnv := "customer-outpost" + sentryEnable := true + if cSentryEnv, ok := config[ConfigErrorReportingEnvironment]; ok { + if ccSentryEnv, ok := cSentryEnv.(string); ok { + sentryEnv = ccSentryEnv + } + } var dsn string - if config[ConfigErrorReportingEnabled].(bool) { + 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", env).Debug("Error reporting enabled") + log.WithField("env", sentryEnv).Debug("Error reporting enabled") + err := sentry.Init(sentry.ClientOptions{ + Dsn: dsn, + Environment: sentryEnv, + TracesSampleRate: 1, + }) + if err != nil { + log.Fatalf("sentry.Init: %s", err) + } } - - err := sentry.Init(sentry.ClientOptions{ - Dsn: dsn, - Environment: env, - TracesSampleRate: 1, - }) - if err != nil { - 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.