2021-01-16 20:41:39 +00:00
|
|
|
package ak
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
|
|
httptransport "github.com/go-openapi/runtime/client"
|
|
|
|
log "github.com/sirupsen/logrus"
|
2021-11-29 13:42:19 +00:00
|
|
|
"goauthentik.io/api"
|
2021-06-16 10:35:17 +00:00
|
|
|
"goauthentik.io/internal/constants"
|
2021-01-16 20:41:39 +00:00
|
|
|
)
|
|
|
|
|
2021-11-29 13:42:19 +00:00
|
|
|
func doGlobalSetup(outpost api.Outpost, globalConfig api.Config) {
|
2021-12-20 20:23:19 +00:00
|
|
|
l := log.WithField("logger", "authentik.outpost")
|
|
|
|
if !outpost.Managed.IsSet() {
|
|
|
|
switch outpost.Config[ConfigLogLevel].(string) {
|
|
|
|
case "trace":
|
|
|
|
log.SetLevel(log.TraceLevel)
|
|
|
|
case "debug":
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
case "info":
|
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
case "warning":
|
|
|
|
log.SetLevel(log.WarnLevel)
|
|
|
|
case "error":
|
|
|
|
log.SetLevel(log.ErrorLevel)
|
|
|
|
default:
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
l.Debug("Managed outpost, not seting global log level")
|
2021-01-16 20:41:39 +00:00
|
|
|
}
|
2021-12-20 20:23:19 +00:00
|
|
|
l.WithField("hash", constants.BUILD()).WithField("version", constants.VERSION).Info("Starting authentik outpost")
|
2021-01-16 20:41:39 +00:00
|
|
|
|
2021-11-29 13:42:19 +00:00
|
|
|
if globalConfig.ErrorReporting.Enabled {
|
|
|
|
dsn := "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8"
|
2021-12-20 20:23:19 +00:00
|
|
|
l.WithField("env", globalConfig.ErrorReporting.Environment).Debug("Error reporting enabled")
|
2021-09-14 15:40:31 +00:00
|
|
|
err := sentry.Init(sentry.ClientOptions{
|
|
|
|
Dsn: dsn,
|
2021-12-16 18:12:05 +00:00
|
|
|
Environment: globalConfig.ErrorReporting.Environment,
|
2021-11-29 13:42:19 +00:00
|
|
|
TracesSampleRate: float64(globalConfig.ErrorReporting.TracesSampleRate),
|
2021-12-20 18:42:45 +00:00
|
|
|
IgnoreErrors: []string{
|
|
|
|
http.ErrAbortHandler.Error(),
|
|
|
|
},
|
2021-09-14 15:40:31 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-12-20 20:23:19 +00:00
|
|
|
l.WithField("env", globalConfig.ErrorReporting.Environment).WithError(err).Warning("Failed to initialise sentry")
|
2021-09-14 15:40:31 +00:00
|
|
|
}
|
2021-01-16 20:41:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-15 22:01:16 +00:00
|
|
|
// GetTLSTransport Get a TLS transport instance, that skips verification if configured via environment variables.
|
|
|
|
func GetTLSTransport() http.RoundTripper {
|
2021-01-16 20:41:39 +00:00
|
|
|
value, set := os.LookupEnv("AUTHENTIK_INSECURE")
|
|
|
|
if !set {
|
|
|
|
value = "false"
|
|
|
|
}
|
|
|
|
tlsTransport, err := httptransport.TLSTransport(httptransport.TLSClientOptions{
|
|
|
|
InsecureSkipVerify: strings.ToLower(value) == "true",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return tlsTransport
|
|
|
|
}
|